- 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) {
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 <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}"`);
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 <room-id>");
}
this._timelineError = null;
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};
}
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);

View file

@ -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() {

View file

@ -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"));
},
}
}

View file

@ -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 {

View file

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