| 1 | // SPDX-FileCopyrightText: Nheko Contributors |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "CommandCompleter.h" |
| 6 | |
| 7 | #include "CompletionModelRoles.h" |
| 8 | |
| 9 | CommandCompleter::CommandCompleter(QObject *parent) |
| 10 | : QAbstractListModel(parent) |
| 11 | { |
| 12 | } |
| 13 | |
| 14 | QHash<int, QByteArray> |
| 15 | CommandCompleter::roleNames() const |
| 16 | { |
| 17 | return { |
| 18 | {CompletionModel::CompletionRole, "completionRole"}, |
| 19 | {CompletionModel::SearchRole, "searchRole"}, |
| 20 | {CompletionModel::SearchRole2, "searchRole2"}, |
| 21 | {Roles::Name, "name"}, |
| 22 | {Roles::Description, "description"}, |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | QVariant |
| 27 | CommandCompleter::data(const QModelIndex &index, int role) const |
| 28 | { |
| 29 | if (hasIndex(index.row(), index.column(), index.parent())) { |
| 30 | switch (role) { |
| 31 | case CompletionModel::CompletionRole: |
| 32 | // append space where applicable in a completion |
| 33 | switch (index.row()) { |
| 34 | case Me: |
| 35 | return QStringLiteral("/me "); |
| 36 | case React: |
| 37 | return QStringLiteral("/react "); |
| 38 | case Join: |
| 39 | return QStringLiteral("/join "); |
| 40 | case Knock: |
| 41 | return QStringLiteral("/knock "); |
| 42 | case Part: |
| 43 | return QStringLiteral("/part "); |
| 44 | case Leave: |
| 45 | return QStringLiteral("/leave "); |
| 46 | case Invite: |
| 47 | return QStringLiteral("/invite @"); |
| 48 | case Kick: |
| 49 | return QStringLiteral("/kick @"); |
| 50 | case Ban: |
| 51 | return QStringLiteral("/ban @"); |
| 52 | case Unban: |
| 53 | return QStringLiteral("/unban @"); |
| 54 | case Redact: |
| 55 | return QStringLiteral("/redact "); |
| 56 | case Roomnick: |
| 57 | return QStringLiteral("/roomnick "); |
| 58 | case Shrug: |
| 59 | return QStringLiteral("/shrug"); |
| 60 | case Fliptable: |
| 61 | return QStringLiteral("/fliptable"); |
| 62 | case Unfliptable: |
| 63 | return QStringLiteral("/unfliptable"); |
| 64 | case Sovietflip: |
| 65 | return QStringLiteral("/sovietflip"); |
| 66 | case ClearTimeline: |
| 67 | return QStringLiteral("/clear-timeline"); |
| 68 | case ResetState: |
| 69 | return QStringLiteral("/reset-state"); |
| 70 | case RotateMegolmSession: |
| 71 | return QStringLiteral("/rotate-megolm-session"); |
| 72 | case Md: |
| 73 | return QStringLiteral("/md "); |
| 74 | case Cmark: |
| 75 | return QStringLiteral("/cmark "); |
| 76 | case Plain: |
| 77 | return QStringLiteral("/plain "); |
| 78 | case Rainbow: |
| 79 | return QStringLiteral("/rainbow "); |
| 80 | case RainbowMe: |
| 81 | return QStringLiteral("/rainbowme "); |
| 82 | case Notice: |
| 83 | return QStringLiteral("/notice "); |
| 84 | case RainbowNotice: |
| 85 | return QStringLiteral("/rainbownotice "); |
| 86 | case Confetti: |
| 87 | return QStringLiteral("/confetti "); |
| 88 | case RainbowConfetti: |
| 89 | return QStringLiteral("/rainbowconfetti "); |
| 90 | case Rainfall: |
| 91 | return QStringLiteral("/rainfall "); |
| 92 | case Msgtype: |
| 93 | return QStringLiteral("/msgtype "); |
| 94 | case Glitch: |
| 95 | return QStringLiteral("/glitch "); |
| 96 | case GradualGlitch: |
| 97 | return QStringLiteral("/gradualglitch "); |
| 98 | case Goto: |
| 99 | return QStringLiteral("/goto "); |
| 100 | case ConvertToDm: |
| 101 | return QStringLiteral("/converttodm"); |
| 102 | case ConvertToRoom: |
| 103 | return QStringLiteral("/converttoroom"); |
| 104 | case Ignore: |
| 105 | return QStringLiteral("/ignore"); |
| 106 | case Unignore: |
| 107 | return QStringLiteral("/unignore"); |
| 108 | case BlockInvites: |
| 109 | return QStringLiteral("/blockinvites"); |
| 110 | case AllowInvites: |
| 111 | return QStringLiteral("/allowinvites"); |
| 112 | default: |
| 113 | return {}; |
| 114 | } |
| 115 | case CompletionModel::SearchRole: |
| 116 | case Qt::DisplayRole: |
| 117 | case Roles::Name: |
| 118 | switch (index.row()) { |
| 119 | case Me: |
| 120 | return tr("/me <message>"); |
| 121 | case React: |
| 122 | return tr("/react <text>"); |
| 123 | case Join: |
| 124 | return tr("/join <!roomid|#alias> [reason]"); |
| 125 | case Knock: |
| 126 | return tr("/knock <!roomid|#alias> [reason]"); |
| 127 | case Part: |
| 128 | return tr("/part [reason]"); |
| 129 | case Leave: |
| 130 | return tr("/leave [reason]"); |
| 131 | case Invite: |
| 132 | return tr("/invite <@userid> [reason]"); |
| 133 | case Kick: |
| 134 | return tr("/kick <@userid> [reason]"); |
| 135 | case Ban: |
| 136 | return tr("/ban <@userid> [reason]"); |
| 137 | case Unban: |
| 138 | return tr("/unban <@userid> [reason]"); |
| 139 | case Redact: |
| 140 | return tr("/redact <$eventid|@userid>"); |
| 141 | case Roomnick: |
| 142 | return tr("/roomnick <displayname>"); |
| 143 | case Shrug: |
| 144 | return tr("/shrug [message]"); |
| 145 | case Fliptable: |
| 146 | return QStringLiteral("/fliptable"); |
| 147 | case Unfliptable: |
| 148 | return QStringLiteral("/unfliptable"); |
| 149 | case Sovietflip: |
| 150 | return QStringLiteral("/sovietflip"); |
| 151 | case ClearTimeline: |
| 152 | return QStringLiteral("/clear-timeline"); |
| 153 | case ResetState: |
| 154 | return QStringLiteral("/reset-state"); |
| 155 | case RotateMegolmSession: |
| 156 | return QStringLiteral("/rotate-megolm-session"); |
| 157 | case Md: |
| 158 | return tr("/md <message>"); |
| 159 | case Cmark: |
| 160 | return tr("/cmark <message>"); |
| 161 | case Plain: |
| 162 | return tr("/plain <message>"); |
| 163 | case Rainbow: |
| 164 | return tr("/rainbow <message>"); |
| 165 | case RainbowMe: |
| 166 | return tr("/rainbowme <message>"); |
| 167 | case Notice: |
| 168 | return tr("/notice <message>"); |
| 169 | case RainbowNotice: |
| 170 | return tr("/rainbownotice <message>"); |
| 171 | case Confetti: |
| 172 | return tr("/confetti [message]"); |
| 173 | case RainbowConfetti: |
| 174 | return tr("/rainbowconfetti [message]"); |
| 175 | case Rainfall: |
| 176 | return tr("/rainfall [message]"); |
| 177 | case Msgtype: |
| 178 | return tr("/msgtype <msgtype> [message]"); |
| 179 | case Glitch: |
| 180 | return tr("/glitch <message>"); |
| 181 | case GradualGlitch: |
| 182 | return tr("/gradualglitch <message>"); |
| 183 | case Goto: |
| 184 | return tr("/goto <message reference>"); |
| 185 | case ConvertToDm: |
| 186 | return QStringLiteral("/converttodm"); |
| 187 | case ConvertToRoom: |
| 188 | return QStringLiteral("/converttoroom"); |
| 189 | case Ignore: |
| 190 | return QStringLiteral("/ignore <@userid>"); |
| 191 | case Unignore: |
| 192 | return QStringLiteral("/unignore <@userid>"); |
| 193 | case BlockInvites: |
| 194 | return QStringLiteral("/blockinvites <@userid>|<!roomid>|<servername>|all"); |
| 195 | case AllowInvites: |
| 196 | return QStringLiteral("/allowinvites <@userid>|<!roomid>|<servername>|all"); |
| 197 | default: |
| 198 | return {}; |
| 199 | } |
| 200 | case CompletionModel::SearchRole2: |
| 201 | case Roles::Description: |
| 202 | switch (index.row()) { |
| 203 | case Me: |
| 204 | return tr("Send a message expressing an action."); |
| 205 | case React: |
| 206 | return tr("Send <text> as a reaction when you’re replying to a message."); |
| 207 | case Join: |
| 208 | return tr("Join a room. Reason is optional."); |
| 209 | case Knock: |
| 210 | return tr("Ask to join a room. Reason is optional."); |
| 211 | case Part: |
| 212 | return tr("Leave a room. Reason is optional."); |
| 213 | case Leave: |
| 214 | return tr("Leave a room. Reason is optional."); |
| 215 | case Invite: |
| 216 | return tr("Invite a user into the current room. Reason is optional."); |
| 217 | case Kick: |
| 218 | return tr("Kick a user from the current room. Reason is optional. If user is left " |
| 219 | "out, will try to kick the sender you are replying to."); |
| 220 | case Ban: |
| 221 | return tr("Ban a user from the current room. Reason is optional. If user is left " |
| 222 | "out, will try to ban the sender you are replying to."); |
| 223 | case Unban: |
| 224 | return tr("Unban a user in the current room. Reason is optional. If user is left " |
| 225 | "out, will try to unban the sender you are replying to."); |
| 226 | case Redact: |
| 227 | return tr("Redact an event by event id or that you are replying to or all locally " |
| 228 | "cached messages of a user."); |
| 229 | case Roomnick: |
| 230 | return tr("Change your displayname in this room."); |
| 231 | case Shrug: |
| 232 | return tr("¯\\_(ツ)_/¯ with an optional message."); |
| 233 | case Fliptable: |
| 234 | return tr("(╯°□°)╯︵ ┻━┻"); |
| 235 | case Unfliptable: |
| 236 | return tr("┯━┯╭( º _ º╭)"); |
| 237 | case Sovietflip: |
| 238 | return tr("ノ┬─┬ノ ︵ ( \\o°o)\\"); |
| 239 | case ClearTimeline: |
| 240 | return tr("Clear the currently cached messages in this room."); |
| 241 | case ResetState: |
| 242 | return tr("Refetch the state in this room."); |
| 243 | case RotateMegolmSession: |
| 244 | return tr("Rotate the current symmetric encryption key."); |
| 245 | case Md: |
| 246 | return tr("Send a markdown formatted message (ignoring the global setting)."); |
| 247 | case Cmark: |
| 248 | return tr( |
| 249 | "Send a commonmark formatted message disabling most extensions compared to /md."); |
| 250 | case Plain: |
| 251 | return tr("Send an unformatted message (ignoring the global setting)."); |
| 252 | case Rainbow: |
| 253 | return tr("Send a message in rainbow colors."); |
| 254 | case RainbowMe: |
| 255 | return tr("Send /me in rainbow colors."); |
| 256 | case Notice: |
| 257 | return tr("Send a bot message."); |
| 258 | case RainbowNotice: |
| 259 | return tr("Send a bot message in rainbow colors."); |
| 260 | case Confetti: |
| 261 | return tr("Send a message with confetti."); |
| 262 | case RainbowConfetti: |
| 263 | return tr("Send a message in rainbow colors with confetti."); |
| 264 | case Rainfall: |
| 265 | return tr("Send a message with rain."); |
| 266 | case Msgtype: |
| 267 | return tr("Send a message with a custom message type."); |
| 268 | case Glitch: |
| 269 | return tr("Send a message with a glitch effect."); |
| 270 | case GradualGlitch: |
| 271 | return tr("Send a message that gradually glitches."); |
| 272 | case Goto: |
| 273 | return tr("Go to a specific message using an event id, index or matrix: link"); |
| 274 | case ConvertToDm: |
| 275 | return tr("Convert this room to a direct chat."); |
| 276 | case ConvertToRoom: |
| 277 | return tr("Convert this direct chat into a room."); |
| 278 | case Ignore: |
| 279 | return tr("Ignore a user."); |
| 280 | case Unignore: |
| 281 | return tr("Stop ignoring a user."); |
| 282 | case BlockInvites: |
| 283 | return tr("Block all invites from a user, a server, to a specific room or set the " |
| 284 | "default."); |
| 285 | case AllowInvites: |
| 286 | return tr("Allow all invites from a user, a server, to a specific room or set the " |
| 287 | "default."); |
| 288 | default: |
| 289 | return {}; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | return {}; |
| 294 | } |