Send clear push notification when DM has unread messages (#10065)

* Send clear push notification when DM has unread messages

* Feedback review
This commit is contained in:
Elias Nahum
2019-01-07 13:05:47 -03:00
committed by GitHub
parent 2c0cf1947a
commit dc175cc704

View File

@@ -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)
}
}