summaryrefslogtreecommitdiffstats
path: root/app/command_shortcuts.go
blob: e10ae8a87486be9cd756bd0de43dd75e15c77221 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package app

import (
	"bytes"
	"strings"

	"github.com/mattermost/platform/model"
	goi18n "github.com/nicksnyder/go-i18n/i18n"
)

type ShortcutsProvider struct {
}

const (
	CMD_SHORTCUTS = "shortcuts"
)

func init() {
	RegisterCommandProvider(&ShortcutsProvider{})
}

func (me *ShortcutsProvider) GetTrigger() string {
	return CMD_SHORTCUTS
}

func (me *ShortcutsProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
	return &model.Command{
		Trigger:          CMD_SHORTCUTS,
		AutoComplete:     true,
		AutoCompleteDesc: T("api.command_shortcuts.desc"),
		AutoCompleteHint: "",
		DisplayName:      T("api.command_shortcuts.name"),
	}
}

func (me *ShortcutsProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
	shortcutIds := [...]string{
		"api.command_shortcuts.header",
		// Nav shortcuts
		"api.command_shortcuts.nav.header",
		"api.command_shortcuts.nav.prev",
		"api.command_shortcuts.nav.next",
		"api.command_shortcuts.nav.unread_prev",
		"api.command_shortcuts.nav.unread_next",
		"api.command_shortcuts.nav.switcher",
		"api.command_shortcuts.nav.direct_messages_menu",
		"api.command_shortcuts.nav.settings",
		"api.command_shortcuts.nav.recent_mentions",
		// Files shortcuts
		"api.command_shortcuts.files.header",
		"api.command_shortcuts.files.upload",
		// Msg shortcuts
		"api.command_shortcuts.msgs.header",
		"api.command_shortcuts.msgs.mark_as_read",
		"api.command_shortcuts.msgs.reprint_prev",
		"api.command_shortcuts.msgs.reprint_next",
		"api.command_shortcuts.msgs.edit",
		"api.command_shortcuts.msgs.reply",
		"api.command_shortcuts.msgs.comp_username",
		"api.command_shortcuts.msgs.comp_channel",
		"api.command_shortcuts.msgs.comp_emoji",
		// Browser shortcuts
		"api.command_shortcuts.browser.header",
		"api.command_shortcuts.browser.channel_prev",
		"api.command_shortcuts.browser.channel_next",
		"api.command_shortcuts.browser.font_increase",
		"api.command_shortcuts.browser.font_decrease",
		"api.command_shortcuts.browser.highlight_prev",
		"api.command_shortcuts.browser.highlight_next",
		"api.command_shortcuts.browser.newline",
	}

	var osDependentWords map[string]interface{}
	if strings.Contains(message, "mac") {
		osDependentWords = map[string]interface{}{
			"CmdOrCtrl":      args.T("api.command_shortcuts.cmd"),
			"ChannelPrevCmd": args.T("api.command_shortcuts.browser.channel_prev.cmd_mac"),
			"ChannelNextCmd": args.T("api.command_shortcuts.browser.channel_next.cmd_mac"),
		}
	} else {
		osDependentWords = map[string]interface{}{
			"CmdOrCtrl":      args.T("api.command_shortcuts.ctrl"),
			"ChannelPrevCmd": args.T("api.command_shortcuts.browser.channel_prev.cmd"),
			"ChannelNextCmd": args.T("api.command_shortcuts.browser.channel_next.cmd"),
		}
	}

	var buffer bytes.Buffer
	for _, element := range shortcutIds {
		buffer.WriteString(args.T(element, osDependentWords))
	}

	return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: buffer.String()}
}