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/command_dnd.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/command_dnd.go (limited to 'app/command_dnd.go') 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")} +} -- cgit v1.2.3-1-g7c22