aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
committerlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
commit3c400703e082a1b180b35d891b8fb3460c7d5b87 (patch)
tree28738dd90fc41b4ab71897f38d324828778ad2e3 /src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
parent72114d732427266024cdd6e27cd8d1aa60afae2f (diff)
parentf28d77dc42f6bac5a026e0b1c78562dee8de45ac (diff)
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
index c04ebdb8..7afc3fa4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
@@ -3,6 +3,8 @@ package de.thedevstack.conversationsplus.utils;
import android.graphics.BitmapFactory;
import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.entities.Message;
@@ -12,6 +14,26 @@ import de.thedevstack.conversationsplus.persistance.FileBackend;
* Created by tzur on 15.12.2015.
*/
public final class MessageUtil {
+ public static boolean wasHighlightedOrPrivate(final Message message) {
+ final String nick = message.getConversation().getMucOptions().getActualNick();
+ final Pattern highlight = generateNickHighlightPattern(nick);
+ if (message.getBody() == null || nick == null) {
+ return false;
+ }
+ final Matcher m = highlight.matcher(message.getBody());
+ return (m.find() || message.getType() == Message.TYPE_PRIVATE);
+ }
+
+ private static Pattern generateNickHighlightPattern(final String nick) {
+ // We expect a word boundary, i.e. space or start of string, followed by
+ // the
+ // nick (matched in case-insensitive manner), followed by optional
+ // punctuation (for example "bob: i disagree" or "how are you alice?"),
+ // followed by another word boundary.
+ return Pattern.compile("\\b" + Pattern.quote(nick) + "\\p{Punct}?\\b",
+ Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
+ }
+
public static void updateMessageWithImageDetails(Message message, String filePath, long size, int imageWidth, int imageHeight) {
message.setRelativeFilePath(filePath);
MessageUtil.updateMessageBodyWithImageParams(message, size, imageWidth, imageHeight);