Example usage for twitter4j Status getQuotedStatus

List of usage examples for twitter4j Status getQuotedStatus

Introduction

In this page you can find the example usage for twitter4j Status getQuotedStatus.

Prototype

Status getQuotedStatus();

Source Link

Document

Returns the Tweet object of the original Tweet that was quoted.

Usage

From source file:org.mariotaku.twidere.util.ContentValuesCreator.java

License:Open Source License

@NonNull
public static ContentValues createStatus(final Status orig, final long accountId) {
    if (orig == null)
        throw new NullPointerException();
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, accountId);
    values.put(Statuses.STATUS_ID, orig.getId());
    values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime());
    final Status status;
    if (orig.isRetweet()) {
        final Status retweetedStatus = orig.getRetweetedStatus();
        final User retweetUser = orig.getUser();
        final long retweetedById = retweetUser.getId();
        values.put(Statuses.RETWEET_ID, retweetedStatus.getId());
        values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime());
        values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById);
        values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName());
        values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName());
        values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps()));
        values.put(Statuses.IS_RETWEET, true);
        if (retweetedById == accountId) {
            values.put(Statuses.MY_RETWEET_ID, orig.getId());
        } else {/* www . j a  v a 2s  .  co  m*/
            values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        }
        status = retweetedStatus;
    } else if (orig.isQuote()) {
        final Status quotedStatus = orig.getQuotedStatus();
        final User quoteUser = orig.getUser();
        final long quotedById = quoteUser.getId();
        values.put(Statuses.QUOTE_ID, quotedStatus.getId());
        final String textHtml = TwitterContentUtils.formatStatusText(orig);
        values.put(Statuses.QUOTE_TEXT_HTML, textHtml);
        values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText());
        values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml));
        values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime());
        values.put(Statuses.QUOTE_SOURCE, orig.getSource());
        final ParcelableMedia[] quoteMedia = ParcelableMedia.fromStatus(orig);
        if (quoteMedia != null && quoteMedia.length > 0) {
            try {
                values.put(Statuses.QUOTE_MEDIA_JSON,
                        LoganSquare.serialize(Arrays.asList(quoteMedia), ParcelableMedia.class));
            } catch (IOException ignored) {
            }
        }
        values.put(Statuses.QUOTED_BY_USER_ID, quotedById);
        values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName());
        values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName());
        values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps());
        values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified());
        values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected());
        values.put(Statuses.IS_QUOTE, true);
        status = quotedStatus;
    } else {
        values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        status = orig;
    }
    if (orig.isRetweet()) {
        values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
        values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
        values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status));
        values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName());
    } else {
        values.put(Statuses.IN_REPLY_TO_STATUS_ID, orig.getInReplyToStatusId());
        values.put(Statuses.IN_REPLY_TO_USER_ID, orig.getInReplyToUserId());
        values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(orig));
        values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, orig.getInReplyToScreenName());
    }
    final User user = status.getUser();
    final long userId = user.getId();
    final String profileImageUrl = (user.getProfileImageUrlHttps());
    final String name = user.getName(), screenName = user.getScreenName();
    values.put(Statuses.USER_ID, userId);
    values.put(Statuses.USER_NAME, name);
    values.put(Statuses.USER_SCREEN_NAME, screenName);
    values.put(Statuses.IS_PROTECTED, user.isProtected());
    values.put(Statuses.IS_VERIFIED, user.isVerified());
    values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl);
    values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    final String textHtml = TwitterContentUtils.formatStatusText(status);
    values.put(Statuses.TEXT_HTML, textHtml);
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml));
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.REPLY_COUNT, status.getReplyCount());
    values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount());
    values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION,
                ParcelableLocation.toString(location.getLatitude(), location.getLongitude()));
    }
    final Place place = status.getPlace();
    if (place != null) {
        values.put(Statuses.PLACE_FULL_NAME, place.getFullName());
    }
    values.put(Statuses.IS_FAVORITE, status.isFavorited());
    final ParcelableMedia[] media = ParcelableMedia.fromStatus(status);
    if (media != null && media.length > 0) {
        try {
            values.put(Statuses.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(media), ParcelableMedia.class));
        } catch (IOException ignored) {
        }
    }
    final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status);
    if (mentions != null && mentions.length > 0) {
        try {
            values.put(Statuses.MENTIONS_JSON,
                    LoganSquare.serialize(Arrays.asList(mentions), ParcelableUserMention.class));
        } catch (IOException ignored) {
        }
    }
    final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId);
    if (card != null) {
        try {
            values.put(Statuses.CARD, LoganSquare.serialize(card));
            values.put(Statuses.CARD_NAME, card.name);
        } catch (IOException ignored) {
        }
    }
    return values;
}