From 9bd7d1397cde767a88cb4397245d052037556687 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 30 Jul 2021 14:37:34 -0700 Subject: [PATCH] Preserve the m.relates_to field for message. --- src/matrix/room/sending/PendingEvent.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index 731707e5..af295579 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -28,6 +28,10 @@ export const SendStatus = createEnum( "Error", ); +const preservedContentFields = { + "m.room.message": [ "m.relates_to" ] +}; + export class PendingEvent { constructor({data, remove, emitUpdate, attachments}) { this._data = data; @@ -96,7 +100,20 @@ export class PendingEvent { this._emitUpdate("status"); } + _preserveContentFields(into) { + const preservedFields = preservedContentFields[this.eventType]; + if (preservedFields) { + const content = this._data.content; + for (const field of preservedFields) { + if (content[field] !== undefined) { + into[field] = content[field]; + } + } + } + } + setEncrypted(type, content) { + this._preserveContentFields(content); this._data.encryptedEventType = type; this._data.encryptedContent = content; this._data.needsEncryption = false;