From dc175cc7043ef6d4ab3e29ed3fe22603db480cb8 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 7 Jan 2019 13:05:47 -0300 Subject: [PATCH] Send clear push notification when DM has unread messages (#10065) * Send clear push notification when DM has unread messages * Feedback review --- app/channel.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/channel.go b/app/channel.go index 1772381484..61401ac2c3 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1600,6 +1600,13 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, clearPush channelsToClearPushNotifications := []string{} if *a.Config().EmailSettings.SendPushNotifications && clearPushNotifications { for _, channelId := range channelIds { + chanResult := <-a.Srv.Store.Channel().Get(channelId, true) + if chanResult.Err != nil { + mlog.Warn(fmt.Sprintf("Failed to get channel %v", chanResult.Err)) + continue + } + channel := chanResult.Data.(*model.Channel) + result := <-a.Srv.Store.Channel().GetMember(channelId, userId) if result.Err != nil { mlog.Warn(fmt.Sprintf("Failed to get membership %v", result.Err)) @@ -1618,9 +1625,10 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, clearPush channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId) } } - } else if notify == model.USER_NOTIFY_MENTION { + } else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT { if result := <-a.Srv.Store.User().GetUnreadCountForChannel(userId, channelId); result.Err == nil { - if result.Data.(int64) > 0 { + count := result.Data.(int64) + if count > 0 { channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId) } }