summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/notification.go18
-rw-r--r--app/notification_test.go52
-rw-r--r--app/user_test.go2
3 files changed, 38 insertions, 34 deletions
diff --git a/app/notification.go b/app/notification.go
index c14701b5f..c48465003 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -665,8 +665,8 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri
message = removeCodeFromMessage(message)
for _, word := range strings.FieldsFunc(message, func(c rune) bool {
- // Split on whitespace (as strings.Fields normally does) or on Markdown characters
- return unicode.IsSpace(c) || c == '*' || c == '~'
+ // Split on any whitespace or punctuation that can't be part of an at mention
+ return !(c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
}) {
isMention := false
@@ -694,11 +694,14 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri
isMention = true
}
- if !isMention {
- // No matches were found with the string split just on whitespace so try further splitting
- // the message on punctuation
+ if isMention {
+ continue
+ }
+
+ if strings.ContainsAny(word, ".-") {
+ // This word contains a character that may be the end of a sentence, so split further
splitWords := strings.FieldsFunc(word, func(c rune) bool {
- return model.SplitRunes[c]
+ return c == '.' || c == '-'
})
for _, splitWord := range splitWords {
@@ -727,6 +730,9 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri
potentialOthersMentioned = append(potentialOthersMentioned, username)
}
}
+ } else if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") {
+ username := word[1:]
+ potentialOthersMentioned = append(potentialOthersMentioned, username)
}
}
diff --git a/app/notification_test.go b/app/notification_test.go
index 1d5c82405..e59ba35d8 100644
--- a/app/notification_test.go
+++ b/app/notification_test.go
@@ -168,40 +168,38 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
"here": false,
"@here": true,
" @here ": true,
- "\t@here\t": true,
"\n@here\n": true,
- // "!@here!": true,
- // "@@here@": true,
- // "#@here#": true,
- // "$@here$": true,
- // "%@here%": true,
- // "^@here^": true,
- // "&@here&": true,
- // "*@here*": true,
- "(@here(": true,
- ")@here)": true,
- // "-@here-": true,
- // "_@here_": true,
- // "=@here=": true,
+ "!@here!": true,
+ "#@here#": true,
+ "$@here$": true,
+ "%@here%": true,
+ "^@here^": true,
+ "&@here&": true,
+ "*@here*": true,
+ "(@here(": true,
+ ")@here)": true,
+ "-@here-": true,
+ "_@here_": false, // This case shouldn't mention since it would be mentioning "@here_"
+ "=@here=": true,
"+@here+": true,
"[@here[": true,
"{@here{": true,
"]@here]": true,
"}@here}": true,
"\\@here\\": true,
- // "|@here|": true,
- ";@here;": true,
- ":@here:": true,
- // "'@here'": true,
- // "\"@here\"": true,
- ",@here,": true,
- "<@here<": true,
- ".@here.": true,
- ">@here>": true,
- "/@here/": true,
- "?@here?": true,
- // "`@here`": true,
- // "~@here~": true,
+ "|@here|": true,
+ ";@here;": true,
+ ":@here:": true,
+ "'@here'": true,
+ "\"@here\"": true,
+ ",@here,": true,
+ "<@here<": true,
+ ".@here.": true,
+ ">@here>": true,
+ "/@here/": true,
+ "?@here?": true,
+ "`@here`": false, // This case shouldn't mention since it's a code block
+ "~@here~": true,
}
for message, shouldMention := range cases {
diff --git a/app/user_test.go b/app/user_test.go
index bc5d36ef5..76829caef 100644
--- a/app/user_test.go
+++ b/app/user_test.go
@@ -5,9 +5,9 @@ package app
import (
"bytes"
+ "encoding/json"
"image"
"image/color"
- "encoding/json"
"math/rand"
"strings"
"testing"