From ab64ce02b22d8002ee4874751ecdec9fb2c8424d Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Wed, 27 Jul 2022 15:18:32 +0200 Subject: [PATCH] Separated the _processCommand and the joinRoom command - renamed executeJoinCommand as joinRoom; - separated the joinRoom process and the parse and result process --- src/domain/session/room/RoomViewModel.js | 57 ++++++++++++++---------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 82fcc785..b66545c6 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -198,30 +198,23 @@ 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"); + async joinRoom(roomName) { + try { + const roomId = await this._options.client.session.joinRoom(roomName); + const roomStatusObserver = await this._options.client.session.observeRoomStatus(roomId); + await roomStatusObserver.waitFor(status => status === RoomStatus.Joined); + this.navigation.push("room", roomId); + return true; + } catch (exc) { + if ((exc.statusCode ?? exc.status) === 400) { + return `'${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") { + return `room '${roomName}' not found`; + } else if ((exc.statusCode ?? exc.status) === 403) { + return `you're not invited to join '${roomName}'`; + } else { + return exc; } - } else { - this._sendError = new Error("join syntax: /join "); - this._timelineError = null; - this.emitChange("error"); } } @@ -234,7 +227,23 @@ export class RoomViewModel extends ViewModel { msgtype = "m.emote"; break; case "join": - await this.executeJoinCommand(args); + if (args.length == 1) { + const roomName = args[0]; + const exc = await this.joinRoom(roomName); + if (exc!==true) { + if (exc && exc.stack && exc.message) { + this._sendError = exc; + } else { + this._sendError = new Error("/join : " + exc); + } + this._timelineError = null; + this.emitChange("error"); + } + } else { + this._sendError = new Error("join syntax: /join "); + this._timelineError = null; + this.emitChange("error"); + } break; case "shrug": message = "¯\\_(ツ)_/¯ " + args.join(" ");