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.
4 files changed, 30 insertions, 5 deletions
diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml
index f31123e5..f6fe03c5 100644
--- a/resources/qml/MessageInput.qml
+++ b/resources/qml/MessageInput.qml
@@ -13,6 +13,8 @@ import im.nheko 1.0
Rectangle {
id: inputBar
+ readonly property string text: messageInput.text
+
color: Nheko.colors.window
Layout.fillWidth: true
Layout.preferredHeight: row.implicitHeight
diff --git a/resources/qml/NotificationWarning.qml b/resources/qml/MessageInputWarning.qml
index 13d2cb23..c2db2daa 100644
--- a/resources/qml/NotificationWarning.qml
+++ b/resources/qml/MessageInputWarning.qml
@@ -8,14 +8,20 @@ import QtQuick.Layouts 1.2
import im.nheko 1.0
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
Layout.fillWidth: true
+ Layout.margins: isVisible ? Nheko.paddingSmall : 0
Rectangle {
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...
color: Qt.rgba(Nheko.theme.error.r, Nheko.theme.error.g, Nheko.theme.error.b, 0.3)
border.width: 1
@@ -31,7 +37,7 @@ Item {
anchors.verticalCenter: parent.verticalCenter
anchors.margins: Nheko.paddingSmall
color: Nheko.colors.text
- text: qsTr("You are about to notify the whole room")
+ text: warningRoot.text
textFormat: Text.PlainText
}
diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml
index e836f60f..5c982270 100644
--- a/resources/qml/TimelineView.qml
+++ b/resources/qml/TimelineView.qml
@@ -153,13 +153,30 @@ Item {
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 {
}
MessageInput {
+ id: input
}
}
diff --git a/resources/res.qrc b/resources/res.qrc
index 88159d40..5fbd00d7 100644
--- a/resources/res.qrc
+++ b/resources/res.qrc
@@ -123,7 +123,7 @@
<file>qml/ForwardCompleter.qml</file>
<file>qml/SelfVerificationCheck.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/AdaptiveLayoutElement.qml</file>
<file>qml/components/AvatarListTile.qml</file>
|