mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
fix out of channel mentions for mentioned word with valid punctuations (#8585)
This commit is contained in:
committed by
Derrick Anderson
parent
f7dd715052
commit
e16217166d
@@ -897,7 +897,9 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.ContainsAny(word, ".-:") {
|
||||
if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") {
|
||||
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, word[1:])
|
||||
} else if strings.ContainsAny(word, ".-:") {
|
||||
// This word contains a character that may be the end of a sentence, so split further
|
||||
splitWords := strings.FieldsFunc(word, func(c rune) bool {
|
||||
return c == '.' || c == '-' || c == ':'
|
||||
@@ -908,16 +910,10 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
|
||||
continue
|
||||
}
|
||||
if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
|
||||
username := splitWord[1:]
|
||||
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, username)
|
||||
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, splitWord[1:])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") {
|
||||
username := word[1:]
|
||||
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -234,6 +234,12 @@ func TestGetExplicitMentions(t *testing.T) {
|
||||
OtherPotentialMentions: []string{"potential"},
|
||||
},
|
||||
},
|
||||
"PotentialOutOfChannelUserWithPeriod": {
|
||||
Message: "this is an message for @potential.user",
|
||||
Expected: &ExplicitMentions{
|
||||
OtherPotentialMentions: []string{"potential.user"},
|
||||
},
|
||||
},
|
||||
"InlineCode": {
|
||||
Message: "`this shouldn't mention @channel at all`",
|
||||
Keywords: map[string][]string{},
|
||||
|
||||
Reference in New Issue
Block a user