summary refs log tree commit diff
path: root/src/CommandCompleter.cpp
blob: 2ec427d6715f05267710fc4cc89e6c66141100d4 (plain) (blame)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "CommandCompleter.h"

#include "CompletionModelRoles.h"

CommandCompleter::CommandCompleter(QObject *parent)
  : QAbstractListModel(parent)
{
}

QHash<int, QByteArray>
CommandCompleter::roleNames() const
{
    return {
      {CompletionModel::CompletionRole, "completionRole"},
      {CompletionModel::SearchRole, "searchRole"},
      {CompletionModel::SearchRole2, "searchRole2"},
      {Roles::Name, "name"},
      {Roles::Description, "description"},
    };
}

QVariant
CommandCompleter::data(const QModelIndex &index, int role) const
{
    if (hasIndex(index.row(), index.column(), index.parent())) {
        switch (role) {
        case CompletionModel::CompletionRole:
            // append space where applicable in a completion
            switch (index.row()) {
            case Me:
                return QStringLiteral("/me ");
            case React:
                return QStringLiteral("/react ");
            case Join:
                return QStringLiteral("/join ");
            case Knock:
                return QStringLiteral("/knock ");
            case Part:
                return QStringLiteral("/part ");
            case Leave:
                return QStringLiteral("/leave ");
            case Invite:
                return QStringLiteral("/invite @");
            case Kick:
                return QStringLiteral("/kick @");
            case Ban:
                return QStringLiteral("/ban @");
            case Unban:
                return QStringLiteral("/unban @");
            case Redact:
                return QStringLiteral("/redact ");
            case Roomnick:
                return QStringLiteral("/roomnick ");
            case Shrug:
                return QStringLiteral("/shrug");
            case Fliptable:
                return QStringLiteral("/fliptable");
            case Unfliptable:
                return QStringLiteral("/unfliptable");
            case Sovietflip:
                return QStringLiteral("/sovietflip");
            case ClearTimeline:
                return QStringLiteral("/clear-timeline");
            case ResetState:
                return QStringLiteral("/reset-state");
            case RotateMegolmSession:
                return QStringLiteral("/rotate-megolm-session");
            case Md:
                return QStringLiteral("/md ");
            case Cmark:
                return QStringLiteral("/cmark ");
            case Plain:
                return QStringLiteral("/plain ");
            case Rainbow:
                return QStringLiteral("/rainbow ");
            case RainbowMe:
                return QStringLiteral("/rainbowme ");
            case Notice:
                return QStringLiteral("/notice ");
            case RainbowNotice:
                return QStringLiteral("/rainbownotice ");
            case Confetti:
                return QStringLiteral("/confetti ");
            case RainbowConfetti:
                return QStringLiteral("/rainbowconfetti ");
            case Goto:
                return QStringLiteral("/goto ");
            case ConvertToDm:
                return QStringLiteral("/converttodm");
            case ConvertToRoom:
                return QStringLiteral("/converttoroom");
            default:
                return {};
            }
        case CompletionModel::SearchRole:
        case Qt::DisplayRole:
        case Roles::Name:
            switch (index.row()) {
            case Me:
                return tr("/me <message>");
            case React:
                return tr("/react <text>");
            case Join:
                return tr("/join <!roomid|#alias> [reason]");
            case Knock:
                return tr("/knock <!roomid|#alias> [reason]");
            case Part:
                return tr("/part [reason]");
            case Leave:
                return tr("/leave [reason]");
            case Invite:
                return tr("/invite <@userid> [reason]");
            case Kick:
                return tr("/kick <@userid> [reason]");
            case Ban:
                return tr("/ban <@userid> [reason]");
            case Unban:
                return tr("/unban <@userid> [reason]");
            case Redact:
                return tr("/redact <$eventid|@userid>");
            case Roomnick:
                return tr("/roomnick <displayname>");
            case Shrug:
                return tr("/shrug [message]");
            case Fliptable:
                return QStringLiteral("/fliptable");
            case Unfliptable:
                return QStringLiteral("/unfliptable");
            case Sovietflip:
                return QStringLiteral("/sovietflip");
            case ClearTimeline:
                return QStringLiteral("/clear-timeline");
            case ResetState:
                return QStringLiteral("/reset-state");
            case RotateMegolmSession:
                return QStringLiteral("/rotate-megolm-session");
            case Md:
                return tr("/md <message>");
            case Cmark:
                return tr("/cmark <message>");
            case Plain:
                return tr("/plain <message>");
            case Rainbow:
                return tr("/rainbow <message>");
            case RainbowMe:
                return tr("/rainbowme <message>");
            case Notice:
                return tr("/notice <message>");
            case RainbowNotice:
                return tr("/rainbownotice <message>");
            case Confetti:
                return tr("/confetti [message]");
            case RainbowConfetti:
                return tr("/rainbowconfetti [message]");
            case Goto:
                return tr("/goto <message reference>");
            case ConvertToDm:
                return QStringLiteral("/converttodm");
            case ConvertToRoom:
                return QStringLiteral("/converttoroom");
            default:
                return {};
            }
        case CompletionModel::SearchRole2:
        case Roles::Description:
            switch (index.row()) {
            case Me:
                return tr("Send a message expressing an action.");
            case React:
                return tr("Send <text> as a reaction when you’re replying to a message.");
            case Join:
                return tr("Join a room. Reason is optional.");
            case Knock:
                return tr("Ask to join a room. Reason is optional.");
            case Part:
                return tr("Leave a room. Reason is optional.");
            case Leave:
                return tr("Leave a room. Reason is optional.");
            case Invite:
                return tr("Invite a user into the current room. Reason is optional.");
            case Kick:
                return tr("Kick a user from the current room. Reason is optional.");
            case Ban:
                return tr("Ban a user from the current room. Reason is optional.");
            case Unban:
                return tr("Unban a user in the current room. Reason is optional.");
            case Redact:
                return tr("Redact an event or all locally cached messages of a user.");
            case Roomnick:
                return tr("Change your displayname in this room.");
            case Shrug:
                return tr(\\_(ツ)_/¯ with an optional message.");
            case Fliptable:
                return tr("(╯°□°)╯︵ ┻━┻");
            case Unfliptable:
                return tr("┯━┯╭( º _ º╭)");
            case Sovietflip:
                return tr("ノ┬─┬ノ ︵ ( \\o°o)\\");
            case ClearTimeline:
                return tr("Clear the currently cached messages in this room.");
            case ResetState:
                return tr("Refetch the state in this room.");
            case RotateMegolmSession:
                return tr("Rotate the current symmetric encryption key.");
            case Md:
                return tr("Send a markdown formatted message (ignoring the global setting).");
            case Cmark:
                return tr(
                  "Send a commonmark formatted message disabling most extensions compared to /md.");
            case Plain:
                return tr("Send an unformatted message (ignoring the global setting).");
            case Rainbow:
                return tr("Send a message in rainbow colors.");
            case RainbowMe:
                return tr("Send /me in rainbow colors.");
            case Notice:
                return tr("Send a bot message.");
            case RainbowNotice:
                return tr("Send a bot message in rainbow colors.");
            case Confetti:
                return tr("Send a message with confetti.");
            case RainbowConfetti:
                return tr("Send a message in rainbow colors with confetti.");
            case Goto:
                return tr("Go to a specific message using an event id, index or matrix: link");
            case ConvertToDm:
                return tr("Convert this room to a direct chat.");
            case ConvertToRoom:
                return tr("Convert this direct chat into a room.");
            default:
                return {};
            }
        }
    }
    return {};
}