Fix /join to be consistent with the other code
Plus a number of other tidyups: * Fix /join to dispatch a view_room for the room alias with the additional auto_join parameter * Make RoomView automatically join the room if the auto_join parameter is true and the user isn't already in it * Tidy up RoomView's peeking code, also fixing https://github.com/vector-im/vector-web/issues/1220 in react-sdk (although it still requires a synapse change to actually fix, but react-sdk does 'the right thing'). * Remove duplication of usage text from /join command * Amalgamate MatrixChat::_viewRoom's many, many parameters into an object and sort out case consistency a little.
This commit is contained in:
parent
8103a795ec
commit
d8dedae084
3 changed files with 73 additions and 79 deletions
|
@ -132,46 +132,25 @@ var commands = {
|
|||
}),
|
||||
|
||||
// Join a room
|
||||
join: new Command("join", "<room_alias>", function(room_id, args) {
|
||||
join: new Command("join", "#alias:domain", function(room_id, args) {
|
||||
if (args) {
|
||||
var matches = args.match(/^(\S+)$/);
|
||||
if (matches) {
|
||||
var room_alias = matches[1];
|
||||
if (room_alias[0] !== '#') {
|
||||
return reject("Usage: /join #alias:domain");
|
||||
return reject(this.getUsage());
|
||||
}
|
||||
if (!room_alias.match(/:/)) {
|
||||
room_alias += ':' + MatrixClientPeg.get().getDomain();
|
||||
}
|
||||
|
||||
// Try to find a room with this alias
|
||||
// XXX: do we need to do this? Doesn't the JS SDK suppress duplicate attempts to join the same room?
|
||||
var foundRoom = MatrixTools.getRoomForAlias(
|
||||
MatrixClientPeg.get().getRooms(),
|
||||
room_alias
|
||||
);
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_alias: room_alias,
|
||||
auto_join: true,
|
||||
});
|
||||
|
||||
if (foundRoom) { // we've already joined this room, view it if it's not archived.
|
||||
var me = foundRoom.getMember(MatrixClientPeg.get().credentials.userId);
|
||||
if (me && me.membership !== "leave") {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: foundRoom.roomId
|
||||
});
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise attempt to join this alias.
|
||||
return success(
|
||||
MatrixClientPeg.get().joinRoom(room_alias).then(
|
||||
function(room) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: room.roomId
|
||||
});
|
||||
})
|
||||
);
|
||||
return success();
|
||||
}
|
||||
}
|
||||
return reject(this.getUsage());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue