From b3523c320bbe17f0bae66f2900a80a286ce14cd8 Mon Sep 17 00:00:00 2001 From: Mikhail Aheichyk Date: Mon, 26 Feb 2024 09:21:30 +0300 Subject: [PATCH] Add event with m.reference relation to unknown parent to the timeline. Signed-off-by: Mikhail Aheichyk --- spec/unit/room.spec.ts | 19 +++++++++++++++++++ src/models/room.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index 4d64e4df54d..8b25416f3f3 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -3199,6 +3199,25 @@ describe("Room", function () { expect(room.eventShouldLiveIn(reply).shouldLiveInRoom).toBeTruthy(); expect(room.eventShouldLiveIn(reply).shouldLiveInThread).toBeFalsy(); }); + + it("an event with m.reference relation to unknown parent event should live in the main timeline only", async () => { + const event = utils.mkEvent({ + event: true, + type: "org.example.child", + user: "@alice:example.org", + content: { + "key": "value", + "m.relates_to": { + event_id: "$unknown-parent", + rel_type: "m.reference", + }, + }, + room: roomId, + }); + + expect(room.eventShouldLiveIn(event).shouldLiveInRoom).toBeTruthy(); + expect(room.eventShouldLiveIn(event).shouldLiveInThread).toBeFalsy(); + }); }); describe("getEventReadUpTo()", () => { diff --git a/src/models/room.ts b/src/models/room.ts index 67aea690756..e65aab07724 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -2197,7 +2197,7 @@ export class Room extends ReadReceipt { // Due to replies not being typical relations and being used as fallbacks for threads relations // If we bypass the if case above then we know we are not a thread, so if we are still a reply // then we know that we must be in the main timeline. Same goes if we have no associated parent event. - if (!parentEventId || !!event.replyEventId) { + if (!parentEventId || !!event.replyEventId || event.getRelation()?.rel_type === "m.reference") { return { shouldLiveInRoom: true, shouldLiveInThread: false,