From 1e5179f8356ecf16221bb9ca1ddc2057702a60f6 Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Mon, 25 Jul 2022 15:22:06 +0200 Subject: [PATCH] =?UTF-8?q?=20-=20Application=20des=20diff=C3=A9rents=20co?= =?UTF-8?q?mmentaires=20du=20Pull=20Request=20(#809)=20=20-=20Correction?= =?UTF-8?q?=20des=20erreurs=20d'indentations.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/session/room/RoomViewModel.js | 124 +++++++++--------- src/matrix/Session.js | 17 --- src/matrix/common.js | 18 +-- .../web/ui/css/themes/element/theme.css | 51 +++---- src/platform/web/ui/session/room/RoomView.js | 12 +- 5 files changed, 105 insertions(+), 117 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index a15447b8..9b6aa966 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -197,77 +197,77 @@ export class RoomViewModel extends ViewModel { } } - async _getMessageInformations (message) { - let msgtype = "m.text"; - if (message.startsWith("/")) { - const [commandName, ...args] = message.substring(1).split(" "); - switch (commandName) { - case "me": - message = message.substring(4).trim(); - msgtype = "m.emote"; - break; - case "join": - if (args.length == 1) { - let roomName = args[0]; - try { - const internalId = await this._options.client.session.joinRoom(roomName); - await this._options.client.session.waitForRoomFromSync(internalId); - 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) === 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 = 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 (commandName[0] == "/") { - message = message.substring(1).trim(); - break; - } else { - this._sendError = new Error(`no command name "${commandName}". To send the message instead of executing, please type "/${message}"`); + async _processCommand (message) { + let msgtype = undefined; + const [commandName, ...args] = message.substring(1).split(" "); + switch (commandName) { + case "me": + message = message.substring(4).trim(); + msgtype = "m.emote"; + break; + case "join": + if (args.length == 1) { + let roomName = args[0]; + try { + const roomId = await this._options.client.session.joinRoom(roomName); + await session.observeRoomStatus(roomId).waitFor(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 = new Error("join syntax: /join "); + } this._timelineError = null; this.emitChange("error"); - msgtype = undefined; - message = undefined; - } - } + } + } else { + this._sendError = new Error("join syntax: /join "); + this._timelineError = null; + this.emitChange("error"); + } + break; + case "shrug": + message = "¯\\_(ツ)_/¯ " + message.substring(7); + msgtype = "m.text"; + break; + case "tableflip": + message="(╯°□°)╯︵ ┻━┻ " + message.substring(11); + msgtype = "m.text"; + break; + case "unflip": + message="┬──┬ ノ( ゜-゜ノ) " + message.substring(8); + msgtype = "m.text"; + break; + case "lenny": + message="( ͡° ͜ʖ ͡°) " + message.substring(7); + msgtype = "m.text"; + break; + default: + 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; } return {type: msgtype, message: message}; } async _sendMessage(message, replyingTo) { if (!this._room.isArchived && message) { - let messinfo = await this._getMessageInformations(message); + let messinfo = {msgtype : "m.text", message : message}; + if (message.startsWith("//")) { + messinfo.message = message.substring(1).trim(); + } else if (message.startsWith("/")) { + messinfo = await this._processCommand(message); + } try { - let msgtype = messinfo.type; - let message = messinfo.message; + const msgtype = messinfo.type; + const message = messinfo.message; if (msgtype && message) { if (replyingTo) { await replyingTo.reply(msgtype, message); diff --git a/src/matrix/Session.js b/src/matrix/Session.js index f45cb5b3..ae1dea61 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -948,23 +948,6 @@ export class Session { return body.room_id; }); } - - waitForRoomFromSync(roomId) { - let resolve; - const promise = new Promise(r => { resolve = r; }) - const subscription = { - onAdd: (_, value) => { - if (value.id === roomId) { - this._session.rooms.unsubscribe(subscription); - resolve(); - } - }, - onUpdate: () => undefined, - onRemove: () => undefined, - }; - this._session.rooms.subscribe(subscription); - return promise; - } } export function tests() { diff --git a/src/matrix/common.js b/src/matrix/common.js index ba7876ed..abd74a57 100644 --- a/src/matrix/common.js +++ b/src/matrix/common.js @@ -22,16 +22,16 @@ export function makeTxnId() { } export function isTxnId(txnId) { - return txnId.startsWith("t") && txnId.length === 15; + return txnId.startsWith("t") && txnId.length === 15; } export function tests() { - return { - "isTxnId succeeds on result of makeTxnId": assert => { - assert(isTxnId(makeTxnId())); - }, - "isTxnId fails on event id": assert => { - assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); - }, - } + return { + "isTxnId succeeds on result of makeTxnId": assert => { + assert(isTxnId(makeTxnId())); + }, + "isTxnId fails on event id": assert => { + assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); + }, + } } diff --git a/src/platform/web/ui/css/themes/element/theme.css b/src/platform/web/ui/css/themes/element/theme.css index f14100b2..f611c767 100644 --- a/src/platform/web/ui/css/themes/element/theme.css +++ b/src/platform/web/ui/css/themes/element/theme.css @@ -522,26 +522,31 @@ a { .RoomView_error { color: var(--error-color); background : #efefef; - padding-right : 20px; - padding-left : 20px; - overflow : hidden; height : 0px; font-weight : bold; transition : 0.25s all ease-out; + padding-right : 20px; + padding-left : 20px; +} + +.RoomView_error div{ + overflow : hidden; + height: 100%; + width: 100%; position : relative; display : flex; + align-items : center; } .RoomView_error:not(:empty) { height : 40px; - align-items : center; padding-top : 20px; padding-bottom : 20px; } .RoomView_error p { - position : relative; - display : block; + position : relative; + display : block; width : 100%; height : auto; margin : 0; @@ -557,29 +562,29 @@ a { } .RoomView_error button:hover { - background : #cfcfcf; + background : #cfcfcf; } .RoomView_error button:after { - content:""; - position : absolute; - top : 10px; - right: 16px; - background : red; - width : 5px; - height : 20px; - transform: rotate(45deg); + content:""; + position : absolute; + top : 10px; + right: 16px; + background : red; + width : 5px; + height : 20px; + transform: rotate(45deg); } .RoomView_error button:before { - content:""; - position : absolute; - top : 17px; - left: 10px; - background : red; - width : 20px; - height : 5px; - transform: rotate(45deg); + content:""; + position : absolute; + top : 17px; + left: 10px; + background : red; + width : 20px; + height : 5px; + transform: rotate(45deg); } .MessageComposer_replyPreview .Timeline_message { diff --git a/src/platform/web/ui/session/room/RoomView.js b/src/platform/web/ui/session/room/RoomView.js index 7cfd7d85..e3eb0587 100644 --- a/src/platform/web/ui/session/room/RoomView.js +++ b/src/platform/web/ui/session/room/RoomView.js @@ -47,12 +47,12 @@ export class RoomView extends TemplateView { ]), t.div({className: "RoomView_body"}, [ t.div({className: "RoomView_error"}, [ - t.if(vm => vm.error, t => t.p({}, vm => vm.error)), - t.if(vm => vm.error, t => t.button({ - className: "RoomView_error_closerButton", - onClick: evt => vm.dismissError(evt) - })) - ]), + t.if(vm => vm.error, t => t.div( + [ + t.p({}, vm => vm.error), + t.button({ className: "RoomView_error_closerButton", onClick: evt => vm.dismissError(evt) }) + ]) + )]), t.mapView(vm => vm.timelineViewModel, timelineViewModel => { return timelineViewModel ? new TimelineView(timelineViewModel, this._viewClassForTile) :