diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/command_dnd.go | 49 | ||||
-rw-r--r-- | app/notification.go | 2 | ||||
-rw-r--r-- | app/status.go | 28 |
3 files changed, 79 insertions, 0 deletions
diff --git a/app/command_dnd.go b/app/command_dnd.go new file mode 100644 index 000000000..7eff6039d --- /dev/null +++ b/app/command_dnd.go @@ -0,0 +1,49 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "github.com/mattermost/mattermost-server/model" + goi18n "github.com/nicksnyder/go-i18n/i18n" +) + +type DndProvider struct { +} + +const ( + CMD_DND = "dnd" +) + +func init() { + RegisterCommandProvider(&DndProvider{}) +} + +func (me *DndProvider) GetTrigger() string { + return CMD_DND +} + +func (me *DndProvider) GetCommand(T goi18n.TranslateFunc) *model.Command { + return &model.Command{ + Trigger: CMD_DND, + AutoComplete: true, + AutoCompleteDesc: T("api.command_dnd.desc"), + DisplayName: T("api.command_dnd.name"), + } +} + +func (me *DndProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse { + status, err := a.GetStatus(args.UserId) + if err != nil { + return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.error")} + } else { + if status.Status == "dnd" { + a.SetStatusOnline(args.UserId, args.Session.Id, true) + return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.disabled")} + } + } + + a.SetStatusDoNotDisturb(args.UserId) + + return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.success")} +} diff --git a/app/notification.go b/app/notification.go index 3adf14419..84a2b610b 100644 --- a/app/notification.go +++ b/app/notification.go @@ -993,6 +993,8 @@ func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *mo return true } else if pushStatus == model.STATUS_OFFLINE && status.Status == model.STATUS_OFFLINE { return true + } else if status.Status == model.STATUS_DND { + return false } return false 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) |