Skip to content

Commit cbb72c2

Browse files
authored
Merge pull request element-hq#1685 from vector-im/dbkr/fix_room_directory
Fix joining rooms by typing the alias
2 parents c12839d + 5f477b3 commit cbb72c2

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

src/components/structures/RoomDirectory.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,38 +126,47 @@ module.exports = React.createClass({
126126
});
127127
},
128128

129-
showRoom: function(room, ev) {
129+
onRoomClicked: function(room, ev) {
130130
if (ev.shiftKey) {
131131
ev.preventDefault();
132132
this.removeFromDirectory(room);
133-
return;
133+
} else {
134+
this.showRoom(room);
134135
}
136+
},
135137

136-
var oob_data = {};
137-
if (MatrixClientPeg.get().isGuest()) {
138-
if (!room.world_readable && !room.guest_can_join) {
139-
var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog");
140-
Modal.createDialog(NeedToRegisterDialog, {
141-
title: "Failed to join the room",
142-
description: "This room is inaccessible to guests. You may be able to join if you register."
143-
});
144-
return;
145-
}
146-
}
138+
showRoomAlias: function(alias) {
139+
this.showRoom(null, alias);
140+
},
147141

148-
var room_alias = get_display_alias_for_room(room);
142+
showRoom: function(room, room_alias) {
143+
var payload = {action: 'view_room'};
144+
if (room) {
145+
// Don't let the user view a room they won't be able to either
146+
// peek or join: fail earlier so they don't have to click back
147+
// to the directory.
148+
if (MatrixClientPeg.get().isGuest()) {
149+
if (!room.world_readable && !room.guest_can_join) {
150+
var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog");
151+
Modal.createDialog(NeedToRegisterDialog, {
152+
title: "Failed to join the room",
153+
description: "This room is inaccessible to guests. You may be able to join if you register."
154+
});
155+
return;
156+
}
157+
}
149158

150-
oob_data = {
151-
avatarUrl: room.avatar_url,
152-
// XXX: This logic is duplicated from the JS SDK which
153-
// would normally decide what the name is.
154-
name: room.name || room_alias || "Unnamed room",
155-
};
159+
if (!room_alias) {
160+
room_alias = get_display_alias_for_room(room);
161+
}
156162

157-
var payload = {
158-
oob_data: oob_data,
159-
action: 'view_room',
160-
};
163+
payload.oob_data = {
164+
avatarUrl: room.avatar_url,
165+
// XXX: This logic is duplicated from the JS SDK which
166+
// would normally decide what the name is.
167+
name: room.name || room_alias || "Unnamed room",
168+
};
169+
}
161170
// It's not really possible to join Matrix rooms by ID because the HS has no way to know
162171
// which servers to start querying. However, there's no other way to join rooms in
163172
// this list without aliases at present, so if roomAlias isn't set here we have no
@@ -213,7 +222,7 @@ module.exports = React.createClass({
213222

214223
rows.unshift(
215224
<tr key={ rooms[i].room_id }
216-
onClick={self.showRoom.bind(null, rooms[i])}
225+
onClick={self.onRoomClicked.bind(self, rooms[i])}
217226
// cancel onMouseDown otherwise shift-clicking highlights text
218227
onMouseDown={(ev) => {ev.preventDefault();}}
219228
>
@@ -245,7 +254,7 @@ module.exports = React.createClass({
245254
this.forceUpdate();
246255
this.setState({ roomAlias : this.refs.roomAlias.value })
247256
if (ev.key == "Enter") {
248-
this.showRoom(null, this.refs.roomAlias.value);
257+
this.showRoomAlias(this.refs.roomAlias.value);
249258
}
250259
},
251260

0 commit comments

Comments
 (0)