Files
mattermost/app/command_leave.go
David Meza b54d134299 PLT-6484 Add /leave command to leave a channel (#6402)
* PLT-6484 Add /leave command to leave a channel

* Text changes requeted on review.

* PLT-6484 Display the right error message when trying to /leave town-square

* PLT-6484 Be able to execute /leave command in direct and group message channels with the same effect as clicking x

* PLT-6484 Refactor to create new leave_private_channel_modal.jsx

* PLT-6484 Remove previous leave private channel logic to use new leave_private_channel_modal.jsx

* Remove dot in command description. Change localized error when leaving Town square.

* disable /leave command in reply threads on the right-hand sidebar, since it is not obvious which channel you should leave
2017-08-03 08:59:42 -04:00

56 lines
1.9 KiB
Go

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type LeaveProvider struct {
}
const (
CMD_LEAVE = "leave"
)
func init() {
RegisterCommandProvider(&LeaveProvider{})
}
func (me *LeaveProvider) GetTrigger() string {
return CMD_LEAVE
}
func (me *LeaveProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LEAVE,
AutoComplete: true,
AutoCompleteDesc: T("api.command_leave.desc"),
DisplayName: T("api.command_leave.name"),
}
}
func (me *LeaveProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
var channel *model.Channel
var noChannelErr *model.AppError
if channel, noChannelErr = GetChannel(args.ChannelId); noChannelErr != nil {
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
if channel.Name == model.DEFAULT_CHANNEL {
return &model.CommandResponse{Text: args.T("api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
err := LeaveChannel(args.ChannelId, args.UserId)
if err != nil {
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
team, err := GetTeam(args.TeamId)
if err != nil {
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
return &model.CommandResponse{GotoLocation: args.SiteURL + "/" + team.Name + "/channels/" + model.DEFAULT_CHANNEL, Text: args.T("api.command_leave.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}