List of usage examples for twitter4j DirectMessage getId
long getId();
From source file:com.tweetmyhome.TweetMyHome.java
private void sendDm(long idDestiny, String text) { try {//from w w w . jav a2 s . com long superUserId = db.getSuperAdminId(); DirectMessage dm = tw.sendDirectMessage(idDestiny, text); db.add(new SimpleDirectMessage(this, dm.getId(), superUserId, null, text, Calendar.getInstance().getTimeInMillis())); tweetCount.incementCount(); } catch (TwitterException ex) { error(ex.toString(), ex); } }
From source file:com.tweetmyhome.TweetMyHome.java
/** * Si me llegan mensajes significa que lo estoy siguiendo... * @param directMessage //w ww . ja v a 2 s . c om */ @Override public void onDirectMessage(DirectMessage directMessage) { String text = directMessage.getText(); debug("onDirectMessage text: @" + directMessage.getSender().getScreenName() + " : " + text); if (TwitterUserUtil.equals(directMessage.getSender().getScreenName(), p.getValueByKey(Key.twitterSuperUser))) { debug("Own tweet detected..."); return; } User user = directMessage.getSender(); TweetStringAnalizer tsa; try { tsa = new TweetStringAnalizer(text, tweetDictionary); if (!tsa.isErrorFounded()) { db.add(new SimpleDirectMessage(this, directMessage.getId(), directMessage.getSenderId(), null, text, Calendar.getInstance().getTimeInMillis())); analyzeAndRespond(user, tsa, true); } else { // pasa si no reconose el mensaje error(tsa.getErrorString().toString()); } } catch (TweetStringException | TwitterException | TweetMyHomeException ex) { error(ex.toString(), ex); } }
From source file:de.vanita5.twittnuker.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_string = sender != null ? ParseUtils.parseString(sender.getProfileImageUrlHttps()) : null;/*w w w . j a v a 2 s . c o m*/ final String recipient_profile_image_url_string = recipient != null ? ParseUtils.parseString(recipient.getProfileImageUrlHttps()) : null; id = message.getId(); timestamp = getTime(message.getCreatedAt()); sender_id = sender != null ? sender.getId() : -1; recipient_id = recipient != null ? recipient.getId() : -1; text_html = 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; sender_profile_image_url = sender_profile_image_url_string; recipient_profile_image_url = recipient_profile_image_url_string; text_unescaped = toPlainText(text_html); medias = ParcelableMedia.fromEntities(message); first_media = medias != null && medias.length > 0 ? medias[0].url : null; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeDirectMessageContentValues(final DirectMessage message, final long account_id, final boolean is_outgoing, final boolean large_profile_image) { if (message == null || message.getId() <= 0) 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 = ParseUtils.parseString(sender.getProfileImageUrlHttps()); final String recipient_profile_image_url = ParseUtils.parseString(recipient.getProfileImageUrlHttps()); values.put(DirectMessages.ACCOUNT_ID, account_id); 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()); final String text_html = Utils.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, is_outgoing); 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, large_profile_image ? getBiggerTwitterProfileImage(sender_profile_image_url) : sender_profile_image_url); values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, large_profile_image ? getBiggerTwitterProfileImage(recipient_profile_image_url) : recipient_profile_image_url); final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message); if (mediaArray != null) { values.put(DirectMessages.MEDIA, JSONSerializer.toJSONArrayString(mediaArray)); values.put(DirectMessages.FIRST_MEDIA, mediaArray[0].url); }/*from w w w . j av a 2s .c o m*/ return values; }
From source file:de.vanita5.twittnuker.util.Utils.java
License:Open Source License
public static boolean truncateMessages(final List<DirectMessage> in, final List<DirectMessage> out, final long since_id) { if (in == null) return false; for (final DirectMessage message : in) { if (since_id > 0 && message.getId() <= since_id) { continue; }// w w w . j a v a2 s .c o m out.add(message); } return in.size() != out.size(); }
From source file:net.lacolaco.smileessence.data.DirectMessageCache.java
License:Open Source License
/** * Put message into cache/*from ww w . ja va 2 s .c o m*/ * * @param message * @return the previous value associated with key, or null if there was no mapping for key */ public DirectMessage put(DirectMessage message) { return cache.put(message.getId(), message); }
From source file:net.lacolaco.smileessence.view.dialog.MessageDetailDialogFragment.java
License:Open Source License
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { MainActivity activity = (MainActivity) getActivity(); final Account account = activity.getCurrentAccount(); DirectMessage selectedMessage = DirectMessageCache.getInstance().get(getMessageID()); if (selectedMessage == null) { Notificator.publish(getActivity(), R.string.notice_error_get_messages); return new DisposeDialog(getActivity()); }/*w ww . j a v a 2 s .c o m*/ View header = getTitleView(activity, account, selectedMessage); ListView listView = (ListView) header.findViewById(R.id.listview_status_detail_reply_to); final MessageListAdapter adapter = new MessageListAdapter(getActivity()); listView.setAdapter(adapter); long replyToMessageId = -1; ArrayList<DirectMessage> allMessages = Lists.newArrayList(DirectMessageCache.getInstance().all()); Collections.sort(allMessages, new Comparator<DirectMessage>() { @Override public int compare(DirectMessage lhs, DirectMessage rhs) { return rhs.getCreatedAt().compareTo(lhs.getCreatedAt()); } }); for (DirectMessage directMessage : allMessages) { if (selectedMessage.getId() == directMessage.getId()) { continue; } if (directMessage.getCreatedAt().getTime() > selectedMessage.getCreatedAt().getTime()) { continue; } if (directMessage.getSenderId() == selectedMessage.getRecipientId() && directMessage.getRecipientId() == selectedMessage.getSenderId()) { replyToMessageId = directMessage.getId(); break; } } if (replyToMessageId == -1) { listView.setVisibility(View.GONE); } else { TwitterUtils.tryGetMessage(account, replyToMessageId, new TwitterUtils.MessageCallback() { @Override public void success(DirectMessage message) { adapter.addToTop(new MessageViewModel(message, account)); adapter.updateForce(); } @Override public void error() { } }); } return new AlertDialog.Builder(getActivity()).setView(header).create(); }
From source file:net.lacolaco.smileessence.view.dialog.MessageDetailDialogFragment.java
License:Open Source License
public void deleteMessage(final Account account, final DirectMessage message) { ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), new Runnable() { @Override//w ww. ja v a 2 s . c o m public void run() { new DeleteMessageTask(new TwitterApi(account).getTwitter(), message.getId(), getActivity()) .execute(); dismiss(); } }); }
From source file:net.lacolaco.smileessence.viewmodel.MessageViewModel.java
License:Open Source License
public MessageViewModel(DirectMessage directMessage, Account account) { id = directMessage.getId(); UserCache.getInstance().put(directMessage.getSender()); senderID = directMessage.getSenderId(); senderScreenName = directMessage.getSenderScreenName(); senderName = directMessage.getSender().getName(); senderIconURL = directMessage.getSender().getProfileImageURL(); recipientId = directMessage.getRecipientId(); recipientScreenName = directMessage.getRecipientScreenName(); text = directMessage.getText();//from ww w . ja va 2s . c o m createdAt = directMessage.getCreatedAt(); myMessage = isMyMessage(account); }
From source file:org.apache.camel.component.twitter.consumer.directmessage.DirectMessageConsumer.java
License:Apache License
public List<DirectMessage> pollConsume() throws TwitterException { List<DirectMessage> list = te.getProperties().getTwitter().getDirectMessages(new Paging(lastId)); for (DirectMessage dm : list) { checkLastId(dm.getId()); }//from w w w . j a v a2 s .co m return list; }