From 5a6d8387f5b8c7984104b8989c0b78112cc6a886 Mon Sep 17 00:00:00 2001 From: sowmiyamuthuraman <32141844+sowmiyamuthuraman@users.noreply.github.com> Date: Wed, 4 Nov 2020 14:43:24 +0530 Subject: [PATCH] MM-29379 Ignore channel mentions when channel is muted and channel mention setting is not updated by the user (#15992) --- app/notification.go | 3 ++- app/notification_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/notification.go b/app/notification.go index 929685588c..fd5441cda8 100644 --- a/app/notification.go +++ b/app/notification.go @@ -907,7 +907,8 @@ func addMentionKeywordsForUser(keywords map[string][]string, profile *model.User // Add @channel and @all to keywords if user has them turned on and the server allows them if allowChannelMentions { - ignoreChannelMentions := channelNotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] == model.IGNORE_CHANNEL_MENTIONS_ON + // Ignore channel mentions if channel is muted and channel mention setting is default + ignoreChannelMentions := channelNotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] == model.IGNORE_CHANNEL_MENTIONS_ON || (channelNotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.USER_NOTIFY_MENTION && channelNotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] == model.IGNORE_CHANNEL_MENTIONS_DEFAULT) if profile.NotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP] == "true" && !ignoreChannelMentions { keywords["@channel"] = append(keywords["@channel"], profile.Id) diff --git a/app/notification_test.go b/app/notification_test.go index 6b41bc7b2c..10a0893891 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1548,6 +1548,30 @@ func TestAddMentionKeywordsForUser(t *testing.T) { assert.NotContains(t, keywords["@here"], user.Id) }) + t.Run("should not add @channel/@all/@here when channel is muted and channel mention setting is not updated by user", func(t *testing.T) { + user := &model.User{ + Id: model.NewId(), + Username: "user", + NotifyProps: map[string]string{ + model.CHANNEL_MENTIONS_NOTIFY_PROP: "true", + }, + } + channelNotifyProps := map[string]string{ + model.MARK_UNREAD_NOTIFY_PROP: model.USER_NOTIFY_MENTION, + model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP: model.IGNORE_CHANNEL_MENTIONS_DEFAULT, + } + status := &model.Status{ + Status: model.STATUS_ONLINE, + } + + keywords := map[string][]string{} + addMentionKeywordsForUser(keywords, user, channelNotifyProps, status, true) + + assert.NotContains(t, keywords["@channel"], user.Id) + assert.NotContains(t, keywords["@all"], user.Id) + assert.NotContains(t, keywords["@here"], user.Id) + }) + t.Run("should not add @here when when user is not online", func(t *testing.T) { user := &model.User{ Id: model.NewId(),