From 62b3569025347a1291229771f363be5962951f25 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Wed, 25 Oct 2017 17:51:13 +0200 Subject: [PLT-4341] add dnd command (#7694) --- app/status.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'app/status.go') diff --git a/app/status.go b/app/status.go index 56bad2105..e5926a071 100644 --- a/app/status.go +++ b/app/status.go @@ -295,6 +295,34 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) { }) } +func (a *App) SetStatusDoNotDisturb(userId string) { + if !*a.Config().ServiceSettings.EnableUserStatuses { + return + } + + status, err := a.GetStatus(userId) + + if err != nil { + status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""} + } + + status.Status = model.STATUS_DND + status.Manual = true + + a.AddStatusCache(status) + + if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil { + l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) + } + + event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil) + event.Add("status", model.STATUS_DND) + event.Add("user_id", status.UserId) + a.Go(func() { + a.Publish(event) + }) +} + func GetStatusFromCache(userId string) *model.Status { if result, ok := statusCache.Get(userId); ok { status := result.(*model.Status) -- cgit v1.2.3-1-g7c22