From faa8cae532ee9899542808e667ee533a078cb270 Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Thu, 21 Jul 2022 13:55:23 +0200 Subject: [PATCH] Added the possibility to join a room using /join (also added the global commands uses, and some others commands like /shrug .) --- src/domain/session/room/RoomViewModel.js | 80 ++++++++++++++++--- .../web/ui/css/themes/element/theme.css | 12 +++ 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 94c78286..dfda5767 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -197,18 +197,80 @@ export class RoomViewModel extends ViewModel { } } + async _getMessageInformations (message) { + let msgtype = "m.text"; + if (message.startsWith("/")) { + let command=message.substring(1).split(" "); + switch (command[0]) { + case "me": + message = message.substring(4).trim(); + msgtype = "m.emote"; + break; + case "join": + if (command.length==2) { + let roomname = message.substring(5).trim(); + try { + await this._options.client.session.joinRoom(roomname); + } 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"); + } else { + this._sendError=new Error("join syntax: /join "); + } + this._timelineError = null; + this.emitChange("error"); + } + } else { + this._sendError=new Error("join syntax: /join "); + this._timelineError = null; + this.emitChange("error"); + } + msgtype=undefined; + message=undefined; + break; + case "shrug": + message="¯\\_(ツ)_/¯ "+message.substring(7); + break; + case "tableflip": + message="(╯°□°)╯︵ ┻━┻ "+message.substring(11); + break; + case "unflip": + message="┬──┬ ノ( ゜-゜ノ) "+message.substring(8); + break; + case "lenny": + message="( ͡° ͜ʖ ͡°) "+message.substring(7); + break; + default: + if (command[0][0]=="/") { + message = message.substring(1).trim(); + break; + } else { + this._sendError=new Error("no command name '"+command[0]+"'"); + this._timelineError = null; + this.emitChange("error"); + msgtype=undefined; + message=undefined; + } + } + } + return [msgtype, message]; + } + async _sendMessage(message, replyingTo) { if (!this._room.isArchived && message) { + let messinfo = await this._getMessageInformations(message); try { - let msgtype = "m.text"; - if (message.startsWith("/me ")) { - message = message.substr(4).trim(); - msgtype = "m.emote"; - } - if (replyingTo) { - await replyingTo.reply(msgtype, message); - } else { - await this._room.sendEvent("m.room.message", {msgtype, body: message}); + let msgtype = messinfo[0]; + let message = messinfo[1]; + console.log("messinfo :",messinfo); + if (msgtype && message) { + if (replyingTo) { + await replyingTo.reply(msgtype, message); + } else { + await this._room.sendEvent("m.room.message", {msgtype, body: message}); + } } } catch (err) { console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`); diff --git a/src/platform/web/ui/css/themes/element/theme.css b/src/platform/web/ui/css/themes/element/theme.css index 632d5bc5..16dfea12 100644 --- a/src/platform/web/ui/css/themes/element/theme.css +++ b/src/platform/web/ui/css/themes/element/theme.css @@ -521,6 +521,18 @@ a { .RoomView_error { color: var(--error-color); + background : #efefef; + padding-right : 20px; + padding-left : 20px; + overflow : hidden; + height : 0px; + transition : 0.25s all ease-out; +} + +.RoomView_error:not(:empty) { + height : auto; + padding-top : 20px; + padding-bottom : 20px; } .MessageComposer_replyPreview .Timeline_message {