From 4f86eee2504661e90edce06fe2d57d13f6fd741f Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Mon, 19 Dec 2022 11:32:37 +0100 Subject: [PATCH] Threads are missing from the timeline (#2996) --- .../matrix-client-event-timeline.spec.ts | 55 +++++++++++++++++++ src/client.ts | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/spec/integ/matrix-client-event-timeline.spec.ts b/spec/integ/matrix-client-event-timeline.spec.ts index 5edd5c4b7d2..0c553e77ff5 100644 --- a/spec/integ/matrix-client-event-timeline.spec.ts +++ b/spec/integ/matrix-client-event-timeline.spec.ts @@ -1016,6 +1016,61 @@ describe("MatrixClient event timelines", function () { httpBackend.flushAllExpected(), ]); }); + + it("should create threads for thread roots discovered", function () { + const room = client.getRoom(roomId)!; + const timelineSet = room.getTimelineSets()[0]; + + httpBackend + .when("GET", "/rooms/!foo%3Abar/context/" + encodeURIComponent(EVENTS[0].event_id!)) + .respond(200, function () { + return { + start: "start_token0", + events_before: [], + event: EVENTS[0], + events_after: [], + end: "end_token0", + state: [], + }; + }); + + httpBackend + .when("GET", "/rooms/!foo%3Abar/messages") + .check(function (req) { + const params = req.queryParams!; + expect(params.dir).toEqual("b"); + expect(params.from).toEqual("start_token0"); + expect(params.limit).toEqual("30"); + }) + .respond(200, function () { + return { + chunk: [EVENTS[1], EVENTS[2], THREAD_ROOT], + end: "start_token1", + }; + }); + + let tl: EventTimeline; + return Promise.all([ + client + .getEventTimeline(timelineSet, EVENTS[0].event_id!) + .then(function (tl0) { + tl = tl0!; + return client.paginateEventTimeline(tl, { backwards: true }); + }) + .then(function (success) { + expect(success).toBeTruthy(); + expect(tl!.getEvents().length).toEqual(4); + expect(tl!.getEvents()[0].event).toEqual(THREAD_ROOT); + expect(tl!.getEvents()[1].event).toEqual(EVENTS[2]); + expect(tl!.getEvents()[2].event).toEqual(EVENTS[1]); + expect(tl!.getEvents()[3].event).toEqual(EVENTS[0]); + expect(room.getThreads().map((it) => it.id)).toEqual([THREAD_ROOT.event_id!]); + expect(tl!.getPaginationToken(EventTimeline.BACKWARDS)).toEqual("start_token1"); + expect(tl!.getPaginationToken(EventTimeline.FORWARDS)).toEqual("end_token0"); + }), + httpBackend.flushAllExpected(), + ]); + }); }); it("should ensure thread events are ordered correctly", async () => { diff --git a/src/client.ts b/src/client.ts index 832df1e1fc8..8066b22c8cd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6059,7 +6059,7 @@ export class MatrixClient extends TypedEventEmitter it.isRelation(THREAD_RELATION_TYPE.name)), + timelineEvents.filter((it) => it.getServerAggregatedRelation(THREAD_RELATION_TYPE.name)), false, );