From 7826774a14ebf9a3bab11069a8f2ff8947fe931a Mon Sep 17 00:00:00 2001 From: Stan Chan Date: Thu, 12 Apr 2018 12:02:36 -0700 Subject: Add Auto Responder handler (#8386) WIP Out Of Office Return error for status command if user status is OOO Ignore notifications if Out Of Office Disable AutoResponder if status is set to online Add test for AutoResponder DisableAutoResponse when manually setting status Remove check on status slash command return early if user does not exists in SendAutoResponse method Add proper error handling Add a newline after error handling Revert back to err == nil in api4/status.go Remove a.Go when using a.Publish Add name consistency with the feature auto responder Last changes for name consistency, also fix failing test with auto_responder Fix names of functions in auto responder test Add ExperimentalEnableAutomaticReplies flag Auto Responder reply to a post --- app/status.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'app/status.go') diff --git a/app/status.go b/app/status.go index c8bff0d1a..64d5379ef 100644 --- a/app/status.go +++ b/app/status.go @@ -303,6 +303,32 @@ func (a *App) SaveAndBroadcastStatus(status *model.Status) *model.AppError { return nil } +func (a *App) SetStatusOutOfOffice(userId string) { + if !*a.Config().ServiceSettings.EnableUserStatuses { + return + } + + status, err := a.GetStatus(userId) + + if err != nil { + status = &model.Status{UserId: userId, Status: model.STATUS_OUT_OF_OFFICE, Manual: false, LastActivityAt: 0, ActiveChannel: ""} + } + + status.Status = model.STATUS_OUT_OF_OFFICE + 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_OUT_OF_OFFICE) + event.Add("user_id", status.UserId) + 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