From 4ce37601a15a7af11d33465d1ae92de26f7fa498 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Sat, 12 May 2018 00:57:20 +0800 Subject: add notification when @user, @here, @all and @channel has colon ":" at the end (#8760) --- app/notification.go | 13 ++++++------ app/notification_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/notification.go b/app/notification.go index 7198de764..4bdc6c94f 100644 --- a/app/notification.go +++ b/app/notification.go @@ -919,12 +919,13 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit // remove trailing '.', as that is the end of a sentence foundWithSuffix := false - - for strings.HasSuffix(word, ".") { - word = strings.TrimSuffix(word, ".") - if checkForMention(word) { - foundWithSuffix = true - break + for _, suffixPunctuation := range []string{".", ":"} { + for strings.HasSuffix(word, suffixPunctuation) { + word = strings.TrimSuffix(word, suffixPunctuation) + if checkForMention(word) { + foundWithSuffix = true + break + } } } diff --git a/app/notification_test.go b/app/notification_test.go index 3b8b4adf5..818ad1d9d 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -148,6 +148,16 @@ func TestGetExplicitMentions(t *testing.T) { OtherPotentialMentions: []string{"user"}, }, }, + "OnePersonWithColonAtEnd": { + Message: "this is a message for @user:", + Keywords: map[string][]string{"this": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + OtherPotentialMentions: []string{"user"}, + }, + }, "MultiplePeopleWithOneWord": { Message: "this is a message for @user", Keywords: map[string][]string{"@user": {id1, id2}}, @@ -188,6 +198,18 @@ func TestGetExplicitMentions(t *testing.T) { ChannelMentioned: true, }, }, + + "ChannelWithColonAtEnd": { + Message: "this is a message for @channel:", + Keywords: map[string][]string{"@channel": {id1, id2}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + id2: true, + }, + ChannelMentioned: true, + }, + }, "CapitalizedChannel": { Message: "this is an message for @cHaNNeL", Keywords: map[string][]string{"@channel": {id1, id2}}, @@ -210,6 +232,17 @@ func TestGetExplicitMentions(t *testing.T) { AllMentioned: true, }, }, + "AllWithColonAtEnd": { + Message: "this is a message for @all:", + Keywords: map[string][]string{"@all": {id1, id2}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + id2: true, + }, + AllMentioned: true, + }, + }, "CapitalizedAll": { Message: "this is an message for @ALL", Keywords: map[string][]string{"@all": {id1, id2}}, @@ -230,6 +263,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "AtUserWithColonAtEnd": { + Message: "this is a message for @user:", + Keywords: map[string][]string{"@user": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "AtUserWithPeriodAtEndOfSentence": { Message: "this is a message for @user.period.", Keywords: map[string][]string{"@user.period": {id1}}, @@ -248,6 +290,15 @@ func TestGetExplicitMentions(t *testing.T) { }, }, }, + "UserWithColonAtEnd": { + Message: "this is a message for user:", + Keywords: map[string][]string{"user": {id1}}, + Expected: &ExplicitMentions{ + MentionedUserIds: map[string]bool{ + id1: true, + }, + }, + }, "PotentialOutOfChannelUser": { Message: "this is an message for @potential and @user", Keywords: map[string][]string{"@user": {id1}}, @@ -452,6 +503,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) { "\\@here\\": true, "|@here|": true, ";@here;": true, + "@here:": true, ":@here:": false, // This case shouldn't trigger a mention since it follows the format of reactions e.g. :word: "'@here'": true, "\"@here\"": true, -- cgit v1.2.3-1-g7c22