Example usage for twitter4j DirectMessage getRecipientId

List of usage examples for twitter4j DirectMessage getRecipientId

Introduction

In this page you can find the example usage for twitter4j DirectMessage getRecipientId.

Prototype

long getRecipientId();

Source Link

Usage

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 w  w  .j a  va  2  s  . com*/
    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.viewmodel.MessageViewModel.java

License:Open Source License

public MessageViewModel(DirectMessage directMessage, Account account) {
    id = directMessage.getId();//  ww w.ja  va2 s . com
    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();
    createdAt = directMessage.getCreatedAt();
    myMessage = isMyMessage(account);
}

From source file:org.botlibre.sense.twitter.TwitterDirectMessaging.java

License:Open Source License

/**
 * Check direct messages and reply./*ww w .ja  v  a 2  s.  co m*/
 */
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.tweetalib.android.model.TwitterDirectMessage.java

License:Apache License

public TwitterDirectMessage(DirectMessage message, User otherUser) {
    mId = message.getId();//  w  ww . j  a  v  a 2  s.  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:org.tweetalib.android.model.TwitterDirectMessages.java

License:Apache License

private User getOtherParty(DirectMessage directMessage) {
    if (mMessageOwnerId != directMessage.getRecipientId()) {
        return directMessage.getRecipient();
    }//from  w ww.j a  v a 2  s  .c  om

    return directMessage.getSender();
}