diff options
author | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-02-14 00:48:30 -0500 |
---|---|---|
committer | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-02-14 00:48:30 -0500 |
commit | 50b648156c22e00e994976fb0d7a31428e36189e (patch) | |
tree | f48a8fe9586004786586db42784598f13d7d613d /app/notification.go | |
parent | 963150b6ec81b2fc4118ab4291aa4b93866e4475 (diff) | |
parent | 69e56fc04237ae5a821a9d97c48bc830111d6c78 (diff) | |
download | chat-50b648156c22e00e994976fb0d7a31428e36189e.tar.gz chat-50b648156c22e00e994976fb0d7a31428e36189e.tar.bz2 chat-50b648156c22e00e994976fb0d7a31428e36189e.zip |
Merge branch 'ICU-764' into release-4.7
Diffstat (limited to 'app/notification.go')
-rw-r--r-- | app/notification.go | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/app/notification.go b/app/notification.go index 1318308f8..e158e08d5 100644 --- a/app/notification.go +++ b/app/notification.go @@ -819,44 +819,52 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit ret.MentionedUserIds[id] = true } } + checkForMention := func(word string) bool { + isMention := false + 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 } - 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 } @@ -867,27 +875,10 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit }) for _, splitWord := range splitWords { - if splitWord == "@here" { - ret.HereMentioned = true + if checkForMention(splitWord) { + continue } - - 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) - } - - // 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) } |