MM-20225: Fix notification badge count for All Activity (#13353)

When push notification setting was selected to "All Activity", we were
just sending the unread count for the channel from where the message was sent
and not for all channels.

After discussion with @enahum and @migbot, we decided to keep the badge count
to only refer to mentions and not unread posts.

Therefore, we only take the unread count for the user irrespective of the
notify_props settings.

Updated the tests to reflect that.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-01-01 13:46:51 +05:30
коммит произвёл GitHub
родитель abfd8fcc02
Коммит f75c8c7c9f
2 изменённых файлов: 20 добавлений и 28 удалений

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

@@ -453,11 +453,11 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po
msg = a.buildFullPushNotificationMessage(contentsConfig, post, user, channel, channelName, senderName, explicitMention, channelWideMention, replyToThreadType)
}
badge, err := a.getPushNotificationBadge(user, channel)
unreadCount, err := a.Srv.Store.User().GetUnreadCount(user.Id)
if err != nil {
return nil, err
}
msg.Badge = badge
msg.Badge = int(unreadCount)
return msg, nil
}
@@ -519,16 +519,3 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
return msg
}
func (a *App) getPushNotificationBadge(user *model.User, channel *model.Channel) (int, *model.AppError) {
var unreadCount int64
var err *model.AppError
if user.NotifyProps["push"] == "all" {
unreadCount, err = a.Srv.Store.User().GetAnyUnreadPostCountForChannel(user.Id, channel.Id)
} else {
unreadCount, err = a.Srv.Store.User().GetUnreadCount(user.Id)
}
return int(unreadCount), err
}

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

@@ -909,16 +909,21 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) {
receiver := th.CreateUser()
th.LinkUserToTeam(sender, team)
th.LinkUserToTeam(receiver, team)
channel := th.CreateChannel(team)
th.AddUserToChannel(sender, channel)
th.AddUserToChannel(receiver, channel)
channel1 := th.CreateChannel(team)
th.AddUserToChannel(sender, channel1)
th.AddUserToChannel(receiver, channel1)
channel2 := th.CreateChannel(team)
th.AddUserToChannel(sender, channel2)
th.AddUserToChannel(receiver, channel2)
// Create three mention posts and two non-mention posts
th.CreateMessagePost(channel, "@channel Hello")
th.CreateMessagePost(channel, "@all Hello")
th.CreateMessagePost(channel, fmt.Sprintf("@%s Hello", receiver.Username))
th.CreatePost(channel)
post := th.CreatePost(channel)
th.CreateMessagePost(channel1, "@channel Hello")
th.CreateMessagePost(channel1, "@all Hello")
th.CreateMessagePost(channel1, fmt.Sprintf("@%s Hello in channel 1", receiver.Username))
th.CreateMessagePost(channel2, fmt.Sprintf("@%s Hello in channel 2", receiver.Username))
th.CreatePost(channel1)
post := th.CreatePost(channel1)
for name, tc := range map[string]struct {
explicitMention bool
@@ -927,24 +932,24 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) {
pushNotifyProps string
expectedBadge int
}{
"only mentions included in badge count": {
"only mentions included for notify_props=mention": {
explicitMention: false,
channelWideMention: true,
replyToThreadType: "",
pushNotifyProps: "mention",
expectedBadge: 3,
expectedBadge: 4,
},
"mentions and non-mentions included in badge count": {
"only mentions included for notify_props=all": {
explicitMention: false,
channelWideMention: true,
replyToThreadType: "",
pushNotifyProps: "all",
expectedBadge: 5,
expectedBadge: 4,
},
} {
t.Run(name, func(t *testing.T) {
receiver.NotifyProps["push"] = tc.pushNotifyProps
msg, err := th.App.BuildPushNotificationMessage(model.FULL_NOTIFICATION, post, receiver, channel, channel.Name, sender.Username, tc.explicitMention, tc.channelWideMention, tc.replyToThreadType)
msg, err := th.App.BuildPushNotificationMessage(model.FULL_NOTIFICATION, post, receiver, channel1, channel1.Name, sender.Username, tc.explicitMention, tc.channelWideMention, tc.replyToThreadType)
require.Nil(t, err)
assert.Equal(t, tc.expectedBadge, msg.Badge)
})