private Record extractRecord(String idPrefix, Schema avroSchema, Status status) { User user = status.getUser(); Record doc = new Record(avroSchema); doc.put("id", idPrefix + status.getId()); doc.put("created_at", formatterTo.format(status.getCreatedAt())); doc.put("retweet_count", status.getRetweetCount()); doc.put("retweeted", status.isRetweet()); doc.put("in_reply_to_user_id", status.getInReplyToUserId()); doc.put("in_reply_to_status_id", status.getInReplyToStatusId()); addString(doc, "source", status.getSource()); addString(doc, "text", status.getText()); MediaEntity[] mediaEntities = status.getMediaEntities(); if (mediaEntities.length > 0) { addString(doc, "media_url_https", mediaEntities[0].getMediaURLHttps()); addString(doc, "expanded_url", mediaEntities[0].getExpandedURL()); } doc.put("user_friends_count", user.getFriendsCount()); doc.put("user_statuses_count", user.getStatusesCount()); doc.put("user_followers_count", user.getFollowersCount()); addString(doc, "user_location", user.getLocation()); addString(doc, "user_description", user.getDescription()); addString(doc, "user_screen_name", user.getScreenName()); addString(doc, "user_name", user.getName()); return doc; }
@Override public void onStatus(Status status) { HashtagEntity[] hashtagEntities = status.getHashtagEntities(); JetstreamEvent event = new JetstreamEvent(); event.setEventType("TwitterSample"); Place place = status.getPlace(); if (place != null) { event.put("country", place.getCountry()); } event.put("ct", status.getCreatedAt().getTime()); event.put("text", status.getText()); event.put("lang", status.getLang()); event.put("user", status.getUser().getName()); if (hashtagEntities != null && hashtagEntities.length > 0) { StringBuilder s = new StringBuilder(); s.append(hashtagEntities[0].getText()); for (int i = 1; i < hashtagEntities.length; i++) { s.append(","); s.append(hashtagEntities[i].getText()); } event.put("hashtag", s.toString()); } fireSendEvent(event); }
public TwitterPrincipal(User user) { name = user.getName(); }
public DirectMessage sendDirectMessage(String text) throws TwitterException { return twitter.sendDirectMessage(this.getName(), text); }
public static Notification fromFollow(final User follower) { final String title = follower.getName() + " started following you!"; return new Notification(title, ""); }
public static Notification fromUnfollow(final User unfollower) { final String title = unfollower.getName() + " unfollowed you :("; return new Notification(title, "unlucky... :("); }
@Override public void onStatus(Status status) { String s = "{\"a\" : [{\"user\": \"" + status.getUser().getName() + "\", \"text\":\"" + status.getText() + "\"}]}"; // TODO uncomment again // // try { // System.out.println(s); // parser.parse(IOUtils.toInputStream(s, "UTF-8"), stp); // } catch (IOException e) { // e.printStackTrace(); // } System.out.println("============================"); System.out.println(status.getUser().getName() + " : " + status.getText()); System.out.println(TwitterObjectFactory.getRawJSON(status)); System.out.println("============================"); }
public static Notification fromFavorite(final User favoriter, final Status tweet) { final String title = favoriter.getName() + " liked one of your tweets:"; return new Notification(title, tweet.getText()); }
@Override public void onStatus(Status status) { String s = "{\"a\" : [{\"user\": \"" + status.getUser().getName() + "\", \"text\":\"" + status.getText() + "\"}]}"; // TODO uncomment again // // try { // System.out.println(s); // parser.parse(IOUtils.toInputStream(s, "UTF-8"), stp); // } catch (IOException e) { // e.printStackTrace(); // } System.out.println("============================"); System.out.println(status.getUser().getName() + " : " + status.getText()); System.out.println(TwitterObjectFactory.getRawJSON(status)); System.out.println("============================"); }
@Override public Optional<User> getUserFromAccessToken(String accessToken) throws UserValidationException { String token = accessToken.substring(0, accessToken.indexOf("_")); String tokenSecret = accessToken.substring(accessToken.indexOf("_") + 1, accessToken.length()); if (users.get(token) != null) { return Optional.of(users.get(token)); } else { twitter.setOAuthAccessToken(new AccessToken(token, tokenSecret)); twitter4j.User userTwitter; try { userTwitter = twitter.showUser(Long.valueOf(twitter.getId())); } catch (TwitterException e) { return Optional.empty(); } User user = User.create(userTwitter.getName(), userTwitter.getId() + "", userTwitter.getId() + ""); users.put(token, user); return Optional.of(user); } }
public static Notification fromMention(final Status mention) { final String title = mention.getUser().getName() + " mentioned you"; return new Notification(title, mention.getText()); }
public static Notification fromRetweet(final Status retweetingStatus) { final String title = retweetingStatus.getUser().getName() + " retweeted you"; return new Notification(title, retweetingStatus.getRetweetedStatus().getText()); }
@Override public void onStatus(Status status) { String text = status.getText(); text = text.replace("<", "<"); Matcher matcher = URL_PATTERN.matcher(text); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String unshortenedURL = unshorten(matcher.group(), 1); if (unshortenedURL != null) { matcher.appendReplacement(sb, "<a target=\"_blank\" href=\"" + unshortenedURL + "\">" + unshortenedURL + "</a>"); } else { matcher.appendReplacement(sb, "$0"); } } matcher.appendTail(sb); Tweet tweet = new Tweet(); tweet.setCreatedAt(status.getCreatedAt().getTime()); tweet.setFromUser(status.getUser().getName()); tweet.setId(status.getId()); tweet.setProfileImageUrl(status.getUser().getProfileImageURL().toString()); tweet.setText(sb.toString()); this.lastTweets.offer(tweet); this.messagingTemplate.convertAndSend("/queue/tweets", Collections.singletonList(tweet)); }
private void createTabForPal(final User user) { if (loadedPals.contains(user)) return; LOG.debug("Creating a conversation tab for conversation with {}", user.getScreenName()); easyFxml.loadNode(DIRECT_MESSAGE_CONVERSATION, Pane.class, DMConversationController.class) .afterControllerLoaded(dmc -> dmc.setPal(user)) .getNode() .recover(ExceptionHandler::fromThrowable) .map(conversation -> new Tab(user.getName(), conversation)) .onSuccess(tab -> Platform.runLater(() -> { LOG.debug("Adding [{}] as tab for user {}", tab.getText(), user.getScreenName()); this.conversationsManaged.add(tab); })); loadedPals.add(user); }
public static Notification fromQuotedTweet(final Status quotingStatus) { final String title = quotingStatus.getUser().getName() + " quoted you"; return new Notification( title, quotingStatus.getText() + "\n\n Quoted:\n" + quotingStatus.getQuotedStatus().getText() ); }
/** * Opens the detailed view of a given user. * * @param targetUser the user whose detailed view is requested to be shown */ public void openUserDetails(final User targetUser) { LOG.info("Opening detailed view of user : {} (@{})", targetUser.getName(), targetUser.getScreenName()); easyFxml.loadNode(Screen.USER_VIEW, Pane.class, UserViewController.class) .afterControllerLoaded(uvc -> uvc.targetUserProperty().setValue(targetUser)) .getNode() .recover(ExceptionHandler::fromThrowable) .onSuccess(userDetailsPane -> { final String stageTitle = targetUser.getName() + " (@" + targetUser.getScreenName() + ")"; Stages.stageOf(stageTitle, userDetailsPane).thenAcceptAsync(Stages::scheduleDisplaying); }); }
/** * Handles retweets so as to add retweet info at the top and then display the actual underlying status. */ private void handleRetweet(final Status status) { retweeterLabel.setText(status.getUser().getName()); retweeterIdLabel.setText("@" + status.getUser().getScreenName()); setStatusDisplay(status.getRetweetedStatus()); }
public void sendTweet(final Status status, final User user) { final Message m = new Message.Builder().setMessageText(status.getText()).setTitle(status.getText().substring(0, 50)).setDateReceived(status.getCreatedAt()).setOrigin(status.getUser().getName()).build(); m.setTransientMessage(true); m.setImage(getImage(user)); triggerEvent(new GuiEvent() { @Override public GuiEventKey getKey() { return MessageEventKey.MESSAGE_NEW; } @Override public Object getContent() { return m; } }); } }
/** * @param statusToDisplay The status to fill user readable information from. */ private void setStatusDisplay(final Status statusToDisplay) { author.setText(statusToDisplay.getUser().getName()); authorId.setText("@" + statusToDisplay.getUser().getScreenName()); time.setText(PRETTY_TIME.format(statusToDisplay.getCreatedAt())); loadTextIntoTextFlow(statusToDisplay); final String ppUrl = statusToDisplay.getUser().getOriginalProfileImageURLHttps(); asyncIO.loadImageMiniature(ppUrl, 96.0, 96.0) .thenAcceptAsync(authorProfilePicture::setImage, Platform::runLater); authorProfilePicture.setOnMouseClicked(e -> userDetailsService.openUserDetails(statusToDisplay.getUser())); readMedias(currentStatus.getValue()); }
private Record extractRecord(String idPrefix, Schema avroSchema, Status status) { User user = status.getUser(); Record doc = new Record(avroSchema); doc.put("id", idPrefix + status.getId()); doc.put("created_at", formatterTo.format(status.getCreatedAt())); doc.put("retweet_count", status.getRetweetCount()); doc.put("retweeted", status.isRetweet()); doc.put("in_reply_to_user_id", status.getInReplyToUserId()); doc.put("in_reply_to_status_id", status.getInReplyToStatusId()); addString(doc, "source", status.getSource()); addString(doc, "text", status.getText()); MediaEntity[] mediaEntities = status.getMediaEntities(); if (mediaEntities.length > 0) { addString(doc, "media_url_https", mediaEntities[0].getMediaURLHttps()); addString(doc, "expanded_url", mediaEntities[0].getExpandedURL()); } doc.put("user_friends_count", user.getFriendsCount()); doc.put("user_statuses_count", user.getStatusesCount()); doc.put("user_followers_count", user.getFollowersCount()); addString(doc, "user_location", user.getLocation()); addString(doc, "user_description", user.getDescription()); addString(doc, "user_screen_name", user.getScreenName()); addString(doc, "user_name", user.getName()); return doc; }