diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-09-28 16:33:25 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-09-28 16:33:25 +0200 |
commit | 87010e6094cc35ece98d3beadbbfbc59ea0a25b3 (patch) | |
tree | 08aaa1cbc7a3acab4246e5f516ff8125d99760fd /src/eu/siacs/conversations/services | |
parent | bff23c2e232e8f9a4e64553215130079b7fc5a4f (diff) |
more improvments for new notification service
Diffstat (limited to 'src/eu/siacs/conversations/services')
-rw-r--r-- | src/eu/siacs/conversations/services/NotificationService.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index b004d1c5..656e16f3 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -2,6 +2,9 @@ package eu.siacs.conversations.services; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import android.app.Notification; import android.app.NotificationManager; @@ -162,4 +165,22 @@ public class NotificationService { PendingIntent.FLAG_UPDATE_CURRENT); return resultPendingIntent; } + + public static boolean wasHighlightedOrPrivate(Message message) { + String nick = message.getConversation().getMucOptions().getActualNick(); + Pattern highlight = generateNickHighlightPattern(nick); + Matcher m = highlight.matcher(message.getBody()); + return (m.find() || message.getType() == Message.TYPE_PRIVATE); + } + + private static Pattern generateNickHighlightPattern(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" + nick + "\\p{Punct}?\\b", + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + } |