Handle replies in EventEntry

This commit is contained in:
Danila Fedorin 2021-07-23 14:34:11 -07:00
parent 711732200e
commit 242a9c209b
4 changed files with 17 additions and 13 deletions

View File

@ -155,7 +155,7 @@ export class RoomViewModel extends ViewModel {
this._room.join(); this._room.join();
} }
async _sendMessage(message, reply) { async _sendMessage(message, replyingTo) {
if (!this._room.isArchived && message) { if (!this._room.isArchived && message) {
try { try {
let msgtype = "m.text"; let msgtype = "m.text";
@ -163,11 +163,11 @@ export class RoomViewModel extends ViewModel {
message = message.substr(4).trim(); message = message.substr(4).trim();
msgtype = "m.emote"; msgtype = "m.emote";
} }
const content = {msgtype, body: message}; if (replyingTo) {
if (reply) { await replyingTo.reply(msgtype, message);
content["m.relates_to"] = reply; } else {
await this._room.sendEvent("m.room.message", {msgtype, body: message});
} }
await this._room.sendEvent("m.room.message", content);
} catch (err) { } catch (err) {
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`); console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
this._sendError = err; this._sendError = err;
@ -336,7 +336,7 @@ class ComposerViewModel extends ViewModel {
} }
sendMessage(message) { sendMessage(message) {
const success = this._roomVM._sendMessage(message, this._replyVM?.reply()); const success = this._roomVM._sendMessage(message, this._replyVM);
if (success) { if (success) {
this._isEmpty = true; this._isEmpty = true;
this.emitChange("canSend"); this.emitChange("canSend");

View File

@ -110,8 +110,8 @@ export class BaseMessageTile extends SimpleTile {
this._roomVM.startReply(this); this._roomVM.startReply(this);
} }
reply() { reply(msgtype, body) {
return this._entry.reply(); return this._room.sendEvent("m.room.message", this._entry.reply(msgtype, body));
} }
redact(reason, log) { redact(reason, log) {

View File

@ -151,8 +151,8 @@ export class BaseEventEntry extends BaseEntry {
return createAnnotation(this.id, key); return createAnnotation(this.id, key);
} }
reply() { reply(msgtype, body) {
return createReply(this.id); return createReply(this.id, msgtype, body);
} }
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */ /** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */

View File

@ -29,10 +29,14 @@ export function createAnnotation(targetId, key) {
}; };
} }
export function createReply(targetId) { export function createReply(targetId, msgtype, body) {
return { return {
"m.in_reply_to": { msgtype,
"event_id": targetId body,
"m.relates_to": {
"m.in_reply_to": {
"event_id": targetId
}
} }
}; };
} }