From fb58d9c9efd9a3efa70dd2ddfa988daffd078036 Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Fri, 22 Jul 2022 16:08:53 +0200 Subject: [PATCH] Corrected some syntax dismiss --- src/domain/session/room/RoomViewModel.js | 51 ++++++++++++------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index dfda5767..5ded5108 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -200,71 +200,72 @@ export class RoomViewModel extends ViewModel { async _getMessageInformations (message) { let msgtype = "m.text"; if (message.startsWith("/")) { - let command=message.substring(1).split(" "); - switch (command[0]) { + const [commandName, ...args] = message.substring(1).split(" "); + switch (commandName) { case "me": message = message.substring(4).trim(); msgtype = "m.emote"; break; case "join": - if (command.length==2) { - let roomname = message.substring(5).trim(); + if (args.length == 1) { + let roomName = args[0]; try { - await this._options.client.session.joinRoom(roomname); + await this._options.client.session.joinRoom(roomName); + const internalId = await this._options.client.session.joinRoom(roomName); + this.navigation.push("room", internalId); } 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==502) || (exc.message="Internal Server Error")) { - this._sendError=new Error("/join : room not found"); + 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 { - this._sendError=new Error("join syntax: /join "); + this._sendError = new Error("join syntax: /join "); } this._timelineError = null; this.emitChange("error"); } } else { - this._sendError=new Error("join syntax: /join "); + this._sendError = new Error("join syntax: /join "); this._timelineError = null; this.emitChange("error"); } - msgtype=undefined; - message=undefined; + msgtype = undefined; + message = undefined; break; case "shrug": - message="¯\\_(ツ)_/¯ "+message.substring(7); + message = "¯\\_(ツ)_/¯ " + message.substring(7); break; case "tableflip": - message="(╯°□°)╯︵ ┻━┻ "+message.substring(11); + message="(╯°□°)╯︵ ┻━┻ " + message.substring(11); break; case "unflip": - message="┬──┬ ノ( ゜-゜ノ) "+message.substring(8); + message="┬──┬ ノ( ゜-゜ノ) " + message.substring(8); break; case "lenny": - message="( ͡° ͜ʖ ͡°) "+message.substring(7); + message="( ͡° ͜ʖ ͡°) " + message.substring(7); break; default: - if (command[0][0]=="/") { + if (commandName[0] == "/") { message = message.substring(1).trim(); break; } else { - this._sendError=new Error("no command name '"+command[0]+"'"); + this._sendError = new Error(`no command name "${commandName}". To send the message instead of executing, please type "/${message}"`); this._timelineError = null; this.emitChange("error"); - msgtype=undefined; - message=undefined; + msgtype = undefined; + message = undefined; } } } - return [msgtype, message]; + return {type: msgtype, message: message}; } async _sendMessage(message, replyingTo) { if (!this._room.isArchived && message) { let messinfo = await this._getMessageInformations(message); try { - let msgtype = messinfo[0]; - let message = messinfo[1]; - console.log("messinfo :",messinfo); + let msgtype = messinfo.type; + let message = messinfo.message; if (msgtype && message) { if (replyingTo) { await replyingTo.reply(msgtype, message);