Example usage for twitter4j DirectMessage getText

List of usage examples for twitter4j DirectMessage getText

Introduction

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

Prototype

String getText();

Source Link

Usage

From source file:net.lacolaco.smileessence.view.dialog.MessageMenuDialogFragment.java

License:Open Source License

public void addBottomCommands(Activity activity, DirectMessage message, Account account,
        ArrayList<Command> commands) {
    commands.add(new CommandSaveAsTemplate(activity, message.getText()));
    //User/* w  w w  . ja  v  a2  s . c  o m*/
    for (String screenName : TwitterUtils.getScreenNames(message, null)) {
        commands.add(new CommandOpenUserDetail(activity, screenName, account));
    }
    for (Command command : getHashtagCommands(activity, message)) {
        commands.add(command);
    }
    // Media
    if (message.getURLEntities() != null) {
        for (URLEntity urlEntity : message.getURLEntities()) {
            commands.add(new CommandOpenURL(activity, urlEntity.getExpandedURL()));
        }
    }
    for (MediaEntity mediaEntity : message.getExtendedMediaEntities().length == 0 ? message.getMediaEntities()
            : message.getExtendedMediaEntities()) {
        commands.add(new CommandOpenURL(activity, mediaEntity.getMediaURL()));
    }
}

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

License:Open Source License

public MessageViewModel(DirectMessage directMessage, Account account) {
    id = directMessage.getId();//ww w  .  j  av 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:net.nokok.twitduke.core.twitter.PrintUserStreamListener.java

License:Open Source License

@Override
public void onDirectMessage(DirectMessage directMessage) {
    System.out//www  .j  a v a2 s .  c  o m
            .println("onDirectMessage: " + directMessage.getSenderScreenName() + "," + directMessage.getText());
}

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());
    return s.toString();
}

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

License:Open Source License

/**
 * Process the direct message.//from  w  w  w .j a va  2  s.  co  m
 */
@Override
public void input(Object input, Network network) {
    if (!isEnabled()) {
        return;
    }
    try {
        if (input instanceof DirectMessage) {
            DirectMessage message = (DirectMessage) input;
            String fromUser = message.getSender().getScreenName();
            String text = message.getText().trim();
            log("Processing direct message.", Level.INFO, text, fromUser);
            TextStream stream = new TextStream(text);
            String firstWord = stream.nextWord();
            if ("follow".equals(firstWord) && getFollowMessages()) {
                log("Adding friend.", Level.INFO, fromUser);
                getConnection().createFriendship(message.getSender().getId());
            } else if ("unfollow".equals(firstWord)) {
                log("Removing friend.", Level.INFO, fromUser);
                getConnection().destroyFriendship(message.getSender().getId());
            }
            this.tweetsProcessed++;
            inputSentence(text, fromUser, message.getRecipient().getScreenName(),
                    String.valueOf(message.getSender().getId()), network);
        }
    } 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 ww .  j a v  a 2s. 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.ja va 2 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 {//from   ww w.  j  av a  2s.  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) {
        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 www . jav  a 2  s. c  o m
        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.openhab.action.twitter.internal.Twitter.java

License:Open Source License

/**
 * Sends a direct message via Twitter/*from   w  w w . ja va 2 s. c  om*/
 * 
 * @param recipientId the receiver of this direct message
 * @param messageTxt the direct message to send
 * 
 * @return <code>true</code>, if sending the direct message has been successful and
 *         <code>false</code> in all other cases.
 */
@ActionDoc(text = "Sends a direct message via Twitter", returns = "<code>true</code>, if sending the direct message has been successful and <code>false</code> in all other cases.")
public static boolean sendDirectMessage(
        @ParamDoc(name = "recipientId", text = "the receiver of this direct message") String recipientId,
        @ParamDoc(name = "messageTxt", text = "the direct message to send") String messageTxt) {
    if (!isEnabled) {
        logger.debug("Twitter client is disabled > execution aborted!");
        return false;
    }

    try {
        // abbreviate the Tweet to meet the 140 character limit ...
        messageTxt = StringUtils.abbreviate(messageTxt, CHARACTER_LIMIT);
        // send the direct message
        DirectMessage message = client.sendDirectMessage(recipientId, messageTxt);
        logger.debug("Successfully sent direct message '{}' to @", message.getText(),
                message.getRecipientScreenName());
        return true;
    } catch (TwitterException e) {
        logger.error("Failed to send Tweet '" + messageTxt + "' because of: " + e.getLocalizedMessage());
        return false;
    }
}