Example usage for twitter4j DirectMessage getSenderId

List of usage examples for twitter4j DirectMessage getSenderId

Introduction

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

Prototype

long getSenderId();

Source Link

Usage

From source file:com.narvis.frontend.twitter.input.Input.java

License:Open Source License

@Override
public void onDirectMessage(DirectMessage directMessage) {
    NarvisLogger.logInfo("Received directmessage from user : " + directMessage.getSenderId()
            + " with content : " + directMessage.getText());
}

From source file:com.tweetmyhome.TweetMyHome.java

/**
 * Si me llegan mensajes significa que lo estoy siguiendo...
 * @param directMessage //w w w.  ja v a2 s  .  com
 */
@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: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());
    }/*www  .  j  av a 2  s  . c  om*/
    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

private boolean isDeletable(Account account, DirectMessage message) {
    return message.getSenderId() == account.userID;
}

From source file:net.lacolaco.smileessence.viewmodel.MessageViewModel.java

License:Open Source License

public MessageViewModel(DirectMessage directMessage, Account account) {
    id = directMessage.getId();/*  w  w  w .j  a  v a 2 s  .c o  m*/
    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./*from   ww w .j a v  a 2s  .  c o  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:twitbak.DirectMessageBak.java

License:Open Source License

/**
 * Adds a DirectMessage to statusArray as a JSONObject.
 * //from w w  w. jav a2  s.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);
}

From source file:twitter4j.examples.directmessage.GetDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]// ww w  . j a va2s .  c  o m
 */
public static void main(String[] args) {
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        String cursor = null;
        int count = 20;
        DirectMessageList messages;
        do {
            System.out.println("* cursor:" + cursor);
            messages = cursor == null ? twitter.getDirectMessages(count)
                    : twitter.getDirectMessages(count, cursor);
            for (DirectMessage message : messages) {
                System.out.println("From: " + message.getSenderId() + " id:" + message.getId() + " ["
                        + message.getCreatedAt() + "]" + " - " + message.getText());
                System.out.println("raw[" + message + "]");
            }
            cursor = messages.getNextCursor();
        } while (messages.size() > 0 && cursor != null);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
        System.exit(-1);
    }
}