MM-23211: Fix user not being notified in out of channel mentions (#14097)

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2020-03-25 02:13:25 +05:30
коммит произвёл GitHub
родитель 6c6a64c103
Коммит 32b7f477bf
2 изменённых файлов: 73 добавлений и 55 удалений

Просмотреть файл

@@ -829,6 +829,13 @@ func (m *ExplicitMentions) processText(text string, keywords map[string][]string
} }
if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") { if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") {
// No need to bother about unicode as we are looking for ASCII characters.
last := word[len(word)-1]
switch last {
// If the word is possibly at the end of a sentence, remove that character.
case '.', '-', ':':
word = word[:len(word)-1]
}
m.OtherPotentialMentions = append(m.OtherPotentialMentions, word[1:]) m.OtherPotentialMentions = append(m.OtherPotentialMentions, word[1:])
} else if strings.ContainsAny(word, ".-:") { } else if strings.ContainsAny(word, ".-:") {
// This word contains a character that may be the end of a sentence, so split further // This word contains a character that may be the end of a sentence, so split further

Просмотреть файл

@@ -816,6 +816,7 @@ func TestGetExplicitMentions(t *testing.T) {
} }
func TestGetExplicitMentionsAtHere(t *testing.T) { func TestGetExplicitMentionsAtHere(t *testing.T) {
t.Run("Boundary cases", func(t *testing.T) {
// test all the boundary cases that we know can break up terms (and those that we know won't) // test all the boundary cases that we know can break up terms (and those that we know won't)
cases := map[string]bool{ cases := map[string]bool{
"": false, "": false,
@@ -858,21 +859,31 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
"@HERE": true, "@HERE": true,
"@hERe": true, "@hERe": true,
} }
for message, shouldMention := range cases { for message, shouldMention := range cases {
post := &model.Post{Message: message} post := &model.Post{Message: message}
m := getExplicitMentions(post, nil) m := getExplicitMentions(post, nil)
require.False(t, m.HereMentioned && !shouldMention, "shouldn't have mentioned @here with \"%v\"") require.False(t, m.HereMentioned && !shouldMention, "shouldn't have mentioned @here with \"%v\"")
require.False(t, !m.HereMentioned && shouldMention, "should've mentioned @here with \"%v\"") require.False(t, !m.HereMentioned && shouldMention, "should've mentioned @here with \"%v\"")
} }
})
// mentioning @here and someone t.Run("Mention @here and someone", func(t *testing.T) {
id := model.NewId() id := model.NewId()
m := getExplicitMentions(&model.Post{Message: "@here @user @potential"}, map[string][]string{"@user": {id}}) m := getExplicitMentions(&model.Post{Message: "@here @user @potential"}, map[string][]string{"@user": {id}})
require.True(t, m.HereMentioned, "should've mentioned @here with \"@here @user\"") require.True(t, m.HereMentioned, "should've mentioned @here with \"@here @user\"")
require.Len(t, m.Mentions, 1) require.Len(t, m.Mentions, 1)
require.Equal(t, KeywordMention, m.Mentions[id], "should've mentioned @user with \"@here @user\"") require.Equal(t, KeywordMention, m.Mentions[id], "should've mentioned @user with \"@here @user\"")
require.LessOrEqual(t, len(m.OtherPotentialMentions), 1, "should've potential mentions for @potential") require.Equal(t, len(m.OtherPotentialMentions), 1, "should've potential mentions for @potential")
assert.Equal(t, "potential", m.OtherPotentialMentions[0])
})
t.Run("Username ending with period", func(t *testing.T) {
id := model.NewId()
m := getExplicitMentions(&model.Post{Message: "@potential. test"}, map[string][]string{"@user": {id}})
require.Equal(t, len(m.OtherPotentialMentions), 1, "should've potential mentions for @potential")
assert.Equal(t, "potential", m.OtherPotentialMentions[0])
})
} }
func TestAllowChannelMentions(t *testing.T) { func TestAllowChannelMentions(t *testing.T) {