forked from mystiq/hydrogen-web
- Application des différents commentaires du Pull Request (#809)
- Correction des erreurs d'indentations.
This commit is contained in:
parent
0bf021ea87
commit
1e5179f835
5 changed files with 105 additions and 117 deletions
|
@ -197,9 +197,8 @@ export class RoomViewModel extends ViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
async _getMessageInformations (message) {
|
||||
let msgtype = "m.text";
|
||||
if (message.startsWith("/")) {
|
||||
async _processCommand (message) {
|
||||
let msgtype = undefined;
|
||||
const [commandName, ...args] = message.substring(1).split(" ");
|
||||
switch (commandName) {
|
||||
case "me":
|
||||
|
@ -210,9 +209,9 @@ export class RoomViewModel extends ViewModel {
|
|||
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);
|
||||
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`);
|
||||
|
@ -231,43 +230,44 @@ export class RoomViewModel extends ViewModel {
|
|||
this._timelineError = null;
|
||||
this.emitChange("error");
|
||||
}
|
||||
msgtype = undefined;
|
||||
message = undefined;
|
||||
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:
|
||||
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.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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -522,19 +522,24 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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) :
|
||||
|
|
Loading…
Reference in a new issue