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(),