diff options
author | Vitaly Takmazov | 2018-11-03 13:14:15 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-03 13:14:15 +0300 |
commit | 2a64e080a395170875d62d3bebaf4dce3815bb13 (patch) | |
tree | e9c34caf2a694899ea67ab13d6bb2e0c20bee20d /juick-common/src/main/java | |
parent | 5cf3c20ed4463c6f35d51fc4e10366fe2b850f29 (diff) |
ActivityPub: mentions with @user@server.tld
Diffstat (limited to 'juick-common/src/main/java')
-rw-r--r-- | juick-common/src/main/java/com/juick/util/MessageUtils.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/juick-common/src/main/java/com/juick/util/MessageUtils.java b/juick-common/src/main/java/com/juick/util/MessageUtils.java index 62616bdf..fd357c32 100644 --- a/juick-common/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-common/src/main/java/com/juick/util/MessageUtils.java @@ -71,6 +71,9 @@ public class MessageUtils { private final static String usernameRegex = "((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))"; private final static Pattern usernamePattern = Pattern.compile(usernameRegex); + private final static String jidRegex = "((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))"; + private final static Pattern jidPattern = Pattern.compile(jidRegex); + public static String formatMessageCode(String msg) { msg = msg.replaceAll("&", "&"); msg = msg.replaceAll("<", "<"); @@ -138,7 +141,7 @@ public class MessageUtils { // @username@jabber.org // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"https://juick.com/$2/\">@$2</a>$3"); + msg = msg.replaceAll(jidRegex, "$1<a href=\"https://juick.com/$2/\">@$2</a>$3"); // @username // <a href="http://juick.com/username/">@username</a> @@ -304,12 +307,18 @@ public class MessageUtils { } return input; } - public static List<String> getMentions(Message msg) { - Matcher usernameMatcher = usernamePattern.matcher(msg.getText()); + private static List<String> collectMatches(Pattern pattern, String input) { + Matcher matcher = pattern.matcher(input); List<String> result = new ArrayList<>(); - while (usernameMatcher.find()) { - result.add(usernameMatcher.group()); + while (matcher.find()) { + result.add(matcher.group()); } return result; } + public static List<String> getMentions(Message msg) { + return collectMatches(usernamePattern, msg.getText()); + } + public static List<String> getGlobalMentions(Message msg) { + return collectMatches(jidPattern, msg.getText()); + } } |