List of usage examples for twitter4j DirectMessage getCreatedAt
Date getCreatedAt();
From source file:org.apache.camel.component.twitter.util.TwitterConverter.java
License:Apache License
@Converter public static String toString(DirectMessage dm) throws ParseException { StringBuilder s = new StringBuilder(); s.append(dm.getCreatedAt()).append(" (").append(dm.getSenderScreenName()).append(") "); s.append(dm.getText());// ww w .ja va 2 s. c o m return s.toString(); }
From source file:org.botlibre.sense.twitter.TwitterDirectMessaging.java
License:Open Source License
/** * Check direct messages and reply./*w ww . j a v a 2s.com*/ */ public void checkDirectMessages() { if (!getReplyToMessages()) { // Always check, as gated by Twitter sense. //return; } try { if (getConnection() == null) { connect(); } ResponseList<DirectMessage> messages = getConnection().getDirectMessages(); if (!messages.isEmpty()) { Network memory = getBot().memory().newMemory(); Vertex twitter = memory.createVertex(getPrimitive()); Vertex vertex = twitter.getRelationship(Primitive.LASTDIRECTMESSAGE); long lastMessage = 0; if (vertex != null) { lastMessage = ((Number) vertex.getData()).longValue(); } long max = 0; for (DirectMessage message : messages) { if ((System.currentTimeMillis() - message.getCreatedAt().getTime()) > DAY) { continue; } if (message.getCreatedAt().getTime() > lastMessage) { if (message.getSenderId() != message.getRecipientId()) { input(message); } if (message.getCreatedAt().getTime() > max) { max = message.getCreatedAt().getTime(); } } } if (max != 0) { twitter.setRelationship(Primitive.LASTDIRECTMESSAGE, memory.createVertex(max)); memory.save(); } } } catch (Exception exception) { log(exception); } }
From source file:org.getlantern.firetweet.model.ParcelableDirectMessage.java
License:Open Source License
public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_outgoing) { this.account_id = account_id; this.is_outgoing = is_outgoing; final User sender = message.getSender(), recipient = message.getRecipient(); final String sender_profile_image_url = sender != null ? sender.getProfileImageUrlHttps() : null; final String recipient_profile_image_url = recipient != null ? recipient.getProfileImageUrlHttps() : null; id = message.getId();// w w w. ja va 2 s . c o m timestamp = getTime(message.getCreatedAt()); sender_id = sender != null ? sender.getId() : -1; recipient_id = recipient != null ? recipient.getId() : -1; text_html = TwitterContentUtils.formatDirectMessageText(message); text_plain = message.getText(); sender_name = sender != null ? sender.getName() : null; recipient_name = recipient != null ? recipient.getName() : null; sender_screen_name = sender != null ? sender.getScreenName() : null; recipient_screen_name = recipient != null ? recipient.getScreenName() : null; this.sender_profile_image_url = sender_profile_image_url; this.recipient_profile_image_url = recipient_profile_image_url; text_unescaped = toPlainText(text_html); media = ParcelableMedia.fromEntities(message); }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createDirectMessage(final DirectMessage message, final long accountId, final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); final User sender = message.getSender(), recipient = message.getRecipient(); if (sender == null || recipient == null) return null; final String sender_profile_image_url = sender.getProfileImageUrlHttps(); final String recipient_profile_image_url = recipient.getProfileImageUrlHttps(); values.put(DirectMessages.ACCOUNT_ID, accountId); values.put(DirectMessages.MESSAGE_ID, message.getId()); values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime()); values.put(DirectMessages.SENDER_ID, sender.getId()); values.put(DirectMessages.RECIPIENT_ID, recipient.getId()); if (isOutgoing) { values.put(DirectMessages.CONVERSATION_ID, recipient.getId()); } else {//from w w w . j av a2 s . c om values.put(DirectMessages.CONVERSATION_ID, sender.getId()); } final String text_html = TwitterContentUtils.formatDirectMessageText(message); values.put(DirectMessages.TEXT_HTML, text_html); values.put(DirectMessages.TEXT_PLAIN, message.getText()); values.put(DirectMessages.TEXT_UNESCAPED, toPlainText(text_html)); values.put(DirectMessages.IS_OUTGOING, isOutgoing); values.put(DirectMessages.SENDER_NAME, sender.getName()); values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName()); values.put(DirectMessages.RECIPIENT_NAME, recipient.getName()); values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName()); values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url); values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url); final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message); if (mediaArray != null) { values.put(DirectMessages.MEDIA_LIST, SimpleValueSerializer.toSerializedString(mediaArray)); } return values; }
From source file:org.mariotaku.twidere.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createDirectMessage(final DirectMessage message, final long accountId, final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); final User sender = message.getSender(), recipient = message.getRecipient(); if (sender == null || recipient == null) return null; final String sender_profile_image_url = sender.getProfileImageUrlHttps(); final String recipient_profile_image_url = recipient.getProfileImageUrlHttps(); values.put(DirectMessages.ACCOUNT_ID, accountId); values.put(DirectMessages.MESSAGE_ID, message.getId()); values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime()); values.put(DirectMessages.SENDER_ID, sender.getId()); values.put(DirectMessages.RECIPIENT_ID, recipient.getId()); if (isOutgoing) { values.put(DirectMessages.CONVERSATION_ID, recipient.getId()); } else {//w ww .j av a 2 s .c o m values.put(DirectMessages.CONVERSATION_ID, sender.getId()); } final String text_html = TwitterContentUtils.formatDirectMessageText(message); values.put(DirectMessages.TEXT_HTML, text_html); values.put(DirectMessages.TEXT_PLAIN, message.getText()); values.put(DirectMessages.TEXT_UNESCAPED, toPlainText(text_html)); values.put(DirectMessages.IS_OUTGOING, isOutgoing); values.put(DirectMessages.SENDER_NAME, sender.getName()); values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName()); values.put(DirectMessages.RECIPIENT_NAME, recipient.getName()); values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName()); values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url); values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url); final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message); if (mediaArray != null) { try { values.put(DirectMessages.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(mediaArray), ParcelableMedia.class)); } catch (IOException ignored) { } } return values; }
From source file:org.nsoft.openbus.model.Mensagem.java
License:Open Source License
public static Mensagem createFromDirectMensagem(DirectMessage dm) { try {//from w ww . j a v a 2s .c om Mensagem mensagem = new Mensagem(); mensagem.setAction(OpenTwitterStatusAction.getInstance()); mensagem.idMensagem = Long.toString(dm.getId()); mensagem.nome_usuario = dm.getSender().getName(); mensagem.mensagem = dm.getText(); // mensagem.imagePath = dm.getSender().getProfileImageURL(); mensagem.data = dm.getCreatedAt(); mensagem.idUser = dm.getSender().getId(); mensagem.tipo = TIPO_STATUS; return mensagem; } catch (Exception e) { return null; } }
From source file:org.osframework.maven.plugins.twitter.DirectMessageMojo.java
License:Apache License
private void logDirectMessage(DirectMessage dm) { StringBuilder logMsg = new StringBuilder(formatDate(dm.getCreatedAt())).append(" ") .append(dm.getRecipientScreenName()).append(" ").append(dm.getText()); File logFile = new File(getWorkDirectory(), "dm.log"); BufferedWriter writer = null; try {/* w w w . j ava 2 s. com*/ writer = new BufferedWriter(new FileWriter(logFile, true)); writer.write(logMsg.toString()); } catch (IOException ioe) { getLog().warn("Could not write status to dm.log"); } finally { IOUtil.close(writer); } }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Creates a content for the given message, adds it to the data set and sets * the author.//from w w w . ja v a2 s.c om * * @param author * Person corresponding to the twitter user which authored the * message * @param author * Person corresponding to the twitter user which received the * message * @param directMessage * The twitter status * @return The Content created from the status, null in error case. */ private Content createContentFromTwitterDirectMessage(Person author, Person receipient, DirectMessage directMessage) { if (directMessage == null) { return null; } String messageText = directMessage.getText(); if (messageText == null || messageText.isEmpty()) { return null; } String ident = directMessage.getId() + ""; if (this.getContentWithSourceIdent(ident) != null) { // message already created return null; } Content message = factory.createContent(); message.setStringValue(messageText); message.setName(createTitleFromTwitterText(messageText)); message.metaTag(TwitterTags.TWITTER); message = (Content) this.add(message, ident); if (message == null) { return null; } if (author != null) { message.setAuthor(author); } message.setCreated(directMessage.getCreatedAt()); if (receipient != null) { // set receiver as contributor message.getContributors().add(receipient); } message.metaTag(TwitterTags.DIRECT_MESSAGE); return message; }
From source file:org.tweetalib.android.model.TwitterDirectMessage.java
License:Apache License
public TwitterDirectMessage(DirectMessage message, User otherUser) { mId = message.getId();/* w ww. ja v a2s . c o m*/ mText = message.getText(); mStatusFullMarkup = TwitterUtil.getStatusMarkup(mText, message.getMediaEntities(), message.getURLEntities()); mTextSpanned = URLSpanNoUnderline .stripUnderlines(Html.fromHtml(mStatusFullMarkup.replace("\n", "<br/>") + " ")); mCreatedAt = message.getCreatedAt(); mOtherUserId = otherUser.getId(); mRecipientUserId = message.getRecipientId(); mOtherUserScreenName = otherUser.getScreenName(); mOtherUserName = otherUser.getName(); mOtherUserProfileImageOriginalUrl = otherUser.getOriginalProfileImageURL(); mOtherUserProfileImageMiniUrl = otherUser.getMiniProfileImageURL(); mOtherUserProfileImageNormalUrl = otherUser.getProfileImageURL(); mOtherUserProfileImageBiggerUrl = otherUser.getBiggerProfileImageURL(); TwitterUser sender = new TwitterUser(message.getSender()); mSenderProfileImageOriginalUrl = sender.getProfileImageUrlOriginal(); mSenderProfileImageMiniUrl = sender.getProfileImageUrlMini(); mSenderProfileImageNormalUrl = sender.getProfileImageUrlNormal(); mSenderProfileImageBiggerUrl = sender.getProfileImageUrlBigger(); mMessageType = mRecipientUserId == mOtherUserId ? MessageType.SENT : MessageType.RECEIVED; }
From source file:twitbak.DirectMessageBak.java
License:Open Source License
/** * Adds a DirectMessage to statusArray as a JSONObject. * //from ww w. ja va2s . c o m * @param dm * @throws TwitterException * @throws JSONException */ private void dmToJson(DirectMessage dm) throws TwitterException, JSONException { JSONObject result = new JSONObject(); result.put("Created At", dm.getCreatedAt().toString()); result.put("ID", dm.getId()); result.put("Text", dm.getText()); result.put("Sender ID", dm.getSenderId()); result.put("Sender", dm.getSender().getScreenName()); result.put("Sender Name", dm.getSender().getName()); statusArray.put(result); }