From 26f96b240ddc8cf8c56decea72102b10238e0a43 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 31 Aug 2016 12:52:14 -0400 Subject: PLT-3462 Add the ability to clear push notifications after channel is viewed (#3834) * Add the ability to clear push notifications after channel is viewed * Fix race condition between updating the mention count and reading it when sending push notifications --- api/channel.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'api/channel.go') diff --git a/api/channel.go b/api/channel.go index faa39e13c..e2c67f18b 100644 --- a/api/channel.go +++ b/api/channel.go @@ -846,8 +846,24 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["channel_id"] + doClearPush := false + if *utils.Cfg.EmailSettings.SendPushNotifications && !c.Session.IsMobileApp() { + if result := <-Srv.Store.User().GetUnreadCountForChannel(c.Session.UserId, id); result.Err != nil { + l4g.Error(utils.T("api.channel.update_last_viewed_at.get_unread_count_for_channel.error"), c.Session.UserId, id, result.Err.Error()) + } else { + if result.Data.(int64) > 0 { + doClearPush = true + } + } + } + Srv.Store.Channel().UpdateLastViewedAt(id, c.Session.UserId) + // Must be after update so that unread count is correct + if doClearPush { + go clearPushNotification(c.Session.UserId, id) + } + preference := model.Preference{ UserId: c.Session.UserId, Category: model.PREFERENCE_CATEGORY_LAST, -- cgit v1.2.3-1-g7c22