diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index ee5a505b32..e441ebfb8a 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -74,7 +74,6 @@ export default class AliasSettings extends React.Component { roomId: PropTypes.string.isRequired, canSetCanonicalAlias: PropTypes.bool.isRequired, canSetAliases: PropTypes.bool.isRequired, - aliasEvents: PropTypes.array, // [MatrixEvent] canonicalAliasEvent: PropTypes.object, // MatrixEvent }; @@ -94,27 +93,49 @@ export default class AliasSettings extends React.Component { updatingCanonicalAlias: false, }; - const localDomain = MatrixClientPeg.get().getDomain(); - state.domainToAliases = this.aliasEventsToDictionary(props.aliasEvents || []); - state.remoteDomains = Object.keys(state.domainToAliases).filter((domain) => { - return domain !== localDomain && state.domainToAliases[domain].length > 0; - }); - if (props.canonicalAliasEvent) { + const cli = MatrixClientPeg.get(); + const localDomain = cli.getDomain(); + state.domainToAliases = this.aliasesToDictionary(this._getAltAliases()); + state.remoteDomains = Object.keys(state.domainToAliases).filter((domain) => { + return domain !== localDomain && state.domainToAliases[domain].length > 0; + }); state.canonicalAlias = props.canonicalAliasEvent.getContent().alias; } this.state = state; } - aliasEventsToDictionary(aliasEvents) { // m.room.alias events - const dict = {}; - aliasEvents.forEach((event) => { - dict[event.getStateKey()] = ( - (event.getContent().aliases || []).slice() // shallow-copy - ); - }); - return dict; + async componentWillMount() { + const cli = MatrixClientPeg.get(); + const response = await cli.getLocalAliases(this.props.roomId); + const localAliases = response.aliases; + const localDomain = cli.getDomain(); + const domainToAliases = Object.assign( + {}, + this.state.domainToAliases, + {[localDomain]: localAliases || []}, + ); + this.setState({ domainToAliases }); + } + + aliasesToDictionary(aliases) { + return aliases.reduce((dict, alias) => { + const domain = alias.split(":")[1]; + dict[domain] = dict[domain] || []; + dict[domain].push(alias); + return dict; + }, {}); + } + + _getAltAliases() { + if (this.props.canonicalAliasEvent) { + const altAliases = this.props.canonicalAliasEvent.getContent().alt_aliases; + if (Array.isArray(altAliases)) { + return altAliases; + } + } + return []; } changeCanonicalAlias(alias) { @@ -125,7 +146,9 @@ export default class AliasSettings extends React.Component { updatingCanonicalAlias: true, }); - const eventContent = {}; + const eventContent = { + alt_aliases: this._getAltAliases(), + }; if (alias) eventContent["alias"] = alias; MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias", diff --git a/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.js b/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.js index b65f8d49a4..098c07b825 100644 --- a/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.js +++ b/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.js @@ -78,7 +78,6 @@ export default class GeneralRoomSettingsTab extends React.Component { const canActuallySetAliases = room.currentState.mayClientSendStateEvent("m.room.aliases", client); const canSetCanonical = room.currentState.mayClientSendStateEvent("m.room.canonical_alias", client); const canonicalAliasEv = room.currentState.getStateEvents("m.room.canonical_alias", ''); - const aliasEvents = room.currentState.getStateEvents("m.room.aliases"); const canChangeGroups = room.currentState.mayClientSendStateEvent("m.room.related_groups", client); const groupsEvent = room.currentState.getStateEvents("m.room.related_groups", ""); @@ -94,7 +93,7 @@ export default class GeneralRoomSettingsTab extends React.Component {
+ canonicalAliasEvent={canonicalAliasEv} />