From 242a9c209b4fe2711696bbf5a7c711ef17ce2f91 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 23 Jul 2021 14:34:11 -0700 Subject: [PATCH] Handle replies in EventEntry --- src/domain/session/room/RoomViewModel.js | 12 ++++++------ .../session/room/timeline/tiles/BaseMessageTile.js | 4 ++-- src/matrix/room/timeline/entries/BaseEventEntry.js | 4 ++-- src/matrix/room/timeline/relations.js | 10 +++++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 52613002..151af2e6 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -155,7 +155,7 @@ export class RoomViewModel extends ViewModel { this._room.join(); } - async _sendMessage(message, reply) { + async _sendMessage(message, replyingTo) { if (!this._room.isArchived && message) { try { let msgtype = "m.text"; @@ -163,11 +163,11 @@ export class RoomViewModel extends ViewModel { message = message.substr(4).trim(); msgtype = "m.emote"; } - const content = {msgtype, body: message}; - if (reply) { - content["m.relates_to"] = reply; + if (replyingTo) { + await replyingTo.reply(msgtype, message); + } else { + await this._room.sendEvent("m.room.message", {msgtype, body: message}); } - await this._room.sendEvent("m.room.message", content); } catch (err) { console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`); this._sendError = err; @@ -336,7 +336,7 @@ class ComposerViewModel extends ViewModel { } sendMessage(message) { - const success = this._roomVM._sendMessage(message, this._replyVM?.reply()); + const success = this._roomVM._sendMessage(message, this._replyVM); if (success) { this._isEmpty = true; this.emitChange("canSend"); diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index 0cff2793..9a206ad2 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -110,8 +110,8 @@ export class BaseMessageTile extends SimpleTile { this._roomVM.startReply(this); } - reply() { - return this._entry.reply(); + reply(msgtype, body) { + return this._room.sendEvent("m.room.message", this._entry.reply(msgtype, body)); } redact(reason, log) { diff --git a/src/matrix/room/timeline/entries/BaseEventEntry.js b/src/matrix/room/timeline/entries/BaseEventEntry.js index 68f38357..b1744227 100644 --- a/src/matrix/room/timeline/entries/BaseEventEntry.js +++ b/src/matrix/room/timeline/entries/BaseEventEntry.js @@ -151,8 +151,8 @@ export class BaseEventEntry extends BaseEntry { return createAnnotation(this.id, key); } - reply() { - return createReply(this.id); + reply(msgtype, body) { + return createReply(this.id, msgtype, body); } /** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */ diff --git a/src/matrix/room/timeline/relations.js b/src/matrix/room/timeline/relations.js index 0f861d0e..b6d23c50 100644 --- a/src/matrix/room/timeline/relations.js +++ b/src/matrix/room/timeline/relations.js @@ -29,10 +29,14 @@ export function createAnnotation(targetId, key) { }; } -export function createReply(targetId) { +export function createReply(targetId, msgtype, body) { return { - "m.in_reply_to": { - "event_id": targetId + msgtype, + body, + "m.relates_to": { + "m.in_reply_to": { + "event_id": targetId + } } }; }