mirror of https://github.com/vector-im/riot-web
Fix peeking
Sorts out more of the room joining mess. currentRoom which held the room ID is now more appropriately called currentRoomId. RoomView will now take a roomID or alias as before but will now look up the room ID as required if given the alias. Also, now look up the alias every time you click on it so it's never stale, rather than looking in your current rooms for a room that thinks it has that ID.pull/21833/head
parent
469c415557
commit
11a38fce48
|
@ -409,7 +409,7 @@ module.exports = React.createClass({
|
|||
);
|
||||
var roomIndex = -1;
|
||||
for (var i = 0; i < allRooms.length; ++i) {
|
||||
if (allRooms[i].roomId == this.state.currentRoom) {
|
||||
if (allRooms[i].roomId == this.state.currentRoomId) {
|
||||
roomIndex = i;
|
||||
break;
|
||||
}
|
||||
|
@ -506,20 +506,10 @@ module.exports = React.createClass({
|
|||
page_type: this.PageTypes.RoomView,
|
||||
thirdPartyInvite: thirdPartyInvite,
|
||||
roomOobData: oob_data,
|
||||
newState.currentRoomAlias: roomAlias,
|
||||
newState.currentRoomId: roomId,
|
||||
};
|
||||
|
||||
// If an alias has been provided, we use that and only that,
|
||||
// since otherwise we'll prefer to pass in an ID to RoomView
|
||||
// but if we're not in the room, we should join by alias rather
|
||||
// than ID.
|
||||
if (roomAlias) {
|
||||
newState.currentRoomAlias = roomAlias;
|
||||
newState.currentRoom = null;
|
||||
} else {
|
||||
newState.currentRoomAlias = null;
|
||||
newState.currentRoom = roomId;
|
||||
}
|
||||
|
||||
// if we aren't given an explicit event id, look for one in the
|
||||
// scrollStateMap.
|
||||
if (!eventId) {
|
||||
|
@ -612,13 +602,13 @@ module.exports = React.createClass({
|
|||
dis.dispatch(self.starting_room_alias_payload);
|
||||
delete self.starting_room_alias_payload;
|
||||
} else if (!self.state.page_type) {
|
||||
if (!self.state.currentRoom) {
|
||||
if (!self.state.currentRoomId) {
|
||||
var firstRoom = null;
|
||||
if (cli.getRooms() && cli.getRooms().length) {
|
||||
firstRoom = RoomListSorter.mostRecentActivityFirst(
|
||||
cli.getRooms()
|
||||
)[0].roomId;
|
||||
self.setState({ready: true, currentRoom: firstRoom, page_type: self.PageTypes.RoomView});
|
||||
self.setState({ready: true, currentRoomId: firstRoom, page_type: self.PageTypes.RoomView});
|
||||
} else {
|
||||
self.setState({ready: true, page_type: self.PageTypes.RoomDirectory});
|
||||
}
|
||||
|
@ -628,8 +618,8 @@ module.exports = React.createClass({
|
|||
|
||||
// we notifyNewScreen now because now the room will actually be displayed,
|
||||
// and (mostly) now we can get the correct alias.
|
||||
var presentedId = self.state.currentRoom;
|
||||
var room = MatrixClientPeg.get().getRoom(self.state.currentRoom);
|
||||
var presentedId = self.state.currentRoomId;
|
||||
var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId);
|
||||
if (room) {
|
||||
var theAlias = MatrixTools.getCanonicalAliasForRoom(room);
|
||||
if (theAlias) presentedId = theAlias;
|
||||
|
@ -979,10 +969,10 @@ module.exports = React.createClass({
|
|||
onUserSettingsClose: function() {
|
||||
// XXX: use browser history instead to find the previous room?
|
||||
// or maintain a this.state.pageHistory in _setPage()?
|
||||
if (this.state.currentRoom) {
|
||||
if (this.state.currentRoomId) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: this.state.currentRoom,
|
||||
room_id: this.state.currentRoomId,
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -1022,17 +1012,18 @@ module.exports = React.createClass({
|
|||
page_element = (
|
||||
<RoomView
|
||||
ref="roomView"
|
||||
roomAddress={this.state.currentRoom || this.state.currentRoomAlias}
|
||||
roomId={this.state.currentRoomId}
|
||||
roomAlias={this.state.currentRoomAlias}
|
||||
eventId={this.state.initialEventId}
|
||||
thirdPartyInvite={this.state.thirdPartyInvite}
|
||||
oobData={this.state.roomOobData}
|
||||
highlightedEventId={this.state.highlightedEventId}
|
||||
eventPixelOffset={this.state.initialEventPixelOffset}
|
||||
key={this.state.currentRoom || this.state.currentRoomAlias}
|
||||
key={this.state.currentRoomId || this.state.currentRoomAlias}
|
||||
opacity={this.state.middleOpacity}
|
||||
ConferenceHandler={this.props.ConferenceHandler} />
|
||||
);
|
||||
right_panel = <RightPanel roomId={this.state.currentRoom} collapsed={this.state.collapse_rhs} opacity={this.state.sideOpacity} />
|
||||
right_panel = <RightPanel roomId={this.state.currentRoomId} collapsed={this.state.collapse_rhs} opacity={this.state.sideOpacity} />
|
||||
break;
|
||||
case this.PageTypes.UserSettings:
|
||||
page_element = <UserSettings onClose={this.onUserSettingsClose} version={this.state.version} brand={this.props.config.brand} />
|
||||
|
@ -1068,7 +1059,7 @@ module.exports = React.createClass({
|
|||
<div className="mx_MatrixChat_wrapper">
|
||||
{topBar}
|
||||
<div className={bodyClasses}>
|
||||
<LeftPanel selectedRoom={this.state.currentRoom} collapsed={this.state.collapse_lhs} opacity={this.state.sideOpacity}/>
|
||||
<LeftPanel selectedRoom={this.state.currentRoomId} collapsed={this.state.collapse_lhs} opacity={this.state.sideOpacity}/>
|
||||
<main className="mx_MatrixChat_middlePanel">
|
||||
{page_element}
|
||||
</main>
|
||||
|
|
|
@ -55,7 +55,10 @@ module.exports = React.createClass({
|
|||
propTypes: {
|
||||
ConferenceHandler: React.PropTypes.any,
|
||||
|
||||
// the ID for this room (or, if we don't know it, an alias for it)
|
||||
// Either a room ID or room alias for the room to display.
|
||||
// If the room is being displayed as a result of the user clicking
|
||||
// on a room alias, the alias should be supplied. Otherwise, a room
|
||||
// ID should be supplied.
|
||||
roomAddress: React.PropTypes.string.isRequired,
|
||||
|
||||
// An object representing a third party invite to join this room
|
||||
|
@ -95,15 +98,14 @@ module.exports = React.createClass({
|
|||
|
||||
getInitialState: function() {
|
||||
var room;
|
||||
var room_id;
|
||||
if (this.props.roomAddress[0] == '!') {
|
||||
room = MatrixClientPeg.get().getRoom(this.props.roomAddress);
|
||||
} else {
|
||||
room = MatrixTools.getRoomForAlias(
|
||||
MatrixClientPeg.get().getRooms(), this.props.roomAddress
|
||||
);
|
||||
room_id = this.props.roomAddress;
|
||||
room = MatrixClientPeg.get().getRoom(room_id);
|
||||
}
|
||||
return {
|
||||
room: room,
|
||||
roomId: room_id,
|
||||
roomLoading: !room,
|
||||
editingRoomSettings: false,
|
||||
uploadingRoomSettings: false,
|
||||
|
@ -143,6 +145,27 @@ module.exports = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
if (this.props.roomAddress[0] == '#') {
|
||||
// we always look up the alias from the directory server:
|
||||
// we want the room that the given alias is pointing to
|
||||
// right now. We may have joined that alias before but there's
|
||||
// no guarantee the alias hasn't subsequently been remapped.
|
||||
MatrixClientPeg.get().getRoomIdForAlias(this.props.roomAddress).done((result) => {
|
||||
this.setState({
|
||||
roomId: result.room_id,
|
||||
roomLoading: false,
|
||||
}, this.updatePeeking);
|
||||
}, (err) => {
|
||||
this.setState({
|
||||
roomLoading: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.updatePeeking();
|
||||
},
|
||||
|
||||
updatePeeking: function() {
|
||||
// if this is an unknown room then we're in one of three states:
|
||||
// - This is a room we can peek into (search engine) (we can /peek)
|
||||
// - This is a room we can publicly join or were invited to. (we can /join)
|
||||
|
@ -150,10 +173,13 @@ module.exports = React.createClass({
|
|||
// We can't try to /join because this may implicitly accept invites (!)
|
||||
// We can /peek though. If it fails then we present the join UI. If it
|
||||
// succeeds then great, show the preview (but we still may be able to /join!).
|
||||
if (!this.state.room) {
|
||||
console.log("Attempting to peek into room %s", this.props.roomAddress);
|
||||
// Note that peeking works by room ID and room ID only, as opposed to joining
|
||||
// which must be by alias or invite wherever possible (peeking currently does
|
||||
// not work over federation).
|
||||
if (!this.state.room && this.state.roomId) {
|
||||
console.log("Attempting to peek into room %s", this.state.roomId);
|
||||
|
||||
MatrixClientPeg.get().peekInRoom(this.props.roomAddress).then((room) => {
|
||||
MatrixClientPeg.get().peekInRoom(this.state.roomId).then((room) => {
|
||||
this.setState({
|
||||
room: room,
|
||||
roomLoading: false,
|
||||
|
@ -172,7 +198,7 @@ module.exports = React.createClass({
|
|||
throw err;
|
||||
}
|
||||
}).done();
|
||||
} else {
|
||||
} else if (this.state.room) {
|
||||
MatrixClientPeg.get().stopPeeking();
|
||||
this._onRoomLoaded(this.state.room);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue