add notification when @user, @here, @all and @channel has colon ":" at the end (#8760)
Этот коммит содержится в:
коммит произвёл
Derrick Anderson
родитель
b4db76cedb
Коммит
4ce37601a1
@@ -919,12 +919,13 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
|
|||||||
|
|
||||||
// remove trailing '.', as that is the end of a sentence
|
// remove trailing '.', as that is the end of a sentence
|
||||||
foundWithSuffix := false
|
foundWithSuffix := false
|
||||||
|
for _, suffixPunctuation := range []string{".", ":"} {
|
||||||
for strings.HasSuffix(word, ".") {
|
for strings.HasSuffix(word, suffixPunctuation) {
|
||||||
word = strings.TrimSuffix(word, ".")
|
word = strings.TrimSuffix(word, suffixPunctuation)
|
||||||
if checkForMention(word) {
|
if checkForMention(word) {
|
||||||
foundWithSuffix = true
|
foundWithSuffix = true
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
OtherPotentialMentions: []string{"user"},
|
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": {
|
"MultiplePeopleWithOneWord": {
|
||||||
Message: "this is a message for @user",
|
Message: "this is a message for @user",
|
||||||
Keywords: map[string][]string{"@user": {id1, id2}},
|
Keywords: map[string][]string{"@user": {id1, id2}},
|
||||||
@@ -188,6 +198,18 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
ChannelMentioned: true,
|
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": {
|
"CapitalizedChannel": {
|
||||||
Message: "this is an message for @cHaNNeL",
|
Message: "this is an message for @cHaNNeL",
|
||||||
Keywords: map[string][]string{"@channel": {id1, id2}},
|
Keywords: map[string][]string{"@channel": {id1, id2}},
|
||||||
@@ -210,6 +232,17 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
AllMentioned: true,
|
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": {
|
"CapitalizedAll": {
|
||||||
Message: "this is an message for @ALL",
|
Message: "this is an message for @ALL",
|
||||||
Keywords: map[string][]string{"@all": {id1, id2}},
|
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": {
|
"AtUserWithPeriodAtEndOfSentence": {
|
||||||
Message: "this is a message for @user.period.",
|
Message: "this is a message for @user.period.",
|
||||||
Keywords: map[string][]string{"@user.period": {id1}},
|
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": {
|
"PotentialOutOfChannelUser": {
|
||||||
Message: "this is an message for @potential and @user",
|
Message: "this is an message for @potential and @user",
|
||||||
Keywords: map[string][]string{"@user": {id1}},
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
@@ -452,6 +503,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
|
|||||||
"\\@here\\": true,
|
"\\@here\\": true,
|
||||||
"|@here|": true,
|
"|@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:": false, // This case shouldn't trigger a mention since it follows the format of reactions e.g. :word:
|
||||||
"'@here'": true,
|
"'@here'": true,
|
||||||
"\"@here\"": true,
|
"\"@here\"": true,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user