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).
This commit is contained in:
miruka 2020-08-24 06:01:09 -04:00
parent 83f35c034e
commit bbb46a9feb
2 changed files with 13 additions and 9 deletions

View File

@ -74,7 +74,7 @@ HFlickableColumnPage {
enabled: enabled:
avatar.changed || avatar.changed ||
nameField.item.changed || nameField.item.changed ||
(aliasField.item.changed && ! aliasField.alreadyTakenBy) (aliasField.item.changed && ! aliasField.item.error)
onClicked: applyChanges() onClicked: applyChanges()
} }
@ -235,6 +235,8 @@ HFlickableColumnPage {
readonly property var aliases: window.settings.writeAliases readonly property var aliases: window.settings.writeAliases
readonly property string currentAlias: aliases[userId] || "" readonly property string currentAlias: aliases[userId] || ""
readonly property bool hasWhiteSpace: /\s/.test(item.text)
readonly property string alreadyTakenBy: { readonly property string alreadyTakenBy: {
if (! item.text) return "" if (! item.text) return ""
@ -247,8 +249,8 @@ HFlickableColumnPage {
label.text: qsTr("Composer alias:") label.text: qsTr("Composer alias:")
errorLabel.text: errorLabel.text:
alreadyTakenBy ? hasWhiteSpace ? qsTr("Alias cannot include spaces") :
qsTr("Taken by %1").arg(alreadyTakenBy) : alreadyTakenBy ? qsTr("Taken by %1").arg(alreadyTakenBy) :
"" ""
toolTip.text: qsTr( toolTip.text: qsTr(
@ -263,7 +265,7 @@ HFlickableColumnPage {
HTextField { HTextField {
width: parent.width width: parent.width
error: aliasField.alreadyTakenBy !== "" error: aliasField.hasWhiteSpace || aliasField.alreadyTakenBy
defaultText: aliasField.currentAlias defaultText: aliasField.currentAlias
placeholderText: qsTr("e.g. %1").arg(( placeholderText: qsTr("e.g. %1").arg((
nameField.item.text || nameField.item.text ||

View File

@ -19,14 +19,16 @@ HTextArea {
property bool textChangedSinceLostFocus: false property bool textChangedSinceLostFocus: false
readonly property var usableAliases: { 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 // 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) const room = ModelStore.get(id, "rooms").find(chat.roomId)
if (room &&
! room.inviter_id && ! room.left && room.can_send_messages) room && ! room.inviter_id && ! room.left && room.can_send_messages?
obj[id] = alia obj[id] = alias.trim().split(/\s/)[0] :
null
} }
return obj return obj