From bbb46a9feb37276774e9951393ed7159c7d26ea9 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 24 Aug 2020 06:01:09 -0400 Subject: [PATCH] Disallow whitespace in composer aliases These cause problems with the composer alias parsing code. If an alias from the config file has whitespace, only the first word will be taken into account (ignoring any leading or trailing whitespace). --- src/gui/Pages/AccountSettings/Account.qml | 10 ++++++---- src/gui/Pages/Chat/Composer/MessageArea.qml | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gui/Pages/AccountSettings/Account.qml b/src/gui/Pages/AccountSettings/Account.qml index ac34b7ae..e002fc07 100644 --- a/src/gui/Pages/AccountSettings/Account.qml +++ b/src/gui/Pages/AccountSettings/Account.qml @@ -74,7 +74,7 @@ HFlickableColumnPage { enabled: avatar.changed || nameField.item.changed || - (aliasField.item.changed && ! aliasField.alreadyTakenBy) + (aliasField.item.changed && ! aliasField.item.error) onClicked: applyChanges() } @@ -235,6 +235,8 @@ HFlickableColumnPage { readonly property var aliases: window.settings.writeAliases readonly property string currentAlias: aliases[userId] || "" + readonly property bool hasWhiteSpace: /\s/.test(item.text) + readonly property string alreadyTakenBy: { if (! item.text) return "" @@ -247,8 +249,8 @@ HFlickableColumnPage { label.text: qsTr("Composer alias:") errorLabel.text: - alreadyTakenBy ? - qsTr("Taken by %1").arg(alreadyTakenBy) : + hasWhiteSpace ? qsTr("Alias cannot include spaces") : + alreadyTakenBy ? qsTr("Taken by %1").arg(alreadyTakenBy) : "" toolTip.text: qsTr( @@ -263,7 +265,7 @@ HFlickableColumnPage { HTextField { width: parent.width - error: aliasField.alreadyTakenBy !== "" + error: aliasField.hasWhiteSpace || aliasField.alreadyTakenBy defaultText: aliasField.currentAlias placeholderText: qsTr("e.g. %1").arg(( nameField.item.text || diff --git a/src/gui/Pages/Chat/Composer/MessageArea.qml b/src/gui/Pages/Chat/Composer/MessageArea.qml index ba834c18..c716db16 100644 --- a/src/gui/Pages/Chat/Composer/MessageArea.qml +++ b/src/gui/Pages/Chat/Composer/MessageArea.qml @@ -19,14 +19,16 @@ HTextArea { property bool textChangedSinceLostFocus: false readonly property var usableAliases: { - const obj = {} + const obj = {} + const aliases = window.settings.writeAliases // Get accounts that are members of this room with permission to talk - for (const [id, alia] of Object.entries(window.settings.writeAliases)){ + for (const [id, alias] of Object.entries(aliases)) { const room = ModelStore.get(id, "rooms").find(chat.roomId) - if (room && - ! room.inviter_id && ! room.left && room.can_send_messages) - obj[id] = alia + + room && ! room.inviter_id && ! room.left && room.can_send_messages? + obj[id] = alias.trim().split(/\s/)[0] : + null } return obj