From c6fa8ea24c21621f6c879818a7f8e01dd39afaa5 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 20 Sep 2018 01:07:01 +0100 Subject: [PATCH 1/3] show canonical aliases in timeline, and set/remove implicit ones --- src/TextForEvent.js | 19 ++++++++++++++ .../views/room_settings/AliasSettings.js | 25 ++++++++++++++----- src/components/views/rooms/EventTile.js | 1 + src/i18n/strings/en_EN.json | 2 ++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 6b68941ee3..6e119252f1 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -240,6 +240,24 @@ function textForRoomAliasesEvent(ev) { } } +function textForCanonicalAliasEvent(ev) { + const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); + const oldAlias = ev.getPrevContent().alias; + const newAlias = ev.getContent().alias; + + if (newAlias) { + return _t('%(senderName)s set the canonical address for this room to %(address)s.', { + senderName: senderName, + address: ev.getContent().alias, + }); + } + else if (oldAlias) { + return _t('%(senderName)s removed the canonical address for this room.', { + senderName: senderName, + }); + } +} + function textForCallAnswerEvent(event) { const senderName = event.sender ? event.sender.name : _t('Someone'); const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)'); @@ -402,6 +420,7 @@ const handlers = { const stateHandlers = { 'm.room.aliases': textForRoomAliasesEvent, + 'm.room.canonical_alias': textForCanonicalAliasEvent, 'm.room.name': textForRoomNameEvent, 'm.room.topic': textForTopicEvent, 'm.room.member': textForMemberEvent, diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index bd92d75dd9..58ea42d4ba 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -1,5 +1,6 @@ /* Copyright 2016 OpenMarket Ltd +Copyright 2018 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -97,18 +98,19 @@ module.exports = React.createClass({ } } - - // save new canonical alias let oldCanonicalAlias = null; if (this.props.canonicalAliasEvent) { oldCanonicalAlias = this.props.canonicalAliasEvent.getContent().alias; } - if (oldCanonicalAlias !== this.state.canonicalAlias) { + + let newCanonicalAlias = this.state.canonicalAlias; + + if (this.props.canSetCanonicalAlias && oldCanonicalAlias !== newCanonicalAlias) { console.log("AliasSettings: Updating canonical alias"); promises = [Promise.all(promises).then( MatrixClientPeg.get().sendStateEvent( this.props.roomId, "m.room.canonical_alias", { - alias: this.state.canonicalAlias, + alias: newCanonicalAlias, }, "", ), )]; @@ -161,6 +163,12 @@ module.exports = React.createClass({ description: _t('\'%(alias)s\' is not a valid format for an alias', { alias: alias }), }); } + + if (!this.props.canonicalAlias) { + this.setState({ + canonicalAlias: alias + }); + } }, onLocalAliasChanged: function(alias, index) { @@ -184,10 +192,15 @@ module.exports = React.createClass({ // promptly setState anyway, it's just about acceptable. The alternative // would be to arbitrarily deepcopy to a temp variable and then setState // that, but why bother when we can cut this corner. - this.state.domainToAliases[localDomain].splice(index, 1); + const alias = this.state.domainToAliases[localDomain].splice(index, 1); this.setState({ domainToAliases: this.state.domainToAliases, }); + if (this.props.canonicalAlias === alias) { + this.setState({ + canonicalAlias: null, + }); + } }, onCanonicalAliasChange: function(event) { @@ -205,7 +218,7 @@ module.exports = React.createClass({ let canonical_alias_section; if (this.props.canSetCanonicalAlias) { canonical_alias_section = ( - { Object.keys(self.state.domainToAliases).map(function(domain, i) { diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index dd93171e90..8c58863249 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -49,6 +49,7 @@ const eventTileTypes = { const stateEventTileTypes = { 'm.room.aliases': 'messages.TextualEvent', // 'm.room.aliases': 'messages.RoomAliasesEvent', // too complex + 'm.room.canonical_alias': 'messages.TextualEvent', 'm.room.create': 'messages.RoomCreate', 'm.room.member': 'messages.TextualEvent', 'm.room.name': 'messages.TextualEvent', diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b974e0a96c..88fb201a1d 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1251,6 +1251,8 @@ "%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.|one": "%(senderName)s removed %(removedAddresses)s as an address for this room.", "%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.|other": "%(senderName)s removed %(removedAddresses)s as addresses for this room.", "%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.": "%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.", + "%(senderName)s set the canonical address for this room to %(address)s.": "%(senderName)s set the canonical address for this room to %(address)s.", + "%(senderName)s removed the canonical address for this room.": "%(senderName)s removed the canonical address for this room.", "File to import": "File to import", "Import": "Import", "Failed to set direct chat tag": "Failed to set direct chat tag", From 1aa85c69e46ef877435e137db1e8ee303728f810 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 20 Sep 2018 01:23:29 +0100 Subject: [PATCH 2/3] fix vector-im/riot-web#7293 --- src/components/views/room_settings/AliasSettings.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index 58ea42d4ba..d539f43c8a 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -217,12 +217,14 @@ module.exports = React.createClass({ let canonical_alias_section; if (this.props.canSetCanonicalAlias) { + let found = false; canonical_alias_section = ( ); } else { From e9806bb14760f0c8cd4fd4c4ff8b89cbb5b23bec Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 20 Sep 2018 01:38:25 +0100 Subject: [PATCH 3/3] autocomplete domains on aliases --- src/components/views/room_settings/AliasSettings.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index d539f43c8a..f9bf52cd24 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -147,6 +147,7 @@ module.exports = React.createClass({ if (!alias || alias.length === 0) return; // ignore attempts to create blank aliases const localDomain = MatrixClientPeg.get().getDomain(); + if (!alias.includes(':')) alias += ':' + localDomain; if (this.isAliasValid(alias) && alias.endsWith(localDomain)) { this.state.domainToAliases[localDomain] = this.state.domainToAliases[localDomain] || []; this.state.domainToAliases[localDomain].push(alias); @@ -174,6 +175,7 @@ module.exports = React.createClass({ onLocalAliasChanged: function(alias, index) { if (alias === "") return; // hit the delete button to delete please const localDomain = MatrixClientPeg.get().getDomain(); + if (!alias.includes(':')) alias += ':' + localDomain; if (this.isAliasValid(alias) && alias.endsWith(localDomain)) { this.state.domainToAliases[localDomain][index] = alias; } else {