From 82122872bfd8454f90dda3f3b1f4ee27c2aad1a0 Mon Sep 17 00:00:00 2001 From: Germain Date: Wed, 2 Feb 2022 14:44:38 +0000 Subject: [PATCH] Add thread relation in sendEvent if it's missing (#2149) --- src/client.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/client.ts b/src/client.ts index 8c3f4c5c8..f590ddf0d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3593,6 +3593,22 @@ export class MatrixClient extends EventEmitter { eventType = threadId; threadId = null; } + + if (threadId && content["m.relates_to"]?.rel_type !== RelationType.Thread) { + content["m.relates_to"] = { + ...content["m.relates_to"], + "rel_type": RelationType.Thread, + "event_id": threadId, + }; + + const thread = this.getRoom(roomId)?.threads.get(threadId); + if (thread) { + content["m.relates_to"]["m.in_reply_to"] = { + "event_id": thread.replyToEvent.getId(), + }; + } + } + return this.sendCompleteEvent(roomId, threadId, { type: eventType, content }, txnId as string, callback); } @@ -4213,17 +4229,6 @@ export class MatrixClient extends EventEmitter { body: text, }; - const thread = this.getRoom(roomId)?.threads.get(threadId); - if (thread) { - content["m.relates_to"] = { - "rel_type": RelationType.Thread, - "event_id": threadId, - "m.in_reply_to": { - "event_id": thread.replyToEvent.getId(), - }, - }; - } - return this.sendEvent(roomId, threadId, EventType.Sticker, content, undefined, callback); }