public void testDirectMessagesAsJSON() throws Exception { HttpClientImpl http = new HttpClientImpl(); List<DirectMessage> directMessages = DirectMessageJSONImpl.createDirectMessageList( http.get("http://twitter4j.org/en/testcases/direct_messages.json"), conf); DirectMessage dm = directMessages.get(0); Assert.assertEquals(new java.util.Date(1248177356000l), dm.getCreatedAt()); Assert.assertEquals(6358482, dm.getRecipient().getId()); Assert.assertEquals(246928323, dm.getId()); Assert.assertEquals(6358482, dm.getRecipientId()); Assert.assertEquals("twit4j", dm.getRecipientScreenName()); Assert.assertEquals(6377362, dm.getSender().getId()); Assert.assertEquals(6377362, dm.getSenderId()); Assert.assertEquals("twit4j2", dm.getSenderScreenName()); Assert.assertEquals("Tue Jul 21 20:55:39 KST 2009:directmessage test", dm.getText()); assertDeserializedFormIsEqual(directMessages); }
@Override public void onDirectMessage(DirectMessage directMessage) { Debug.logln( "TwitterServer.onDirectMessage sender: " + directMessage.getSenderScreenName() + " recipient: " + directMessage.getRecipientScreenName() + " text: " + directMessage.getText()); if (directMessage.getSenderId() == this.ownerID) { return; // outgoing message } // incoming message String text = directMessage.getText(); String sender = directMessage.getSenderScreenName(); String recipient = directMessage.getRecipientScreenName(); // Detect trackback Trackback trackback = null; try { trackback = TrackbackStore.getInstance().loadByIncomingText(Channel.TWITTER, sender, text); } catch (Exception e) { LogEntryStore.log(e); } if (trackback == null) { // !$! Send back error message? return; } // Dispatch event TwitterMessage msg = new TwitterMessage(); msg.setDestination(recipient); msg.setSender(sender); msg.write(TrackbackStore.getInstance().cleanIncomingText(text)); this.listener.onTwitterReceived(msg, trackback.getExternalID()); }