diff --git a/app/notification.go b/app/notification.go index 1d4a2ccb49..46d7a0db3c 100644 --- a/app/notification.go +++ b/app/notification.go @@ -593,7 +593,9 @@ func (a *App) getMentionKeywordsInChannel(profiles map[string]*model.User, lookF for _, k := range splitKeys { // note that these are made lower case so that we can do a case insensitive check for them key := strings.ToLower(k) - keywords[key] = append(keywords[key], id) + if key != "" { + keywords[key] = append(keywords[key], id) + } } } diff --git a/app/notification_test.go b/app/notification_test.go index 744b9738d4..751e14acbc 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1150,6 +1150,29 @@ func TestGetMentionKeywords(t *testing.T) { } else if _, ok := mentions["@here"]; ok { t.Fatal("should not have mentioned any user with @here") } + + // user with empty mention keys + userNoMentionKeys := &model.User{ + Id: model.NewId(), + FirstName: "First", + Username: "User", + NotifyProps: map[string]string{ + "mention_keys": ",", + }, + } + + channelMemberNotifyPropsMapEmptyOff := map[string]model.StringMap{ + userNoMentionKeys.Id: { + "ignore_channel_mentions": model.IGNORE_CHANNEL_MENTIONS_OFF, + }, + } + + profiles = map[string]*model.User{userNoMentionKeys.Id: userNoMentionKeys} + mentions = th.App.getMentionKeywordsInChannel(profiles, true, channelMemberNotifyPropsMapEmptyOff) + assert.Equal(t, 1, len(mentions), "should've returned one metion keyword") + ids, ok := mentions["@user"] + assert.True(t, ok) + assert.Equal(t, userNoMentionKeys.Id, ids[0], "should've returned mention key of @user") } func TestGetMentionsEnabledFields(t *testing.T) {