- 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,77 +197,77 @@ 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": message = message.substring(4).trim();
message = message.substring(4).trim(); msgtype = "m.emote";
msgtype = "m.emote"; break;
break; case "join":
case "join": if (args.length == 1) {
if (args.length == 1) { let roomName = args[0];
let roomName = args[0]; try {
try { const roomId = await this._options.client.session.joinRoom(roomName);
const internalId = await this._options.client.session.joinRoom(roomName); await session.observeRoomStatus(roomId).waitFor(status === RoomStatus.Joined);
await this._options.client.session.waitForRoomFromSync(internalId); this.navigation.push("room", roomId);
this.navigation.push("room", internalId); } 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`); } else if ((exc.statusCode ?? exc.status) === 404 || (exc.statusCode ?? exc.status) === 502 || exc.message == "Internal Server Error") {
} 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`);
this._sendError = new Error(`/join : room '${roomName}' not found`); } else if ((exc.statusCode ?? exc.status) === 403) {
} else if ((exc.statusCode ?? exc.status) === 403) { this._sendError = new Error(`/join : you're not invited to join '${roomName}'`);
this._sendError = new Error(`/join : you're not invited to join '${roomName}'`); } else {
} else { this._sendError = new Error("join syntax: /join <room-id>");
this._sendError = new Error("join syntax: /join <room-id>"); }
}
this._timelineError = null;
this.emitChange("error");
}
} else {
this._sendError = new Error("join syntax: /join <room-id>");
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}"`);
this._timelineError = null; this._timelineError = null;
this.emitChange("error"); this.emitChange("error");
msgtype = undefined; }
message = undefined; } else {
} this._sendError = new Error("join syntax: /join <room-id>");
} 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}; 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

@ -22,16 +22,16 @@ export function makeTxnId() {
} }
export function isTxnId(txnId) { export function isTxnId(txnId) {
return txnId.startsWith("t") && txnId.length === 15; return txnId.startsWith("t") && txnId.length === 15;
} }
export function tests() { export function tests() {
return { return {
"isTxnId succeeds on result of makeTxnId": assert => { "isTxnId succeeds on result of makeTxnId": assert => {
assert(isTxnId(makeTxnId())); assert(isTxnId(makeTxnId()));
}, },
"isTxnId fails on event id": assert => { "isTxnId fails on event id": assert => {
assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm"));
}, },
} }
} }

View file

@ -522,26 +522,31 @@ 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;
} }
.RoomView_error p { .RoomView_error p {
position : relative; position : relative;
display : block; display : block;
width : 100%; width : 100%;
height : auto; height : auto;
margin : 0; margin : 0;
@ -557,29 +562,29 @@ a {
} }
.RoomView_error button:hover { .RoomView_error button:hover {
background : #cfcfcf; background : #cfcfcf;
} }
.RoomView_error button:after { .RoomView_error button:after {
content:""; content:"";
position : absolute; position : absolute;
top : 10px; top : 10px;
right: 16px; right: 16px;
background : red; background : red;
width : 5px; width : 5px;
height : 20px; height : 20px;
transform: rotate(45deg); transform: rotate(45deg);
} }
.RoomView_error button:before { .RoomView_error button:before {
content:""; content:"";
position : absolute; position : absolute;
top : 17px; top : 17px;
left: 10px; left: 10px;
background : red; background : red;
width : 20px; width : 20px;
height : 5px; height : 5px;
transform: rotate(45deg); transform: rotate(45deg);
} }
.MessageComposer_replyPreview .Timeline_message { .MessageComposer_replyPreview .Timeline_message {

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) :