From cfd9d314a38acbedfb3f227aef756663f7f2e133 Mon Sep 17 00:00:00 2001 From: Dean Whillier Date: Fri, 21 Jun 2019 17:46:06 -0400 Subject: [PATCH] [MM 7970] Support maintaining online status while the Desktop App is in the background ... and other things. (#11312) * receive os-level user status updates via websocket * removing debugging --- wsapi/user.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wsapi/user.go b/wsapi/user.go index 509ca8a145..8c64cdb480 100644 --- a/wsapi/user.go +++ b/wsapi/user.go @@ -9,6 +9,7 @@ import ( func (api *API) InitUser() { api.Router.Handle("user_typing", api.ApiWebSocketHandler(api.userTyping)) + api.Router.Handle("user_update_active_status", api.ApiWebSocketHandler(api.userUpdateActiveStatus)) } func (api *API) userTyping(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) { @@ -33,3 +34,24 @@ func (api *API) userTyping(req *model.WebSocketRequest) (map[string]interface{}, return nil, nil } + +func (api *API) userUpdateActiveStatus(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) { + var ok bool + var userIsActive bool + if userIsActive, ok = req.Data["user_is_active"].(bool); !ok { + return nil, NewInvalidWebSocketParamError(req.Action, "user_is_active") + } + + var manual bool + if manual, ok = req.Data["manual"].(bool); !ok { + manual = false + } + + if userIsActive { + api.App.SetStatusOnline(req.Session.UserId, manual) + } else { + api.App.SetStatusAwayIfNeeded(req.Session.UserId, manual) + } + + return nil, nil +}