Skip to content

Commit d45e44d

Browse files
committed
Fix joining rooms by typing the alias
Fixes regression introduced by element-hq#1680
1 parent c12839d commit d45e44d

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

src/components/structures/RoomDirectory.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,38 +126,48 @@ 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

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

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-
};
160+
if (!room_alias) {
161+
room_alias = get_display_alias_for_room(room);
162+
}
156163

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

214224
rows.unshift(
215225
<tr key={ rooms[i].room_id }
216-
onClick={self.showRoom.bind(null, rooms[i])}
226+
onClick={self.onRoomClicked.bind(self, rooms[i])}
217227
// cancel onMouseDown otherwise shift-clicking highlights text
218228
onMouseDown={(ev) => {ev.preventDefault();}}
219229
>
@@ -245,7 +255,7 @@ module.exports = React.createClass({
245255
this.forceUpdate();
246256
this.setState({ roomAlias : this.refs.roomAlias.value })
247257
if (ev.key == "Enter") {
248-
this.showRoom(null, this.refs.roomAlias.value);
258+
this.showRoomAlias(this.refs.roomAlias.value);
249259
}
250260
},
251261

0 commit comments

Comments
 (0)