Implement /join

This commit is contained in:
Kegan Dougal 2015-07-17 11:48:40 +01:00
parent 001372ec39
commit 2bb2295499
2 changed files with 45 additions and 11 deletions

View File

@ -61,15 +61,48 @@ var commands = {
var matches = args.match(/^(\S+)$/); var matches = args.match(/^(\S+)$/);
if (matches) { if (matches) {
var room_alias = matches[1]; var room_alias = matches[1];
// TODO: // Try to find a room with this alias
// Map alias to room ID var rooms = MatrixClientPeg.get().getRooms();
// Find the room (if joined, then just view the room) var roomId;
// else join the room alias for (var i = 0; i < rooms.length; i++) {
/* var aliasEvents = rooms[i].currentState.getStateEvents(
dis.dispatch({ "m.room.aliases"
action: 'view_room', );
room_id: roomId for (var j = 0; j < aliasEvents.length; j++) {
}); */ var aliases = aliasEvents[j].getContent().aliases || [];
for (var k = 0; k < aliases.length; k++) {
if (aliases[k] === room_alias) {
roomId = rooms[i].roomId;
break;
}
}
if (roomId) { break; }
}
if (roomId) { break; }
}
if (roomId) { // we've already joined this room, view it.
dis.dispatch({
action: 'view_room',
room_id: roomId
});
return success();
}
else {
// attempt to join this alias.
return success(
MatrixClientPeg.get().joinRoom(room_alias).done(
function(room) {
dis.dispatch({
action: 'view_room',
room_id: room.roomId
});
}, function(err) {
console.error(
"Failed to join room: %s", JSON.stringify(err)
);
})
);
}
} }
} }
return reject("Usage: /join <room_alias> [NOT IMPLEMENTED]"); return reject("Usage: /join <room_alias> [NOT IMPLEMENTED]");

View File

@ -176,18 +176,19 @@ module.exports = {
var cmd = SlashCommands.processInput(this.props.room.roomId, contentText); var cmd = SlashCommands.processInput(this.props.room.roomId, contentText);
if (cmd) { if (cmd) {
ev.preventDefault(); ev.preventDefault();
if (!cmd.error) {
this.refs.textarea.getDOMNode().value = '';
}
if (cmd.promise) { if (cmd.promise) {
cmd.promise.done(function() { cmd.promise.done(function() {
console.log("Command success."); console.log("Command success.");
}, function(err) { }, function(err) {
console.error("Command failure: %s", err); console.error("Command failure: %s", err);
}); });
this.refs.textarea.getDOMNode().value = '';
} }
else if (cmd.error) { else if (cmd.error) {
console.error(cmd.error); console.error(cmd.error);
} }
return; return;
} }