From 38e99f3a68c3debfa56a732835346c40d631998a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 9 Mar 2020 16:29:04 +0100 Subject: [PATCH] add editable list for alt aliases --- .../views/room_settings/AliasSettings.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index 79317d3d1b..7c766e3e31 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -158,6 +158,38 @@ export default class AliasSettings extends React.Component { }); } + changeAltAliases(altAliases) { + if (!this.props.canSetCanonicalAlias) return; + + this.setState({ + updatingCanonicalAlias: true, + altAliases, + }); + + const eventContent = {}; + + if (this.state.canonicalAlias) { + eventContent.alias = this.state.canonicalAlias; + } + if (altAliases) { + eventContent["alt_aliases"] = altAliases; + } + + MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias", + eventContent, "").catch((err) => { + console.error(err); + Modal.createTrackedDialog('Error updating alternative addresses', '', ErrorDialog, { + title: _t("Error updating main address"), + description: _t( + "There was an error updating the room's alternative addresses. It may not be allowed by the server " + + "or a temporary failure occurred.", + ), + }); + }).finally(() => { + this.setState({updatingCanonicalAlias: false}); + }); + } + onNewAliasChanged = (value) => { this.setState({newAlias: value}); }; @@ -216,6 +248,25 @@ export default class AliasSettings extends React.Component { this.changeCanonicalAlias(event.target.value); }; + onNewAltAliasChanged = (value) => { + this.setState({newAltAlias: value}); + } + + onAltAliasAdded = (alias) => { + const altAliases = this.state.altAliases.slice(); + if (!altAliases.some(a => a.trim() === alias.trim())) { + altAliases.push(alias.trim()); + this.changeAltAliases(altAliases); + this.setState({newAltAlias: ""}); + } + } + + onAltAliasDeleted = (index) => { + const altAliases = this.state.altAliases.slice(); + altAliases.splice(index, 1); + this.changeAltAliases(altAliases); + } + _getAliases() { return this.state.altAliases.concat(this._getLocalNonAltAliases()); } @@ -281,6 +332,22 @@ export default class AliasSettings extends React.Component {
{canonicalAliasSection} {localAliasesList} +
); }