From 1621fb481fe91b084a48326419969f3a22ccbbe2 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sat, 29 Sep 2018 16:39:37 +0300
Subject: Mentions
---
juick-common/src/main/java/com/juick/util/MessageUtils.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
(limited to 'juick-common/src/main/java/com/juick/util')
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 bac24507..4de68cb9 100644
--- a/juick-common/src/main/java/com/juick/util/MessageUtils.java
+++ b/juick-common/src/main/java/com/juick/util/MessageUtils.java
@@ -68,6 +68,9 @@ public class MessageUtils {
private final static String replyNumberRegex = "((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
+ private final static String usernameRegex = "((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
+ private final static Pattern usernamePattern = Pattern.compile(usernameRegex);
+
public static String formatMessageCode(String msg) {
msg = msg.replaceAll("&", "&");
msg = msg.replaceAll("<", "<");
@@ -139,7 +142,7 @@ public class MessageUtils {
// @username
// @username
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1@$2$3");
+ msg = msg.replaceAll(usernameRegex, "$1@$2$3");
// (http://juick.com/last?page=2)
// (juick.com)
@@ -301,4 +304,12 @@ public class MessageUtils {
}
return input;
}
+ public static List getMentions(Message msg) {
+ Matcher usernameMatcher = usernamePattern.matcher(msg.getText());
+ List result = new ArrayList<>();
+ while (usernameMatcher.find()) {
+ result.add(usernameMatcher.group());
+ }
+ return result;
+ }
}
--
cgit v1.2.3