Make the room directory join rooms by alias

Also makes some improvement on the multiple code path mess for joining rooms
pull/21833/head
David Baker 2016-06-09 18:49:06 +01:00
parent 049e3a968b
commit 72b3ce200d
2 changed files with 30 additions and 39 deletions

View File

@ -424,40 +424,10 @@ module.exports = React.createClass({
} }
break; break;
case 'view_room_alias': case 'view_room_alias':
if (!this.state.logged_in) { this._viewRoom(
this.starting_room_alias_payload = payload; undefined, payload.room_alias, undefined, payload.event_id,
// Login is the default screen, so we'd do this anyway, payload.third_party_invite, payload.oob_data
// but this will set the URL bar appropriately.
dis.dispatch({ action: 'start_login' });
return;
}
var foundRoom = MatrixTools.getRoomForAlias(
MatrixClientPeg.get().getRooms(), payload.room_alias
); );
if (foundRoom) {
dis.dispatch({
action: 'view_room',
room_id: foundRoom.roomId,
room_alias: payload.room_alias,
event_id: payload.event_id,
third_party_invite: payload.third_party_invite,
oob_data: payload.oob_data,
});
return;
}
// resolve the alias and *then* view it
MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias).done(
function(result) {
dis.dispatch({
action: 'view_room',
room_id: result.room_id,
room_alias: payload.room_alias,
event_id: payload.event_id,
third_party_invite: payload.third_party_invite,
oob_data: payload.oob_data,
});
});
break; break;
case 'view_user_settings': case 'view_user_settings':
this._setPage(this.PageTypes.UserSettings); this._setPage(this.PageTypes.UserSettings);
@ -818,22 +788,35 @@ module.exports = React.createClass({
inviterName: params.inviter_name, inviterName: params.inviter_name,
}; };
var payload;
if (roomString[0] == '#') { if (roomString[0] == '#') {
dis.dispatch({ payload = {
action: 'view_room_alias', action: 'view_room_alias',
room_alias: roomString, room_alias: roomString,
event_id: eventId, event_id: eventId,
third_party_invite: third_party_invite, third_party_invite: third_party_invite,
oob_data: oob_data, oob_data: oob_data,
}); };
} else { } else {
dis.dispatch({ payload = {
action: 'view_room', action: 'view_room',
room_id: roomString, room_id: roomString,
event_id: eventId, event_id: eventId,
third_party_invite: third_party_invite, third_party_invite: third_party_invite,
oob_data: oob_data, oob_data: oob_data,
}); };
}
// we can't view a room unless we're logged in
// (a guest account is fine)
if (!this.state.logged_in) {
this.starting_room_alias_payload = payload;
// Login is the default screen, so we'd do this anyway,
// but this will set the URL bar appropriately.
dis.dispatch({ action: 'start_login' });
return;
} else {
dis.dispatch(payload);
} }
} }
else { else {
@ -1044,7 +1027,7 @@ module.exports = React.createClass({
oobData={this.state.roomOobData} oobData={this.state.roomOobData}
highlightedEventId={this.state.highlightedEventId} highlightedEventId={this.state.highlightedEventId}
eventPixelOffset={this.state.initialEventPixelOffset} eventPixelOffset={this.state.initialEventPixelOffset}
key={this.state.currentRoom} key={this.state.currentRoom || this.state.currentRoomAlias}
opacity={this.state.middleOpacity} opacity={this.state.middleOpacity}
ConferenceHandler={this.props.ConferenceHandler} /> ConferenceHandler={this.props.ConferenceHandler} />
); );

View File

@ -39,6 +39,7 @@ var dis = require("../../dispatcher");
var Tinter = require("../../Tinter"); var Tinter = require("../../Tinter");
var rate_limited_func = require('../../ratelimitedfunc'); var rate_limited_func = require('../../ratelimitedfunc');
var ObjectUtils = require('../../ObjectUtils'); var ObjectUtils = require('../../ObjectUtils');
var MatrixTools = require('../../MatrixTools');
var DEBUG = false; var DEBUG = false;
@ -100,7 +101,14 @@ module.exports = React.createClass({
}, },
getInitialState: function() { getInitialState: function() {
var room = MatrixClientPeg.get().getRoom(this.props.roomAddress); var room;
if (this.props.roomAddress[0] == '!') {
room = MatrixClientPeg.get().getRoom(this.props.roomAddress);
} else {
room = MatrixTools.getRoomForAlias(
MatrixClientPeg.get().getRooms(), this.props.roomAddress
);
}
return { return {
room: room, room: room,
roomLoading: !room, roomLoading: !room,