Prevent saving alias taken by other account

This commit is contained in:
miruka 2020-03-13 12:10:47 -04:00
parent a0c42fe5a6
commit 298043b3cb
3 changed files with 37 additions and 7 deletions

View File

@ -89,7 +89,6 @@
- Adapt shortcuts flicking speed to font size
- Multiaccount aliases:
- Warn when conflict with another alias
- Prevent sending messages with a user not in the current room
- Accept drag and drop to upload files or set a new avatar

View File

@ -8,6 +8,7 @@ HColumnLayout {
property alias label: label
property alias errorLabel: errorLabel
property alias field: field
property alias toolTip: toolTip
@ -51,4 +52,16 @@ HColumnLayout {
Layout.fillWidth: true
}
HLabel {
id: errorLabel
visible: Layout.maximumHeight > 0
wrapMode: Text.Wrap
color: theme.colors.errorText
Layout.maximumHeight: text ? implicitHeight : 0
Layout.fillWidth: true
Behavior on Layout.maximumHeight { HNumberAnimation {} }
}
}

View File

@ -166,14 +166,31 @@ HGridLayout {
}
HLabeledTextField {
property string currentAlias:
window.settings.writeAliases[userId] || ""
property string currentAlias: aliases[userId] || ""
property bool changed: field.text !== currentAlias
readonly property var aliases: window.settings.writeAliases
readonly property string alreadyTakenBy: {
if (! field.text) return ""
for (const [id, idAlias] of Object.entries(aliases))
if (id !== userId && idAlias === field.text) return id
return ""
}
id: aliasField
label.text: qsTr("Multi-account composer alias:")
errorLabel.text:
alreadyTakenBy ?
qsTr("Taken by %1").arg(alreadyTakenBy) :
""
field.error: alreadyTakenBy !== ""
field.onAccepted: applyChanges()
field.placeholderText: (
nameField.field.text ||
@ -197,8 +214,6 @@ HGridLayout {
}
}
HSpacer {}
HRowLayout {
Layout.alignment: Qt.AlignBottom
@ -212,7 +227,10 @@ HGridLayout {
text: qsTr("Save")
loading: nameChangeRunning || avatarChangeRunning
enabled:
nameField.changed || aliasField.changed || avatar.changed
avatar.changed ||
nameField.changed ||
(aliasField.changed && ! aliasField.alreadyTakenBy)
onClicked: applyChanges()
Layout.fillWidth: true