Merge pull request #1615 from vector-im/dbkr/directory_join_by_alias

Fix RoomDirectory to join by alias whenever possible.
pull/1639/head
Richard van der Hoff 2016-06-10 15:23:07 +01:00 committed by GitHub
commit a5986ade51
1 changed files with 15 additions and 8 deletions

View File

@ -81,18 +81,20 @@ module.exports = React.createClass({
// }); // });
}, },
showRoom: function(roomId) { showRoom: function(roomId, roomAlias) {
// extract the metadata from the publicRooms structure to pass // extract the metadata from the publicRooms structure to pass
// as out-of-band data to view_room, because we get information // 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 // here that we can't get other than by joining the room in some
// cases. // cases.
var room; var room;
if (roomId) {
for (var i = 0; i < this.state.publicRooms.length; ++i) { for (var i = 0; i < this.state.publicRooms.length; ++i) {
if (this.state.publicRooms[i].room_id == roomId) { if (this.state.publicRooms[i].room_id == roomId) {
room = this.state.publicRooms[i]; room = this.state.publicRooms[i];
break; break;
} }
} }
}
var oob_data = {}; var oob_data = {};
if (room) { if (room) {
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
@ -114,10 +116,15 @@ module.exports = React.createClass({
}; };
} }
// 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({ dis.dispatch({
oob_data: oob_data,
action: 'view_room', action: 'view_room',
room_id: roomId, room_id: roomId,
oob_data: oob_data, room_alias: roomAlias,
}); });
}, },
@ -164,7 +171,7 @@ module.exports = React.createClass({
topic = linkifyString(sanitizeHtml(topic)); topic = linkifyString(sanitizeHtml(topic));
rows.unshift( rows.unshift(
<tr key={ rooms[i].room_id } onClick={self.showRoom.bind(null, rooms[i].room_id)}> <tr key={ rooms[i].room_id } onClick={self.showRoom.bind(null, rooms[i].room_id, alias)}>
<td className="mx_RoomDirectory_roomAvatar"> <td className="mx_RoomDirectory_roomAvatar">
<BaseAvatar width={24} height={24} resizeMethod='crop' <BaseAvatar width={24} height={24} resizeMethod='crop'
name={ name } idName={ name } name={ name } idName={ name }
@ -193,7 +200,7 @@ module.exports = React.createClass({
this.forceUpdate(); this.forceUpdate();
this.setState({ roomAlias : this.refs.roomAlias.value }) this.setState({ roomAlias : this.refs.roomAlias.value })
if (ev.key == "Enter") { if (ev.key == "Enter") {
this.showRoom(this.refs.roomAlias.value); this.showRoom(null, this.refs.roomAlias.value);
} }
}, },