From 156fcff941b910901253c1b0b7f1dc2d2d4829ea Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Jun 2023 16:04:28 +0100 Subject: [PATCH] Iterate --- src/models/event.ts | 12 ++---------- src/models/room.ts | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/models/event.ts b/src/models/event.ts index 0c89fea407c..feb21fbba74 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -579,16 +579,8 @@ export class MatrixEvent extends TypedEventEmitter { } // A thread relation is always only shown in a thread - const threadRootId = event.threadRootId; - if (threadRootId != undefined) { + if (event.isRelation(THREAD_RELATION_TYPE.name)) { return { shouldLiveInRoom: false, shouldLiveInThread: true, - threadId: threadRootId, + threadId: event.threadRootId, }; } @@ -2149,6 +2149,15 @@ export class Room extends ReadReceipt { }; } + const unsigned = event.getUnsigned(); + if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") { + return { + shouldLiveInRoom: false, + shouldLiveInThread: true, + threadId: unsigned[UNSIGNED_THREAD_ID_FIELD.name], + }; + } + // We've exhausted all scenarios, // we cannot assume that it lives in the main timeline as this may be a relation for an unknown thread // adding the event in the wrong timeline causes stuck notifications and can break ability to send read receipts @@ -2804,7 +2813,7 @@ export class Room extends ReadReceipt { if (parentEvent.threadRootId) { threadRoots.add(parentEvent.threadRootId); const unsigned = event.getUnsigned(); - unsigned["org.matrix.msc4023.thread_id"] = parentEvent.threadRootId; + unsigned[UNSIGNED_THREAD_ID_FIELD.name] = parentEvent.threadRootId; event.setUnsigned(unsigned); } @@ -2881,9 +2890,12 @@ export class Room extends ReadReceipt { private findThreadRoots(events: MatrixEvent[]): Set { const threadRoots = new Set(); for (const event of events) { - const threadRootId = event.threadRootId; - if (threadRootId != undefined) { - threadRoots.add(threadRootId); + if (event.isRelation(THREAD_RELATION_TYPE.name)) { + threadRoots.add(event.relationEventId ?? ""); + } + const unsigned = event.getUnsigned(); + if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") { + threadRoots.add(unsigned[UNSIGNED_THREAD_ID_FIELD.name]!); } } return threadRoots;