mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Added the possibility to join a room using /join (also added the global commands uses, and some others commands like /shrug .)
This commit is contained in:
parent
bb5711db7e
commit
faa8cae532
@ -197,19 +197,81 @@ export class RoomViewModel extends ViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
async _getMessageInformations (message) {
|
||||
let msgtype = "m.text";
|
||||
if (message.startsWith("/")) {
|
||||
let command=message.substring(1).split(" ");
|
||||
switch (command[0]) {
|
||||
case "me":
|
||||
message = message.substring(4).trim();
|
||||
msgtype = "m.emote";
|
||||
break;
|
||||
case "join":
|
||||
if (command.length==2) {
|
||||
let roomname = message.substring(5).trim();
|
||||
try {
|
||||
await this._options.client.session.joinRoom(roomname);
|
||||
} 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==502) || (exc.message="Internal Server Error")) {
|
||||
this._sendError=new Error("/join : room not found");
|
||||
} 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 (command[0][0]=="/") {
|
||||
message = message.substring(1).trim();
|
||||
break;
|
||||
} else {
|
||||
this._sendError=new Error("no command name '"+command[0]+"'");
|
||||
this._timelineError = null;
|
||||
this.emitChange("error");
|
||||
msgtype=undefined;
|
||||
message=undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [msgtype, message];
|
||||
}
|
||||
|
||||
async _sendMessage(message, replyingTo) {
|
||||
if (!this._room.isArchived && message) {
|
||||
let messinfo = await this._getMessageInformations(message);
|
||||
try {
|
||||
let msgtype = "m.text";
|
||||
if (message.startsWith("/me ")) {
|
||||
message = message.substr(4).trim();
|
||||
msgtype = "m.emote";
|
||||
}
|
||||
let msgtype = messinfo[0];
|
||||
let message = messinfo[1];
|
||||
console.log("messinfo :",messinfo);
|
||||
if (msgtype && message) {
|
||||
if (replyingTo) {
|
||||
await replyingTo.reply(msgtype, message);
|
||||
} else {
|
||||
await this._room.sendEvent("m.room.message", {msgtype, body: message});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
|
||||
this._sendError = err;
|
||||
|
@ -521,6 +521,18 @@ a {
|
||||
|
||||
.RoomView_error {
|
||||
color: var(--error-color);
|
||||
background : #efefef;
|
||||
padding-right : 20px;
|
||||
padding-left : 20px;
|
||||
overflow : hidden;
|
||||
height : 0px;
|
||||
transition : 0.25s all ease-out;
|
||||
}
|
||||
|
||||
.RoomView_error:not(:empty) {
|
||||
height : auto;
|
||||
padding-top : 20px;
|
||||
padding-bottom : 20px;
|
||||
}
|
||||
|
||||
.MessageComposer_replyPreview .Timeline_message {
|
||||
|
Loading…
Reference in New Issue
Block a user