summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-08-31 12:52:14 -0400
committerGitHub <noreply@github.com>2016-08-31 12:52:14 -0400
commit26f96b240ddc8cf8c56decea72102b10238e0a43 (patch)
tree7eda509038de3d6b95a02b95bee2ad72e2e3a063 /api/channel.go
parentb0b39ce71cd77fbffbf23d56b20db1927f0c6cb1 (diff)
downloadchat-26f96b240ddc8cf8c56decea72102b10238e0a43.tar.gz
chat-26f96b240ddc8cf8c56decea72102b10238e0a43.tar.bz2
chat-26f96b240ddc8cf8c56decea72102b10238e0a43.zip
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
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go16
1 files changed, 16 insertions, 0 deletions
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,