List of usage examples for twitter4j Status getRetweetedStatus
Status getRetweetedStatus();
From source file:net.lacolaco.smileessence.viewmodel.EventViewModel.java
License:Open Source License
public EventViewModel(EnumEvent event, User source, Status status) { this.event = event; this.createdAt = new Date(); this.sourceUserID = source.getId(); this.sourceScreenName = source.getScreenName(); this.sourceName = source.getName(); this.iconURL = source.getProfileImageURL(); if (status != null) { if (event == EnumEvent.RETWEETED) { this.targetStatusID = status.getRetweetedStatus().getId(); this.targetText = status.getRetweetedStatus().getText(); } else {// ww w . j ava 2 s .com this.targetStatusID = status.getId(); this.targetText = status.getText(); } } else { this.targetStatusID = -1L; this.targetText = ""; } }
From source file:net.lacolaco.smileessence.viewmodel.StatusViewModel.java
License:Open Source License
public StatusViewModel(Status status, Account account) { if (status.isRetweet()) { retweetedStatus = new StatusViewModel(status.getRetweetedStatus(), account); }//from w ww. j a va2s. co m id = status.getId(); text = TwitterUtils.replaceURLEntities(status.getText(), status.getURLEntities(), false); createdAt = status.getCreatedAt(); source = status.getSource(); mentions = status.getUserMentionEntities(); hashtags = status.getHashtagEntities(); media = status.getMediaEntities(); urls = status.getURLEntities(); symbols = status.getSymbolEntities(); User user = status.getUser(); UserCache.getInstance().put(user); userID = user.getId(); screenName = user.getScreenName(); name = user.getName(); iconURL = user.getProfileImageURLHttps(); isProtected = user.isProtected(); setMention(isMention(account.screenName)); setMyStatus(isMyStatus(account.userID)); setRetweetOfMe(isRetweetOfMe(account.userID)); }
From source file:net.nokok.twitduke.core.type.TweetModel.java
License:Open Source License
public TweetModel(Status status) { User user = status.getUser();/* w ww . j av a2 s . co m*/ this.screenName = new ScreenName(status.getUser().getScreenName()); if (status.getRetweetedStatus() != null) { this.retweetedStatus = Optional.of(new TweetModel(status.getRetweetedStatus())); } else { this.retweetedStatus = Optional.empty(); } }
From source file:net.nokok.twitduke.core.view.async.OverlayUserIcon.java
License:Open Source License
public OverlayUserIcon(Status status) { setPreferredSize(new Dimension(50, 50)); Status retweetedStatus = Optional.ofNullable(status.getRetweetedStatus()) .orElseThrow(IllegalArgumentException::new); AsyncImageLoader userIconTask = new AsyncImageLoader(getProfileImageUrl(status)); AsyncImageLoader rtIconTask = new AsyncImageLoader(getProfileImageUrl(retweetedStatus)); setLayout(new OverlayLayout(this)); userIconTask.onSuccess(icon -> {/*from www .j av a2 s . c o m*/ Image s = icon.getImage().getScaledInstance(25, 25, Image.SCALE_DEFAULT); smallIcon = s; }); rtIconTask.onSuccess(icon -> { Image s = icon.getImage().getScaledInstance(50, 50, Image.SCALE_DEFAULT); while (smallIcon == null) { //???????add????????????????? } add(new JLabel(new ImageIcon(smallIcon))); add(new JLabel(new ImageIcon(s))); }); UIAsyncTaskPool.INSTANCE.runTask(userIconTask); UIAsyncTaskPool.INSTANCE.runTask(rtIconTask); }
From source file:net.nokok.twitduke.core.view.tweetcell.TweetPanelFactoryImpl.java
License:Open Source License
/** * ???????????/* w w w .jav a2 s.c o m*/ * * @param status ? * @param accessToken * */ public TweetPanelFactoryImpl(Status status, AccessToken accessToken) { this.status = status; this.accessToken = accessToken; retweetedStatus = Optional.ofNullable(status.getRetweetedStatus()); //???RetweeteeStatus?????????status? activeStatus = retweetedStatus.orElseGet(() -> status); twitter = TAsyncTwitterFactory.newInstance(accessToken); this.screenName = accessToken.getScreenName(); }
From source file:nl.isaac.dotcms.twitter.pojo.CustomStatus.java
License:Creative Commons License
public CustomStatus(Status status) { this.createdAt = status.getCreatedAt(); this.id = status.getId(); this.id_str = String.valueOf(status.getId()); this.text = status.getText(); this.source = status.getSource(); this.isTruncated = status.isTruncated(); this.inReplyToStatusId = status.getInReplyToStatusId(); this.inReplyToUserId = status.getInReplyToUserId(); this.isFavorited = status.isFavorited(); this.inReplyToScreenName = status.getInReplyToScreenName(); this.geoLocation = status.getGeoLocation(); this.place = status.getPlace(); this.retweetCount = status.getRetweetCount(); this.isPossiblySensitive = status.isPossiblySensitive(); this.contributorsIDs = status.getContributors(); this.retweetedStatus = status.getRetweetedStatus(); this.userMentionEntities = status.getUserMentionEntities(); this.urlEntities = status.getURLEntities(); this.hashtagEntities = status.getHashtagEntities(); this.mediaEntities = status.getMediaEntities(); this.currentUserRetweetId = status.getCurrentUserRetweetId(); this.isRetweet = status.isRetweet(); this.isRetweetedByMe = status.isRetweetedByMe(); this.rateLimitStatus = status.getRateLimitStatus(); this.accessLevel = status.getAccessLevel(); this.user = status.getUser(); }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
@Override public View getView(int position, View convertView, ViewGroup parent) { Status tweet = getItem(position); TwitterStreamViewHolder holder;/*from w w w.j av a2 s.com*/ if (convertView == null) { LinkMovementMethod lmm = new DreamLinkMovementMethod(mDream); convertView = LayoutInflater.from(mDream).inflate(R.layout.tweet_row, parent, false); holder = new TwitterStreamViewHolder(); holder.authorImage = (ImageView) convertView.findViewById(R.id.tweet_author_image); holder.author = (TextView) convertView.findViewById(R.id.tweet_author); holder.author.setMovementMethod(lmm); holder.username = (TextView) convertView.findViewById(R.id.tweet_username); holder.username.setMovementMethod(lmm); holder.timestamp = (TextView) convertView.findViewById(R.id.tweet_timestamp); holder.timestamp.setMovementMethod(lmm); holder.content = (TextView) convertView.findViewById(R.id.tweet_content); holder.content.setMovementMethod(lmm); holder.retweetIcon = convertView.findViewById(R.id.tweet_retweet_icon); holder.retweetAuthor = (TextView) convertView.findViewById(R.id.tweet_retweet_author); holder.retweetAuthor.setMovementMethod(lmm); holder.contentImage = (ImageView) convertView.findViewById(R.id.tweet_content_image); convertView.setTag(holder); } else { holder = (TwitterStreamViewHolder) convertView.getTag(); } if (tweet.isRetweet()) { // We have a retweet - setup the retweeting users details & retweet // icon. holder.retweetAuthor.setVisibility(View.VISIBLE); holder.retweetAuthor.setText(getTweetAuthor(tweet)); holder.retweetIcon.setVisibility(View.VISIBLE); // Then populate the rest of the view with the retweeted status. tweet = tweet.getRetweetedStatus(); } else { holder.retweetAuthor.setVisibility(View.GONE); holder.retweetIcon.setVisibility(View.GONE); } holder.author.setText(getTweetAuthor(tweet)); holder.username.setText(getTweetUsername(tweet)); holder.timestamp.setText(getTweetTimestamp(tweet)); holder.content.setText(getTweetText(tweet)); loadImages(holder, tweet); // Hide underlining/coloring of non-content links. hideLinks(holder); // Hide underlining of content links hideLinkUnderlines(holder); return convertView; }
From source file:org.apache.druid.examples.twitter.TwitterSpritzerFirehoseFactory.java
License:Apache License
@Override public Firehose connect(InputRowParser parser, File temporaryDirectory) { final ConnectionLifeCycleListener connectionLifeCycleListener = new ConnectionLifeCycleListener() { @Override/*from w ww . ja va2 s .c o m*/ public void onConnect() { log.info("Connected_to_Twitter"); } @Override public void onDisconnect() { log.info("Disconnect_from_Twitter"); } /** * called before thread gets cleaned up */ @Override public void onCleanUp() { log.info("Cleanup_twitter_stream"); } }; // ConnectionLifeCycleListener final TwitterStream twitterStream; final StatusListener statusListener; final int QUEUE_SIZE = 2000; /** This queue is used to move twitter events from the twitter4j thread to the druid ingest thread. */ final BlockingQueue<Status> queue = new ArrayBlockingQueue<Status>(QUEUE_SIZE); final long startMsec = System.currentTimeMillis(); // // set up Twitter Spritzer // twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addConnectionLifeCycleListener(connectionLifeCycleListener); statusListener = new StatusListener() { // This is what really gets called to deliver stuff from twitter4j @Override public void onStatus(Status status) { // time to stop? if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("Interrupted, time to stop"); } try { boolean success = queue.offer(status, 15L, TimeUnit.SECONDS); if (!success) { log.warn("queue too slow!"); } } catch (InterruptedException e) { throw new RuntimeException("InterruptedException", e); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { //log.info("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { // This notice will be sent each time a limited stream becomes unlimited. // If this number is high and or rapidly increasing, it is an indication that your predicate is too broad, and you should consider a predicate with higher selectivity. log.warn("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { //log.info("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onException(Exception ex) { log.error(ex, "Got exception"); } @Override public void onStallWarning(StallWarning warning) { log.warn("Got stall warning: %s", warning); } }; twitterStream.addListener(statusListener); twitterStream.sample(); // creates a generic StatusStream log.info("returned from sample()"); return new Firehose() { private final Runnable doNothingRunnable = new Runnable() { @Override public void run() { } }; private long rowCount = 0L; private boolean waitIfmax = (getMaxEventCount() < 0L); private final Map<String, Object> theMap = new TreeMap<>(); // DIY json parsing // private final ObjectMapper omapper = new ObjectMapper(); private boolean maxTimeReached() { if (getMaxRunMinutes() <= 0) { return false; } else { return (System.currentTimeMillis() - startMsec) / 60000L >= getMaxRunMinutes(); } } private boolean maxCountReached() { return getMaxEventCount() >= 0 && rowCount >= getMaxEventCount(); } @Override public boolean hasMore() { if (maxCountReached() || maxTimeReached()) { return waitIfmax; } else { return true; } } @Nullable @Override public InputRow nextRow() { // Interrupted to stop? if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("Interrupted, time to stop"); } // all done? if (maxCountReached() || maxTimeReached()) { if (waitIfmax) { // sleep a long time instead of terminating try { log.info("reached limit, sleeping a long time..."); Thread.sleep(2000000000L); } catch (InterruptedException e) { throw new RuntimeException("InterruptedException", e); } } else { // allow this event through, and the next hasMore() call will be false } } if (++rowCount % 1000 == 0) { log.info("nextRow() has returned %,d InputRows", rowCount); } Status status; try { status = queue.take(); } catch (InterruptedException e) { throw new RuntimeException("InterruptedException", e); } theMap.clear(); HashtagEntity[] hts = status.getHashtagEntities(); String text = status.getText(); theMap.put("text", (null == text) ? "" : text); theMap.put("htags", (hts.length > 0) ? Lists.transform(Arrays.asList(hts), new Function<HashtagEntity, String>() { @Nullable @Override public String apply(HashtagEntity input) { return input.getText(); } }) : ImmutableList.<String>of()); long[] lcontrobutors = status.getContributors(); List<String> contributors = new ArrayList<>(); for (long contrib : lcontrobutors) { contributors.add(StringUtils.format("%d", contrib)); } theMap.put("contributors", contributors); GeoLocation geoLocation = status.getGeoLocation(); if (null != geoLocation) { double lat = status.getGeoLocation().getLatitude(); double lon = status.getGeoLocation().getLongitude(); theMap.put("lat", lat); theMap.put("lon", lon); } else { theMap.put("lat", null); theMap.put("lon", null); } if (status.getSource() != null) { Matcher m = sourcePattern.matcher(status.getSource()); theMap.put("source", m.find() ? m.group(1) : status.getSource()); } theMap.put("retweet", status.isRetweet()); if (status.isRetweet()) { Status original = status.getRetweetedStatus(); theMap.put("retweet_count", original.getRetweetCount()); User originator = original.getUser(); theMap.put("originator_screen_name", originator != null ? originator.getScreenName() : ""); theMap.put("originator_follower_count", originator != null ? originator.getFollowersCount() : ""); theMap.put("originator_friends_count", originator != null ? originator.getFriendsCount() : ""); theMap.put("originator_verified", originator != null ? originator.isVerified() : ""); } User user = status.getUser(); final boolean hasUser = (null != user); theMap.put("follower_count", hasUser ? user.getFollowersCount() : 0); theMap.put("friends_count", hasUser ? user.getFriendsCount() : 0); theMap.put("lang", hasUser ? user.getLang() : ""); theMap.put("utc_offset", hasUser ? user.getUtcOffset() : -1); // resolution in seconds, -1 if not available? theMap.put("statuses_count", hasUser ? user.getStatusesCount() : 0); theMap.put("user_id", hasUser ? StringUtils.format("%d", user.getId()) : ""); theMap.put("screen_name", hasUser ? user.getScreenName() : ""); theMap.put("location", hasUser ? user.getLocation() : ""); theMap.put("verified", hasUser ? user.isVerified() : ""); theMap.put("ts", status.getCreatedAt().getTime()); List<String> dimensions = Lists.newArrayList(theMap.keySet()); return new MapBasedInputRow(status.getCreatedAt().getTime(), dimensions, theMap); } @Override public Runnable commit() { // ephemera in, ephemera out. return doNothingRunnable; // reuse the same object each time } @Override public void close() { log.info("CLOSE twitterstream"); twitterStream.shutdown(); // invokes twitterStream.cleanUp() } }; }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Retweet the tweet.//from www . ja v a 2s . c o m */ public void retweet(Status tweet) { if (tweet.isRetweet()) { tweet = tweet.getRetweetedStatus(); } if (tweet.getUser().isProtected()) { log("Cannot retweet protected user", Level.INFO, tweet.getUser().getScreenName(), tweet.getText()); return; } this.retweets++; log("Retweeting:", Level.INFO, tweet.getText(), tweet.getUser().getScreenName()); try { if (getConnection() == null) { connect(); } getConnection().retweetStatus(tweet.getId()); } catch (Exception exception) { if (exception.getMessage() != null && exception.getMessage().contains("authorized") && exception.getMessage().contains("endpoint")) { this.errors = this.errors + 5; } this.errors++; log(exception.toString(), Level.WARNING, tweet.getText()); } }
From source file:org.getlantern.firetweet.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) { this.is_gap = is_gap; this.account_id = account_id; id = orig.getId();/*from w w w . j a v a 2 s .c om*/ timestamp = getTime(orig.getCreatedAt()); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; is_retweet = orig.isRetweet(); retweet_id = retweeted != null ? retweeted.getId() : -1; retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1; retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; retweeted_by_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null; final Status quoted = orig.getQuotedStatus(); final User quote_user = quoted != null ? orig.getUser() : null; is_quote = orig.isQuote(); quote_id = quoted != null ? quoted.getId() : -1; quote_text_html = TwitterContentUtils.formatStatusText(orig); quote_text_plain = orig.getText(); quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html); quote_timestamp = orig.getCreatedAt().getTime(); quote_source = orig.getSource(); quoted_by_user_id = quote_user != null ? quote_user.getId() : -1; quoted_by_user_name = quote_user != null ? quote_user.getName() : null; quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null; quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null; quoted_by_user_is_protected = quote_user != null && quote_user.isProtected(); quoted_by_user_is_verified = quote_user != null && quote_user.isVerified(); final Status status; if (quoted != null) { status = quoted; } else if (retweeted != null) { status = retweeted; } else { status = orig; } final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageUrlHttps(); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = TwitterContentUtils.formatStatusText(status); media = ParcelableMedia.fromEntities(status); text_plain = status.getText(); retweet_count = status.getRetweetCount(); favorite_count = status.getFavoriteCount(); reply_count = status.getReplyCount(); descendent_reply_count = status.getDescendentReplyCount(); in_reply_to_name = TwitterContentUtils.getInReplyToName(status); in_reply_to_screen_name = status.getInReplyToScreenName(); in_reply_to_status_id = status.getInReplyToStatusId(); in_reply_to_user_id = status.getInReplyToUserId(); source = status.getSource(); location = ParcelableLocation.fromGeoLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = HtmlEscapeHelper.toPlainText(text_html); my_retweet_id = retweeted_by_id == account_id ? id : status.getCurrentUserRetweet(); is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id); place_full_name = getPlaceFullName(status.getPlace()); card_name = card != null ? card.name : null; }