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 +}