2023-02-22 01:48:49 +03:00
|
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2022-11-09 06:58:19 +03:00
|
|
|
|
//
|
|
|
|
|
// 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:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/me ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case React:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/react ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Join:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/join ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Knock:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/knock ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Part:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/part ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Leave:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/leave ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Invite:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/invite @");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Kick:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/kick @");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Ban:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/ban @");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Unban:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/unban @");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Redact:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/redact ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Roomnick:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/roomnick ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Shrug:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/shrug");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Fliptable:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/fliptable");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Unfliptable:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/unfliptable");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Sovietflip:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/sovietflip");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ClearTimeline:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/clear-timeline");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ResetState:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/reset-state");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RotateMegolmSession:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rotate-megolm-session");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Md:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/md ");
|
2023-01-31 20:22:12 +03:00
|
|
|
|
case Cmark:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/cmark ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Plain:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/plain ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Rainbow:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rainbow ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RainbowMe:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rainbowme ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Notice:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/notice ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RainbowNotice:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rainbownotice ");
|
2022-12-10 18:17:15 +03:00
|
|
|
|
case Confetti:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/confetti ");
|
2022-12-10 18:17:15 +03:00
|
|
|
|
case RainbowConfetti:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rainbowconfetti ");
|
2023-03-07 21:11:00 +03:00
|
|
|
|
case Rainfall:
|
|
|
|
|
return QStringLiteral("/rainfall ");
|
2023-03-22 02:44:00 +03:00
|
|
|
|
case Msgtype:
|
|
|
|
|
return QStringLiteral("/msgtype ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Goto:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/goto ");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ConvertToDm:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/converttodm");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ConvertToRoom:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/converttoroom");
|
2023-12-12 04:29:36 +03:00
|
|
|
|
case Ignore:
|
|
|
|
|
return QStringLiteral("/ignore");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
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:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/join <!roomid|#alias> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Knock:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/knock <!roomid|#alias> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Part:
|
|
|
|
|
return tr("/part [reason]");
|
|
|
|
|
case Leave:
|
|
|
|
|
return tr("/leave [reason]");
|
|
|
|
|
case Invite:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/invite <@userid> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Kick:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/kick <@userid> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Ban:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/ban <@userid> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Unban:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/unban <@userid> [reason]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Redact:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/redact <$eventid|@userid>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Roomnick:
|
|
|
|
|
return tr("/roomnick <displayname>");
|
|
|
|
|
case Shrug:
|
|
|
|
|
return tr("/shrug [message]");
|
|
|
|
|
case Fliptable:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/fliptable");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Unfliptable:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/unfliptable");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Sovietflip:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/sovietflip");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ClearTimeline:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/clear-timeline");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ResetState:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/reset-state");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RotateMegolmSession:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/rotate-megolm-session");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Md:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/md <message>");
|
2023-01-31 20:22:12 +03:00
|
|
|
|
case Cmark:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/cmark <message>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Plain:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/plain <message>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Rainbow:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/rainbow <message>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RainbowMe:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/rainbowme <message>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Notice:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/notice <message>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case RainbowNotice:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/rainbownotice <message>");
|
2022-12-10 18:17:15 +03:00
|
|
|
|
case Confetti:
|
|
|
|
|
return tr("/confetti [message]");
|
|
|
|
|
case RainbowConfetti:
|
|
|
|
|
return tr("/rainbowconfetti [message]");
|
2023-03-07 21:11:00 +03:00
|
|
|
|
case Rainfall:
|
|
|
|
|
return tr("/rainfall [message]");
|
2023-03-22 02:44:00 +03:00
|
|
|
|
case Msgtype:
|
|
|
|
|
return tr("/msgtype <msgtype> [message]");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Goto:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("/goto <message reference>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ConvertToDm:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/converttodm");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ConvertToRoom:
|
2023-02-11 14:33:23 +03:00
|
|
|
|
return QStringLiteral("/converttoroom");
|
2023-12-12 04:29:36 +03:00
|
|
|
|
case Ignore:
|
|
|
|
|
return QStringLiteral("/ignore <@userid>");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
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).");
|
2023-01-31 20:22:12 +03:00
|
|
|
|
case Cmark:
|
|
|
|
|
return tr(
|
|
|
|
|
"Send a commonmark formatted message disabling most extensions compared to /md.");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
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.");
|
2022-12-10 18:17:15 +03:00
|
|
|
|
case Confetti:
|
|
|
|
|
return tr("Send a message with confetti.");
|
|
|
|
|
case RainbowConfetti:
|
|
|
|
|
return tr("Send a message in rainbow colors with confetti.");
|
2023-03-07 21:11:00 +03:00
|
|
|
|
case Rainfall:
|
|
|
|
|
return tr("Send a message with rain.");
|
2023-03-22 02:44:00 +03:00
|
|
|
|
case Msgtype:
|
|
|
|
|
return tr("Send a message with a custom message type.");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case Goto:
|
2023-02-10 22:56:05 +03:00
|
|
|
|
return tr("Go to a specific message using an event id, index or matrix: link");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
case ConvertToDm:
|
|
|
|
|
return tr("Convert this room to a direct chat.");
|
|
|
|
|
case ConvertToRoom:
|
|
|
|
|
return tr("Convert this direct chat into a room.");
|
2023-12-12 04:29:36 +03:00
|
|
|
|
case Ignore:
|
|
|
|
|
return tr("Ignores a user.");
|
2022-11-09 06:58:19 +03:00
|
|
|
|
default:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|