aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-common/src/main/java')
-rw-r--r--juick-common/src/main/java/com/juick/util/MessageUtils.java19
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("&", "&amp;");
msg = msg.replaceAll("<", "&lt;");
@@ -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());
+ }
}