From f61cfbc54276afc303afd640e9cad7a9261b22df Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 16:41:01 +0100 Subject: [PATCH 1/3] Fix RoomDirectory to join by alias whenever possible. --- src/components/structures/RoomDirectory.js | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index d780823099..c6aca6189f 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -81,20 +81,30 @@ module.exports = React.createClass({ // }); }, - showRoom: function(roomId) { + showRoom: function(roomIdOrAlias) { // extract the metadata from the publicRooms structure to pass // as out-of-band data to view_room, because we get information // here that we can't get other than by joining the room in some // cases. var room; - for (var i = 0; i < this.state.publicRooms.length; ++i) { - if (this.state.publicRooms[i].room_id == roomId) { - room = this.state.publicRooms[i]; - break; + if (roomIdOrAlias[0] == '!') { + for (var i = 0; i < this.state.publicRooms.length; ++i) { + if (this.state.publicRooms[i].room_id == roomIdOrAlias) { + room = this.state.publicRooms[i]; + break; + } } } var oob_data = {}; if (room) { + // pluck the alias out of the room data and use it to join the room, as we cannot + // really join rooms by ID (the HS has no way to get candidate servers). However, + // we still have to do this for room in the public room list that don't have an alias + // since this is currently the only choice. + // (Note we don't just pass the room alias to this function: we still want to be able to + // look up the oob data for which we need the room id). + var alias = room.canonical_alias || (room.aliases ? room.aliases[0] : undefined); + if (alias) roomIdOrAlias = alias; if (MatrixClientPeg.get().isGuest()) { if (!room.world_readable && !room.guest_can_join) { var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog"); @@ -114,9 +124,12 @@ module.exports = React.createClass({ }; } + // XXX: this interface needs to change to officially accept room IDs + // or aliases, rather than it happening to work if you pass an alias + // as room_id dis.dispatch({ action: 'view_room', - room_id: roomId, + room_id: roomIdOrAlias, oob_data: oob_data, }); }, From a030e46c6990754cb2de3240b689dcd7c4bf2602 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 17:13:02 +0100 Subject: [PATCH 2/3] Use join_room_by_alias in RoomDirectory This still doesn't actually cause the room to be joined by alias though, so still need to fix that --- src/components/structures/RoomDirectory.js | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index c6aca6189f..1f1d4a8cb2 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -81,15 +81,15 @@ module.exports = React.createClass({ // }); }, - showRoom: function(roomIdOrAlias) { + showRoom: function(roomId, roomAlias) { // extract the metadata from the publicRooms structure to pass // as out-of-band data to view_room, because we get information // here that we can't get other than by joining the room in some // cases. var room; - if (roomIdOrAlias[0] == '!') { + if (roomId) { for (var i = 0; i < this.state.publicRooms.length; ++i) { - if (this.state.publicRooms[i].room_id == roomIdOrAlias) { + if (this.state.publicRooms[i].room_id == roomId) { room = this.state.publicRooms[i]; break; } @@ -97,14 +97,6 @@ module.exports = React.createClass({ } var oob_data = {}; if (room) { - // pluck the alias out of the room data and use it to join the room, as we cannot - // really join rooms by ID (the HS has no way to get candidate servers). However, - // we still have to do this for room in the public room list that don't have an alias - // since this is currently the only choice. - // (Note we don't just pass the room alias to this function: we still want to be able to - // look up the oob data for which we need the room id). - var alias = room.canonical_alias || (room.aliases ? room.aliases[0] : undefined); - if (alias) roomIdOrAlias = alias; if (MatrixClientPeg.get().isGuest()) { if (!room.world_readable && !room.guest_can_join) { var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog"); @@ -124,14 +116,21 @@ module.exports = React.createClass({ }; } - // XXX: this interface needs to change to officially accept room IDs - // or aliases, rather than it happening to work if you pass an alias - // as room_id - dis.dispatch({ - action: 'view_room', - room_id: roomIdOrAlias, + var payload = { oob_data: oob_data, - }); + }; + if (roomAlias) { + payload.action = 'view_room_alias'; + payload.room_alias = roomAlias; + } else { + // It's not really possible to join Matrix rooms by ID because the HS has no way to know + // which servers to start querying. However, there's no other way to join rooms in + // this list without aliases at present. + payload.action = 'view_room'; + payload.room_id = roomId; + } + + dis.dispatch(payload); }, getRows: function(filter) { @@ -177,7 +176,7 @@ module.exports = React.createClass({ topic = linkifyString(sanitizeHtml(topic)); rows.unshift( - + Date: Fri, 10 Jun 2016 15:13:41 +0100 Subject: [PATCH 3/3] Switch to new view_room --- src/components/structures/RoomDirectory.js | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 1f1d4a8cb2..2a37616b6a 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -116,21 +116,16 @@ module.exports = React.createClass({ }; } - var payload = { + // It's not really possible to join Matrix rooms by ID because the HS has no way to know + // which servers to start querying. However, there's no other way to join rooms in + // this list without aliases at present, so if roomAlias isn't set here we'll rely + // on view_room falling back to using the ID + dis.dispatch({ oob_data: oob_data, - }; - if (roomAlias) { - payload.action = 'view_room_alias'; - payload.room_alias = roomAlias; - } else { - // It's not really possible to join Matrix rooms by ID because the HS has no way to know - // which servers to start querying. However, there's no other way to join rooms in - // this list without aliases at present. - payload.action = 'view_room'; - payload.room_id = roomId; - } - - dis.dispatch(payload); + action: 'view_room', + room_id: roomId, + room_alias: roomAlias, + }); }, getRows: function(filter) {