summaryrefslogtreecommitdiffstats
path: root/app/command_leave.go
diff options
context:
space:
mode:
authorDavid Meza <dmeza@users.noreply.github.com>2017-08-03 07:59:42 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-08-03 08:59:42 -0400
commitb54d1342990253d3fe4a00c64df27cdd1bb0719b (patch)
treedadf9452248080b1a976d37430409696091fe52b /app/command_leave.go
parent19804c4e40340cc4c0093197f71216719ffe4050 (diff)
downloadchat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.tar.gz
chat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.tar.bz2
chat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.zip
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
Diffstat (limited to 'app/command_leave.go')
-rw-r--r--app/command_leave.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/app/command_leave.go b/app/command_leave.go
new file mode 100644
index 000000000..963172e86
--- /dev/null
+++ b/app/command_leave.go
@@ -0,0 +1,55 @@
+// 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}
+}