diff options
author | Corey Hulen <corey@hulen.com> | 2017-09-12 17:49:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-12 17:49:42 -0700 |
commit | 3e9bd30b00901f0f184119deef2ae6ab41957daa (patch) | |
tree | 5fd64a9635d115f78ac0f90ce472711eef79abd9 /app/notification.go | |
parent | 4731b8f9b993536ed61dbc065e161e8994253f0d (diff) | |
download | chat-3e9bd30b00901f0f184119deef2ae6ab41957daa.tar.gz chat-3e9bd30b00901f0f184119deef2ae6ab41957daa.tar.bz2 chat-3e9bd30b00901f0f184119deef2ae6ab41957daa.zip |
PLT-7502 fixing clearing of push notifications for iOS (#7429)
* PLT-7502 fixing clearing of push notificaitons for iOS
* PLT-7502 fixing clearing of push notificaitons for iOS
Diffstat (limited to 'app/notification.go')
-rw-r--r-- | app/notification.go | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/app/notification.go b/app/notification.go index 255e8c399..b0a6a02e2 100644 --- a/app/notification.go +++ b/app/notification.go @@ -649,32 +649,39 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel * return nil } -func (a *App) ClearPushNotification(userId string, channelId string) *model.AppError { - sessions, err := a.getMobileAppSessions(userId) - if err != nil { - return err - } - - msg := model.PushNotification{} - msg.Type = model.PUSH_TYPE_CLEAR - msg.ChannelId = channelId - msg.ContentAvailable = 0 - if badge := <-a.Srv.Store.User().GetUnreadCount(userId); badge.Err != nil { - msg.Badge = 0 - l4g.Error(utils.T("store.sql_user.get_unread_count.app_error"), userId, badge.Err) - } else { - msg.Badge = int(badge.Data.(int64)) - } - - l4g.Debug(utils.T("api.post.send_notifications_and_forget.clear_push_notification.debug"), msg.DeviceId, msg.ChannelId) +func (a *App) ClearPushNotification(userId string, channelId string) { + go func() { + // Sleep is to allow the read replicas a chance to fully sync + // the unread count for sending an accurate count. + // Delaying a little doesn't hurt anything and is cheaper than + // attempting to read from master. + time.Sleep(time.Second * 5) + + sessions, err := a.getMobileAppSessions(userId) + if err != nil { + l4g.Error(err.Error()) + return + } + + msg := model.PushNotification{} + msg.Type = model.PUSH_TYPE_CLEAR + msg.ChannelId = channelId + msg.ContentAvailable = 0 + if badge := <-a.Srv.Store.User().GetUnreadCount(userId); badge.Err != nil { + msg.Badge = 0 + l4g.Error(utils.T("store.sql_user.get_unread_count.app_error"), userId, badge.Err) + } else { + msg.Badge = int(badge.Data.(int64)) + } - for _, session := range sessions { - tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson())) - tmpMessage.SetDeviceIdAndPlatform(session.DeviceId) - go a.sendToPushProxy(tmpMessage, session) - } + l4g.Debug(utils.T("api.post.send_notifications_and_forget.clear_push_notification.debug"), msg.DeviceId, msg.ChannelId) - return nil + for _, session := range sessions { + tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson())) + tmpMessage.SetDeviceIdAndPlatform(session.DeviceId) + go a.sendToPushProxy(tmpMessage, session) + } + }() } func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session) { |