summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2023-02-23 21:57:53 -0500
committerLoren Burkholder <computersemiexpert@outlook.com>2023-02-28 20:10:25 -0500
commitb6ef00b5ee14bd0adc85c3a98bb8a127f79932ea (patch)
treedf09acee8f648cea85aa75bfcd43b6f247e8cc81 /src
parentEnhance appearance of room ping warning (diff)
downloadnheko-b6ef00b5ee14bd0adc85c3a98bb8a127f79932ea.tar.xz
Show warning when invalid command is entered
Fixes #1363

Please note that this doesn't prompt when you try to send a message with a bad command.
Diffstat (limited to 'src')
-rw-r--r--src/CompletionProxyModel.h2
-rw-r--r--src/timeline/InputBar.cpp2
-rw-r--r--src/ui/NhekoGlobalObject.cpp60
-rw-r--r--src/ui/NhekoGlobalObject.h3
4 files changed, 67 insertions, 0 deletions
diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h

index e0f00788..90daf7ad 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h
@@ -184,6 +184,8 @@ public slots: void setSearchString(const QString &s); QString searchString() const { return searchString_; } + bool hasCompletion() const { return rowCount() > 0; } + signals: void newSearchString(QString); diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index 7d964bb5..5184ba94 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp
@@ -846,6 +846,8 @@ InputBar::command(const QString &command, QString args) cache::getMembers(this->room->roomId().toStdString(), 0, -1)); } else if (command == QLatin1String("converttoroom")) { utils::removeDirectFromRoom(this->room->roomId()); + } else { + message("/" + command + " " + args); } } diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp
index a6f9abe7..3cb6a8a8 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp
@@ -190,3 +190,63 @@ Nheko::setWindowRole([[maybe_unused]] QWindow *win, [[maybe_unused]] QString new QXcbWindowFunctions::setWmWindowRole(win, newRole.toUtf8()); #endif } + +QString +Nheko::getCommandFromText(const QString &text) +{ + if (text.startsWith('/')) { + int command_end = text.indexOf(QRegularExpression(QStringLiteral("\\s"))); + if (command_end == -1) + command_end = text.size(); + auto command = text.mid(1, command_end - 1); + if (command.isEmpty() || command == QLatin1String("/")) + return {}; + else { + return command; + } + } else + return {}; +} + +bool +Nheko::isInvalidCommand(QString command) const +{ + if (command.size() <= 0) + return false; + + static const QStringList validCommands{QStringLiteral("/me"), + QStringLiteral("/react"), + QStringLiteral("/join"), + QStringLiteral("/knock"), + QStringLiteral("/part"), + QStringLiteral("/leave"), + QStringLiteral("/invite"), + QStringLiteral("/kick"), + QStringLiteral("/ban"), + QStringLiteral("/unban"), + QStringLiteral("/redact"), + QStringLiteral("/roomnick"), + QStringLiteral("/shrug"), + QStringLiteral("/fliptable"), + QStringLiteral("/unfliptable"), + QStringLiteral("/sovietflip"), + QStringLiteral("/clear-timeline"), + QStringLiteral("/reset-state"), + QStringLiteral("/rotate-megolm-session"), + QStringLiteral("/md"), + QStringLiteral("/cmark"), + QStringLiteral("/plain"), + QStringLiteral("/rainbow"), + QStringLiteral("/rainbowme"), + QStringLiteral("/notice"), + QStringLiteral("/rainbownotice"), + QStringLiteral("/confetti"), + QStringLiteral("/rainbowconfetti"), + QStringLiteral("/goto"), + QStringLiteral("/converttodm"), + QStringLiteral("/converttoroom")}; + + if (!command.startsWith('/')) + command.prepend('/'); + return !validCommands.contains(command); +} diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h
index b7a7a637..1ea2c109 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h
@@ -72,6 +72,9 @@ public: Q_INVOKABLE void setTransientParent(QWindow *window, QWindow *parentWindow) const; Q_INVOKABLE void setWindowRole(QWindow *win, QString newRole) const; + Q_INVOKABLE QString getCommandFromText(const QString &text); + Q_INVOKABLE bool isInvalidCommand(QString command) const; + public slots: void updateUserProfile();