- Application des différents commentaires du Pull Request (#809)

- Correction des erreurs d'indentations.
This commit is contained in:
Kaki In 2022-07-25 15:22:06 +02:00
parent 0bf021ea87
commit 1e5179f835
5 changed files with 105 additions and 117 deletions

View File

@ -197,9 +197,8 @@ export class RoomViewModel extends ViewModel {
} }
} }
async _getMessageInformations (message) { async _processCommand (message) {
let msgtype = "m.text"; let msgtype = undefined;
if (message.startsWith("/")) {
const [commandName, ...args] = message.substring(1).split(" "); const [commandName, ...args] = message.substring(1).split(" ");
switch (commandName) { switch (commandName) {
case "me": case "me":
@ -210,9 +209,9 @@ export class RoomViewModel extends ViewModel {
if (args.length == 1) { if (args.length == 1) {
let roomName = args[0]; let roomName = args[0];
try { try {
const internalId = await this._options.client.session.joinRoom(roomName); const roomId = await this._options.client.session.joinRoom(roomName);
await this._options.client.session.waitForRoomFromSync(internalId); await session.observeRoomStatus(roomId).waitFor(status === RoomStatus.Joined);
this.navigation.push("room", internalId); this.navigation.push("room", roomId);
} catch (exc) { } catch (exc) {
if ((exc.statusCode ?? exc.status) === 400) { if ((exc.statusCode ?? exc.status) === 400) {
this._sendError = new Error(`/join : '${roomName}' was not legal room ID or room alias`); this._sendError = new Error(`/join : '${roomName}' was not legal room ID or room alias`);
@ -231,43 +230,44 @@ export class RoomViewModel extends ViewModel {
this._timelineError = null; this._timelineError = null;
this.emitChange("error"); this.emitChange("error");
} }
msgtype = undefined;
message = undefined;
break; break;
case "shrug": case "shrug":
message = "¯\\_(ツ)_/¯ " + message.substring(7); message = "¯\\_(ツ)_/¯ " + message.substring(7);
msgtype = "m.text";
break; break;
case "tableflip": case "tableflip":
message="(╯°□°)╯︵ ┻━┻ " + message.substring(11); message="(╯°□°)╯︵ ┻━┻ " + message.substring(11);
msgtype = "m.text";
break; break;
case "unflip": case "unflip":
message="┬──┬ ( ゜-゜ノ) " + message.substring(8); message="┬──┬ ( ゜-゜ノ) " + message.substring(8);
msgtype = "m.text";
break; break;
case "lenny": case "lenny":
message="( ͡° ͜ʖ ͡°) " + message.substring(7); message="( ͡° ͜ʖ ͡°) " + message.substring(7);
msgtype = "m.text";
break; break;
default: 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}"`); this._sendError = new Error(`no command name "${commandName}". To send the message instead of executing, please type "/${message}"`);
this._timelineError = null; this._timelineError = null;
this.emitChange("error"); this.emitChange("error");
msgtype = undefined; msgtype = undefined;
message = undefined; message = undefined;
} }
}
}
return {type: msgtype, message: message}; return {type: msgtype, message: message};
} }
async _sendMessage(message, replyingTo) { async _sendMessage(message, replyingTo) {
if (!this._room.isArchived && message) { 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 { try {
let msgtype = messinfo.type; const msgtype = messinfo.type;
let message = messinfo.message; const message = messinfo.message;
if (msgtype && message) { if (msgtype && message) {
if (replyingTo) { if (replyingTo) {
await replyingTo.reply(msgtype, message); await replyingTo.reply(msgtype, message);

View File

@ -948,23 +948,6 @@ export class Session {
return body.room_id; 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() { export function tests() {

View File

@ -522,19 +522,24 @@ a {
.RoomView_error { .RoomView_error {
color: var(--error-color); color: var(--error-color);
background : #efefef; background : #efefef;
padding-right : 20px;
padding-left : 20px;
overflow : hidden;
height : 0px; height : 0px;
font-weight : bold; font-weight : bold;
transition : 0.25s all ease-out; transition : 0.25s all ease-out;
padding-right : 20px;
padding-left : 20px;
}
.RoomView_error div{
overflow : hidden;
height: 100%;
width: 100%;
position : relative; position : relative;
display : flex; display : flex;
align-items : center;
} }
.RoomView_error:not(:empty) { .RoomView_error:not(:empty) {
height : 40px; height : 40px;
align-items : center;
padding-top : 20px; padding-top : 20px;
padding-bottom : 20px; padding-bottom : 20px;
} }

View File

@ -47,12 +47,12 @@ export class RoomView extends TemplateView {
]), ]),
t.div({className: "RoomView_body"}, [ t.div({className: "RoomView_body"}, [
t.div({className: "RoomView_error"}, [ t.div({className: "RoomView_error"}, [
t.if(vm => vm.error, t => t.p({}, vm => vm.error)), t.if(vm => vm.error, t => t.div(
t.if(vm => vm.error, t => t.button({ [
className: "RoomView_error_closerButton", t.p({}, vm => vm.error),
onClick: evt => vm.dismissError(evt) t.button({ className: "RoomView_error_closerButton", onClick: evt => vm.dismissError(evt) })
})) ])
]), )]),
t.mapView(vm => vm.timelineViewModel, timelineViewModel => { t.mapView(vm => vm.timelineViewModel, timelineViewModel => {
return timelineViewModel ? return timelineViewModel ?
new TimelineView(timelineViewModel, this._viewClassForTile) : new TimelineView(timelineViewModel, this._viewClassForTile) :