MM-10597 Improved handling of punctuation around notifications (#8901)
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
5e36cbae09
Коммит
bca7339e4c
@@ -1004,23 +1004,24 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
word = strings.TrimLeft(word, ":.-_")
|
||||||
|
|
||||||
if checkForMention(word) {
|
if checkForMention(word) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove trailing '.', as that is the end of a sentence
|
foundWithoutSuffix := false
|
||||||
foundWithSuffix := false
|
wordWithoutSuffix := word
|
||||||
for _, suffixPunctuation := range []string{".", ":"} {
|
for strings.LastIndexAny(wordWithoutSuffix, ".-:_") != -1 {
|
||||||
for strings.HasSuffix(word, suffixPunctuation) {
|
wordWithoutSuffix = wordWithoutSuffix[0 : len(wordWithoutSuffix)-1]
|
||||||
word = strings.TrimSuffix(word, suffixPunctuation)
|
|
||||||
if checkForMention(word) {
|
if checkForMention(wordWithoutSuffix) {
|
||||||
foundWithSuffix = true
|
foundWithoutSuffix = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if foundWithSuffix {
|
if foundWithoutSuffix {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,14 +148,58 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
OtherPotentialMentions: []string{"user"},
|
OtherPotentialMentions: []string{"user"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"OnePersonWithColonAtEnd": {
|
"OnePersonWithPeriodAfter": {
|
||||||
Message: "this is a message for @user:",
|
Message: "this is a message for @user.",
|
||||||
Keywords: map[string][]string{"this": {id1}},
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"OnePersonWithPeriodBefore": {
|
||||||
|
Message: "this is a message for .@user",
|
||||||
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"OnePersonWithColonAfter": {
|
||||||
|
Message: "this is a message for @user:",
|
||||||
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"OnePersonWithColonBefore": {
|
||||||
|
Message: "this is a message for :@user",
|
||||||
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"OnePersonWithHyphenAfter": {
|
||||||
|
Message: "this is a message for @user.",
|
||||||
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"OnePersonWithHyphenBefore": {
|
||||||
|
Message: "this is a message for -@user",
|
||||||
|
Keywords: map[string][]string{"@user": {id1}},
|
||||||
Expected: &ExplicitMentions{
|
Expected: &ExplicitMentions{
|
||||||
MentionedUserIds: map[string]bool{
|
MentionedUserIds: map[string]bool{
|
||||||
id1: true,
|
id1: true,
|
||||||
},
|
},
|
||||||
OtherPotentialMentions: []string{"user"},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"MultiplePeopleWithOneWord": {
|
"MultiplePeopleWithOneWord": {
|
||||||
@@ -493,7 +537,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
|
|||||||
"(@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,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user