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
Этот коммит содержится в:
Joram Wilander
2016-08-31 12:52:14 -04:00
коммит произвёл GitHub
родитель b0b39ce71c
Коммит 26f96b240d
8 изменённых файлов: 181 добавлений и 70 удалений

Просмотреть файл

@@ -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,