summaryrefslogtreecommitdiffstats
path: root/app/notification.go
diff options
context:
space:
mode:
authorStephen Kiers <stephen@stephenkiers.com>2018-02-13 10:49:48 -0700
committerStephen Kiers <stephen@stephenkiers.com>2018-02-13 10:49:48 -0700
commit08c21f75199f959bbe63396be246e2b7d36a9a39 (patch)
treea70355eb41ae721b40d9822d99d78db976c7a9e6 /app/notification.go
parentbdf478c75bb41c00cdfd47bd7ae68c70a06886af (diff)
downloadchat-08c21f75199f959bbe63396be246e2b7d36a9a39.tar.gz
chat-08c21f75199f959bbe63396be246e2b7d36a9a39.tar.bz2
chat-08c21f75199f959bbe63396be246e2b7d36a9a39.zip
Added more tests and simplified code
Diffstat (limited to 'app/notification.go')
-rw-r--r--app/notification.go87
1 files changed, 39 insertions, 48 deletions
diff --git a/app/notification.go b/app/notification.go
index 6531f72f7..90303fb8f 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -820,46 +820,54 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
}
}
+ checkForMention := func(word string) bool {
+ isMention := false
+
+ fmt.Printf("New Word: %v\n", word)
+
+ if word == "@here" {
+ ret.HereMentioned = true
+ }
+
+ if word == "@channel" {
+ ret.ChannelMentioned = true
+ }
+
+ if word == "@all" {
+ ret.AllMentioned = true
+ }
+
+ // Non-case-sensitive check for regular keys
+ if ids, match := keywords[strings.ToLower(word)]; match {
+ addMentionedUsers(ids)
+ isMention = true
+ }
+
+ // Case-sensitive check for first name
+ if ids, match := keywords[word]; match {
+ addMentionedUsers(ids)
+ isMention = true
+ }
+
+ return isMention
+ }
processText := func(text string) {
for _, word := range strings.FieldsFunc(text, func(c rune) bool {
// Split on any whitespace or punctuation that can't be part of an at mention or emoji pattern
return !(c == ':' || c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
}) {
- isMention := false
-
// skip word with format ':word:' with an assumption that it is an emoji format only
if word[0] == ':' && word[len(word)-1] == ':' {
continue
}
- // remove trailing '.', as that is the end of a sentence
- word = strings.TrimSuffix(word, ".")
-
- if word == "@here" {
- ret.HereMentioned = true
- }
-
- if word == "@channel" {
- ret.ChannelMentioned = true
- }
-
- if word == "@all" {
- ret.AllMentioned = true
- }
-
- // Non-case-sensitive check for regular keys
- if ids, match := keywords[strings.ToLower(word)]; match {
- addMentionedUsers(ids)
- isMention = true
- }
-
- // Case-sensitive check for first name
- if ids, match := keywords[word]; match {
- addMentionedUsers(ids)
- isMention = true
+ if checkForMention(word) {
+ continue
}
- if isMention {
+ // remove trailing '.', as that is the end of a sentence
+ word = strings.TrimSuffix(word, ".")
+ if checkForMention(word) {
continue
}
@@ -870,27 +878,10 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
})
for _, splitWord := range splitWords {
- if splitWord == "@here" {
- ret.HereMentioned = true
- }
-
- if splitWord == "@all" {
- ret.AllMentioned = true
- }
-
- if splitWord == "@channel" {
- ret.ChannelMentioned = true
- }
-
- // Non-case-sensitive check for regular keys
- if ids, match := keywords[strings.ToLower(splitWord)]; match {
- addMentionedUsers(ids)
+ if checkForMention(splitWord) {
+ continue
}
-
- // Case-sensitive check for first name
- if ids, match := keywords[splitWord]; match {
- addMentionedUsers(ids)
- } else if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
+ if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
username := splitWord[1:]
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, username)
}