mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
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.
This commit is contained in:
parent
9043087c80
commit
b6ef00b5ee
8 changed files with 97 additions and 5 deletions
|
@ -13,6 +13,8 @@ import im.nheko 1.0
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: inputBar
|
id: inputBar
|
||||||
|
|
||||||
|
readonly property string text: messageInput.text
|
||||||
|
|
||||||
color: Nheko.colors.window
|
color: Nheko.colors.window
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: row.implicitHeight
|
Layout.preferredHeight: row.implicitHeight
|
||||||
|
|
|
@ -8,14 +8,20 @@ import QtQuick.Layouts 1.2
|
||||||
import im.nheko 1.0
|
import im.nheko 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
implicitHeight: warningRect.visible ? warningDisplay.implicitHeight + 2 * Nheko.paddingSmall : 0
|
id: warningRoot
|
||||||
|
|
||||||
|
required property string text
|
||||||
|
required property bool isVisible
|
||||||
|
|
||||||
|
implicitHeight: isVisible ? warningDisplay.implicitHeight + 2 * Nheko.paddingSmall : 0
|
||||||
height: implicitHeight
|
height: implicitHeight
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.margins: isVisible ? Nheko.paddingSmall : 0
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: warningRect
|
id: warningRect
|
||||||
|
|
||||||
visible: (room && room.permissions.canPingRoom() && room.input.containsAtRoom)
|
visible: warningRoot.isVisible
|
||||||
// TODO: Qt.alpha() would make more sense but it wasn't working...
|
// TODO: Qt.alpha() would make more sense but it wasn't working...
|
||||||
color: Qt.rgba(Nheko.theme.error.r, Nheko.theme.error.g, Nheko.theme.error.b, 0.3)
|
color: Qt.rgba(Nheko.theme.error.r, Nheko.theme.error.g, Nheko.theme.error.b, 0.3)
|
||||||
border.width: 1
|
border.width: 1
|
||||||
|
@ -31,7 +37,7 @@ Item {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.margins: Nheko.paddingSmall
|
anchors.margins: Nheko.paddingSmall
|
||||||
color: Nheko.colors.text
|
color: Nheko.colors.text
|
||||||
text: qsTr("You are about to notify the whole room")
|
text: warningRoot.text
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,13 +153,30 @@ Item {
|
||||||
UploadBox {
|
UploadBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationWarning {
|
MessageInputWarning {
|
||||||
|
text: qsTr("You are about to notify the whole room")
|
||||||
|
isVisible: (room && room.permissions.canPingRoom() && room.input.containsAtRoom)
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageInputWarning {
|
||||||
|
text: qsTr("The command /%1 is not recognized and will be sent as part of your message").arg(Nheko.getCommandFromText(input.text))
|
||||||
|
isVisible: {
|
||||||
|
if (!input.text)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let command = Nheko.getCommandFromText(input.text);
|
||||||
|
if (Nheko.isInvalidCommand(command) && ("/" + command !== input.text))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReplyPopup {
|
ReplyPopup {
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageInput {
|
MessageInput {
|
||||||
|
id: input
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@
|
||||||
<file>qml/ForwardCompleter.qml</file>
|
<file>qml/ForwardCompleter.qml</file>
|
||||||
<file>qml/SelfVerificationCheck.qml</file>
|
<file>qml/SelfVerificationCheck.qml</file>
|
||||||
<file>qml/TypingIndicator.qml</file>
|
<file>qml/TypingIndicator.qml</file>
|
||||||
<file>qml/NotificationWarning.qml</file>
|
<file>qml/MessageInputWarning.qml</file>
|
||||||
<file>qml/components/AdaptiveLayout.qml</file>
|
<file>qml/components/AdaptiveLayout.qml</file>
|
||||||
<file>qml/components/AdaptiveLayoutElement.qml</file>
|
<file>qml/components/AdaptiveLayoutElement.qml</file>
|
||||||
<file>qml/components/AvatarListTile.qml</file>
|
<file>qml/components/AvatarListTile.qml</file>
|
||||||
|
|
|
@ -184,6 +184,8 @@ public slots:
|
||||||
void setSearchString(const QString &s);
|
void setSearchString(const QString &s);
|
||||||
QString searchString() const { return searchString_; }
|
QString searchString() const { return searchString_; }
|
||||||
|
|
||||||
|
bool hasCompletion() const { return rowCount() > 0; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void newSearchString(QString);
|
void newSearchString(QString);
|
||||||
|
|
||||||
|
|
|
@ -846,6 +846,8 @@ InputBar::command(const QString &command, QString args)
|
||||||
cache::getMembers(this->room->roomId().toStdString(), 0, -1));
|
cache::getMembers(this->room->roomId().toStdString(), 0, -1));
|
||||||
} else if (command == QLatin1String("converttoroom")) {
|
} else if (command == QLatin1String("converttoroom")) {
|
||||||
utils::removeDirectFromRoom(this->room->roomId());
|
utils::removeDirectFromRoom(this->room->roomId());
|
||||||
|
} else {
|
||||||
|
message("/" + command + " " + args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,3 +190,63 @@ Nheko::setWindowRole([[maybe_unused]] QWindow *win, [[maybe_unused]] QString new
|
||||||
QXcbWindowFunctions::setWmWindowRole(win, newRole.toUtf8());
|
QXcbWindowFunctions::setWmWindowRole(win, newRole.toUtf8());
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
|
|
@ -72,6 +72,9 @@ public:
|
||||||
Q_INVOKABLE void setTransientParent(QWindow *window, QWindow *parentWindow) const;
|
Q_INVOKABLE void setTransientParent(QWindow *window, QWindow *parentWindow) const;
|
||||||
Q_INVOKABLE void setWindowRole(QWindow *win, QString newRole) 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:
|
public slots:
|
||||||
void updateUserProfile();
|
void updateUserProfile();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue