forked from mystiq/hydrogen-web
Separated the join instructions into a executeJoinCommand method
This commit is contained in:
parent
f9f49b7640
commit
550b9db4dc
1 changed files with 28 additions and 24 deletions
|
@ -198,6 +198,33 @@ export class RoomViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async executeJoinCommand(args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
let roomName = args[0];
|
||||||
|
try {
|
||||||
|
const roomId = await this._options.client.session.joinRoom(roomName);
|
||||||
|
await (await this._options.client.session.observeRoomStatus(roomId)).waitFor(status => status === RoomStatus.Joined);
|
||||||
|
this.navigation.push("room", roomId);
|
||||||
|
} catch (exc) {
|
||||||
|
if ((exc.statusCode ?? exc.status) === 400) {
|
||||||
|
this._sendError = new Error(`/join : '${roomName}' was not legal room ID or room alias`);
|
||||||
|
} else if ((exc.statusCode ?? exc.status) === 404 || (exc.statusCode ?? exc.status) === 502 || exc.message == "Internal Server Error") {
|
||||||
|
this._sendError = new Error(`/join : room '${roomName}' not found`);
|
||||||
|
} else if ((exc.statusCode ?? exc.status) === 403) {
|
||||||
|
this._sendError = new Error(`/join : you're not invited to join '${roomName}'`);
|
||||||
|
} else {
|
||||||
|
this._sendError = exc;
|
||||||
|
}
|
||||||
|
this._timelineError = null;
|
||||||
|
this.emitChange("error");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._sendError = new Error("join syntax: /join <room-id>");
|
||||||
|
this._timelineError = null;
|
||||||
|
this.emitChange("error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _processCommand (message) {
|
async _processCommand (message) {
|
||||||
let msgtype = undefined;
|
let msgtype = undefined;
|
||||||
const [commandName, ...args] = message.substring(1).split(" ");
|
const [commandName, ...args] = message.substring(1).split(" ");
|
||||||
|
@ -207,30 +234,7 @@ export class RoomViewModel extends ViewModel {
|
||||||
msgtype = "m.emote";
|
msgtype = "m.emote";
|
||||||
break;
|
break;
|
||||||
case "join":
|
case "join":
|
||||||
if (args.length == 1) {
|
await this.executeJoinCommand(args);
|
||||||
let roomName = args[0];
|
|
||||||
try {
|
|
||||||
const roomId = await this._options.client.session.joinRoom(roomName);
|
|
||||||
await (await this._options.client.session.observeRoomStatus(roomId)).waitFor(status => status === RoomStatus.Joined);
|
|
||||||
this.navigation.push("room", roomId);
|
|
||||||
} catch (exc) {
|
|
||||||
if ((exc.statusCode ?? exc.status) === 400) {
|
|
||||||
this._sendError = new Error(`/join : '${roomName}' was not legal room ID or room alias`);
|
|
||||||
} else if ((exc.statusCode ?? exc.status) === 404 || (exc.statusCode ?? exc.status) === 502 || exc.message == "Internal Server Error") {
|
|
||||||
this._sendError = new Error(`/join : room '${roomName}' not found`);
|
|
||||||
} else if ((exc.statusCode ?? exc.status) === 403) {
|
|
||||||
this._sendError = new Error(`/join : you're not invited to join '${roomName}'`);
|
|
||||||
} else {
|
|
||||||
this._sendError = exc;
|
|
||||||
}
|
|
||||||
this._timelineError = null;
|
|
||||||
this.emitChange("error");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._sendError = new Error("join syntax: /join <room-id>");
|
|
||||||
this._timelineError = null;
|
|
||||||
this.emitChange("error");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "shrug":
|
case "shrug":
|
||||||
message = "¯\\_(ツ)_/¯ " + args.join(" ");
|
message = "¯\\_(ツ)_/¯ " + args.join(" ");
|
||||||
|
|
Loading…
Reference in a new issue