From db7bed4575a9d91fbdac1de65b5124c15962df05 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 18:01:02 +0100 Subject: [PATCH 1/6] Add additional tests for thread timelines --- .../matrix-client-event-timeline.spec.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index 454a4d30323..43ae394f97f 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -1,5 +1,5 @@ import * as utils from "../test-utils/test-utils"; -import { EventTimeline } from "../../src/matrix"; +import { EventTimeline, MatrixEvent } from "../../src/matrix"; import { logger } from "../../src/logger"; import { TestClient } from "../TestClient"; import { Thread, THREAD_RELATION_TYPE } from "../../src/models/thread"; @@ -500,7 +500,8 @@ describe("MatrixClient event timelines", function() { Thread.setServerSideSupport(true); client.stopClient(); // we don't need the client to be syncing at this time const room = client.getRoom(roomId); - const timelineSet = room.getTimelineSets()[0]; + const thread = room.createThread(THREAD_ROOT.event_id, undefined, [], false); + const timelineSet = thread.timelineSet; httpBackend.when("GET", "/rooms/!foo%3Abar/context/" + encodeURIComponent(THREAD_REPLY.event_id)) .respond(200, function() { @@ -538,6 +539,39 @@ describe("MatrixClient event timelines", function() { expect(timeline.getEvents().find(e => e.getId() === THREAD_ROOT.event_id)).toBeTruthy(); expect(timeline.getEvents().find(e => e.getId() === THREAD_REPLY.event_id)).toBeTruthy(); }); + + it("should return undefined when event is not within a thread but timelineSet is", async () => { + client.clientOpts.experimentalThreadSupport = true; + Thread.setServerSideSupport(true); + client.stopClient(); // we don't need the client to be syncing at this time + const room = client.getRoom(roomId); + const threadRoot = new MatrixEvent(THREAD_ROOT); + const thread = room.createThread(THREAD_ROOT.event_id, threadRoot, [threadRoot], false); + const timelineSet = thread.timelineSet; + + httpBackend.when("GET", "/rooms/!foo%3Abar/event/" + encodeURIComponent(THREAD_ROOT.event_id)) + .respond(200, function() { + return THREAD_ROOT; + }); + + httpBackend.when("GET", "/rooms/!foo%3Abar/context/" + encodeURIComponent(EVENTS[0].event_id)) + .respond(200, function() { + return { + start: "start_token0", + events_before: [], + event: THREAD_ROOT, + events_after: [], + end: "end_token0", + state: [], + }; + }); + + const timelinePromise = client.getEventTimeline(timelineSet, EVENTS[0].event_id); + await httpBackend.flushAllExpected(); + + const timeline = await timelinePromise; + expect(timeline).toBeUndefined(); + }); }); describe("getLatestTimeline", function() { From 8fd209de2e8b0ab6266b65da504be77a0c88cddd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 18:08:02 +0100 Subject: [PATCH 2/6] Fix issues around mixing up event timeline sets with /context/ API --- src/client.ts | 62 ++++++++++++++++++-------------- src/models/event-timeline-set.ts | 7 ++-- src/models/thread.ts | 2 +- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/client.ts b/src/client.ts index 304655eac3b..923c56c11f0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5245,6 +5245,7 @@ export class MatrixClient extends TypedEventEmitterIf the EventTimelineSet object already has the given event in its store, the * corresponding timeline will be returned. Otherwise, a /context request is * made, and used to construct an EventTimeline. + * If the event does not belong to this EventTimelineSet then undefined will be returned. * * @param {EventTimelineSet} timelineSet The timelineSet to look for the event in * @param {string} eventId The ID of the event to look for @@ -5252,7 +5253,7 @@ export class MatrixClient extends TypedEventEmitter { + public async getEventTimeline(timelineSet: EventTimelineSet, eventId: string): Promise { // don't allow any timeline support unless it's been enabled. if (!this.timelineSupport) { throw new Error("timeline support is disabled. Set the 'timelineSupport'" + @@ -5297,38 +5298,47 @@ export class MatrixClient extends TypedEventEmitter { this.timelineSet = new EventTimelineSet(this.room, { timelineSupport: true, pendingEvents: true, - }); + }, this.client, this); this.reEmitter = new TypedReEmitter(this); this.reEmitter.reEmit(this.timelineSet, [ From 8e25e5204bd9cd6bb3e9dff0ab1611e430e89303 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 18:18:33 +0100 Subject: [PATCH 3/6] Increase coverage --- .../matrix-client-event-timeline.spec.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index 43ae394f97f..99daeae5da0 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -559,7 +559,7 @@ describe("MatrixClient event timelines", function() { return { start: "start_token0", events_before: [], - event: THREAD_ROOT, + event: EVENTS[0], events_after: [], end: "end_token0", state: [], @@ -572,6 +572,32 @@ describe("MatrixClient event timelines", function() { const timeline = await timelinePromise; expect(timeline).toBeUndefined(); }); + + it("should return undefined when event is within a thread but timelineSet is not", async () => { + client.clientOpts.experimentalThreadSupport = true; + Thread.setServerSideSupport(true); + client.stopClient(); // we don't need the client to be syncing at this time + const room = client.getRoom(roomId); + const timelineSet = room.getTimelineSets()[0]; + + httpBackend.when("GET", "/rooms/!foo%3Abar/context/" + encodeURIComponent(THREAD_REPLY.event_id)) + .respond(200, function() { + return { + start: "start_token0", + events_before: [], + event: THREAD_REPLY, + events_after: [], + end: "end_token0", + state: [], + }; + }); + + const timelinePromise = client.getEventTimeline(timelineSet, THREAD_REPLY.event_id); + await httpBackend.flushAllExpected(); + + const timeline = await timelinePromise; + expect(timeline).toBeUndefined(); + }); }); describe("getLatestTimeline", function() { From 93c293b192dc5a28ffb3006292382ba8d4720bb8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 18:47:31 +0100 Subject: [PATCH 4/6] Increase coverage --- .../matrix-client-event-timeline.spec.js | 29 ++++++++++++++++++- src/client.ts | 8 ++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index 99daeae5da0..420fee6e588 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -1,5 +1,5 @@ import * as utils from "../test-utils/test-utils"; -import { EventTimeline, MatrixEvent } from "../../src/matrix"; +import { EventTimeline, Filter, MatrixEvent } from "../../src/matrix"; import { logger } from "../../src/logger"; import { TestClient } from "../TestClient"; import { Thread, THREAD_RELATION_TYPE } from "../../src/models/thread"; @@ -598,6 +598,33 @@ describe("MatrixClient event timelines", function() { const timeline = await timelinePromise; expect(timeline).toBeUndefined(); }); + + it("should should add lazy loading filter when requested", async () => { + client.clientOpts.lazyLoadMembers = true; + client.stopClient(); // we don't need the client to be syncing at this time + const room = client.getRoom(roomId); + const timelineSet = room.getTimelineSets()[0]; + + const req = httpBackend.when("GET", "/rooms/!foo%3Abar/context/" + encodeURIComponent(EVENTS[0].event_id)); + req.respond(200, function() { + return { + start: "start_token0", + events_before: [], + event: EVENTS[0], + events_after: [], + end: "end_token0", + state: [], + }; + }); + req.check((request) => { + expect(request.opts.qs.filter).toEqual(JSON.stringify(Filter.LAZY_LOADING_MESSAGES_FILTER)); + }); + + await Promise.all([ + client.getEventTimeline(timelineSet, EVENTS[0].event_id), + httpBackend.flushAllExpected(), + ]); + }); }); describe("getLatestTimeline", function() { diff --git a/src/client.ts b/src/client.ts index 923c56c11f0..242c1613048 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5304,13 +5304,13 @@ export class MatrixClient extends TypedEventEmitter Date: Wed, 8 Jun 2022 18:59:45 +0100 Subject: [PATCH 5/6] Better scope assertions --- src/client.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index 242c1613048..920f6ad57dc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5247,7 +5247,7 @@ export class MatrixClient extends TypedEventEmitter Date: Wed, 8 Jun 2022 23:04:43 +0100 Subject: [PATCH 6/6] Iterate PR --- src/client.ts | 2 +- src/models/event.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index 920f6ad57dc..c29578d20ac 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5306,7 +5306,7 @@ export class MatrixClient extends TypedEventEmitter