From 9449d0e3023381eaddabbbf9f238adba341cfa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Thu, 24 Sep 2020 19:01:14 +0200 Subject: [PATCH] [MM-28447] Avoid "ghost mentions" when "First Name" is not set, but "First Name trigger mention" setting is set (#15577) * Do not add any keyword regarding first name if the first name is not set * Add test Co-authored-by: Mattermod --- app/notification.go | 2 +- app/notification_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/notification.go b/app/notification.go index e0bfab9b83..e45add5a5b 100644 --- a/app/notification.go +++ b/app/notification.go @@ -873,7 +873,7 @@ func addMentionKeywordsForUser(keywords map[string][]string, profile *model.User } // If turned on, add the user's case sensitive first name - if profile.NotifyProps[model.FIRST_NAME_NOTIFY_PROP] == "true" { + if profile.NotifyProps[model.FIRST_NAME_NOTIFY_PROP] == "true" && profile.FirstName != "" { keywords[profile.FirstName] = append(keywords[profile.FirstName], profile.Id) } diff --git a/app/notification_test.go b/app/notification_test.go index 67ed5845e0..6b41bc7b2c 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1424,6 +1424,24 @@ func TestAddMentionKeywordsForUser(t *testing.T) { assert.NotContains(t, keywords["Robert"], user.Id) }) + t.Run("should not add case sensitive first name if enabled but empty First Name", func(t *testing.T) { + user := &model.User{ + Id: model.NewId(), + Username: "user", + FirstName: "", + LastName: "Robert", + NotifyProps: map[string]string{ + model.FIRST_NAME_NOTIFY_PROP: "true", + }, + } + channelNotifyProps := map[string]string{} + + keywords := map[string][]string{} + addMentionKeywordsForUser(keywords, user, channelNotifyProps, nil, false) + + assert.NotContains(t, keywords[""], user.Id) + }) + t.Run("should not add case sensitive first name if disabled", func(t *testing.T) { user := &model.User{ Id: model.NewId(),