From f32eb525f3fa0828a23f589d765c267e3b2aea86 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 2 Sep 2016 12:50:15 -0400 Subject: Do not send push notifications for channels being actively viewed (#3931) --- api/channel.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'api/channel.go') diff --git a/api/channel.go b/api/channel.go index e2c67f18b..c477a5ee4 100644 --- a/api/channel.go +++ b/api/channel.go @@ -846,8 +846,16 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["channel_id"] + data := model.StringInterfaceFromJson(r.Body) + + var active bool + var ok bool + if active, ok = data["active"].(bool); !ok { + active = true + } + doClearPush := false - if *utils.Cfg.EmailSettings.SendPushNotifications && !c.Session.IsMobileApp() { + if *utils.Cfg.EmailSettings.SendPushNotifications && !c.Session.IsMobileApp() && active { 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 { @@ -857,6 +865,12 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) { } } + go func() { + if err := SetActiveChannel(c.Session.UserId, id); err != nil { + l4g.Error(err.Error()) + } + }() + Srv.Store.Channel().UpdateLastViewedAt(id, c.Session.UserId) // Must be after update so that unread count is correct -- cgit v1.2.3-1-g7c22