Skip to content

Commit

Permalink
Remove Context from User Name. fixes #239 @3h
Browse files Browse the repository at this point in the history
  • Loading branch information
みぞ@CrazyBeatCoder committed Nov 24, 2017
1 parent 3c5e61d commit eb7a557
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mizo0203.twitter.timeline.talker;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import twitter4j.StallWarning;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
Expand Down Expand Up @@ -31,6 +33,12 @@ public void start() {
mTwitterStream.user();
}

private static String getUserNameWithoutContext(String name) {
Pattern p = Pattern.compile("([^@@]+).+");
Matcher m = p.matcher(name);
return m.replaceFirst("$1");
}

private class OnStatusEvent implements StatusListener {

public void onStatus(final Status status) {
Expand All @@ -42,11 +50,11 @@ public void onStatus(final Status status) {

if (status.isRetweet()) {
Status retweetedStatus = status.getRetweetedStatus();
buffer.append(status.getUser().getName() + "さんがリツイート。");
buffer.append(retweetedStatus.getUser().getName() + "さんから、");
buffer.append(getUserNameWithoutContext(status.getUser().getName()) + "さんがリツイート。");
buffer.append(getUserNameWithoutContext(retweetedStatus.getUser().getName()) + "さんから、");
buffer.append(retweetedStatus.getText());
} else {
buffer.append(status.getUser().getName() + "さんから、");
buffer.append(getUserNameWithoutContext(status.getUser().getName()) + "さんから、");
buffer.append(status.getText());
}

Expand Down

0 comments on commit eb7a557

Please sign in to comment.