From 67eb3a0527e125e49dec1f257b303cb9176d1872 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Mon, 22 Jan 2024 16:04:02 +0100 Subject: [PATCH] Make `timeline` a getter --- spec/unit/room.spec.ts | 8 ++++---- src/models/read-receipt.ts | 2 +- src/models/room.ts | 21 +++++++++++---------- src/models/thread.ts | 16 ++++++++++------ 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index 11eaf6980d5..4d64e4df54d 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -1460,7 +1460,7 @@ describe("Room", function () { it("should reset the unread count when our non-synthetic receipt points to the latest event", () => { // Given a room with 2 events, and an unread count set. room.client.isInitialSyncComplete = jest.fn().mockReturnValue(true); - room.timeline = [event1, event2]; + jest.spyOn(room, "timeline", "get").mockReturnValue([event1, event2]); room.setUnread(NotificationCountType.Total, 45); room.setUnread(NotificationCountType.Highlight, 57); // Sanity check: @@ -1479,7 +1479,7 @@ describe("Room", function () { it("should not reset the unread count when someone else's receipt points to the latest event", () => { // Given a room with 2 events, and an unread count set. room.client.isInitialSyncComplete = jest.fn().mockReturnValue(true); - room.timeline = [event1, event2]; + jest.spyOn(room, "timeline", "get").mockReturnValue([event1, event2]); room.setUnread(NotificationCountType.Total, 45); room.setUnread(NotificationCountType.Highlight, 57); // Sanity check: @@ -1498,7 +1498,7 @@ describe("Room", function () { it("should not reset the unread count when our non-synthetic receipt points to an earlier event", () => { // Given a room with 2 events, and an unread count set. room.client.isInitialSyncComplete = jest.fn().mockReturnValue(true); - room.timeline = [event1, event2]; + jest.spyOn(room, "timeline", "get").mockReturnValue([event1, event2]); room.setUnread(NotificationCountType.Total, 45); room.setUnread(NotificationCountType.Highlight, 57); // Sanity check: @@ -1517,7 +1517,7 @@ describe("Room", function () { it("should not reset the unread count when our a synthetic receipt points to the latest event", () => { // Given a room with 2 events, and an unread count set. room.client.isInitialSyncComplete = jest.fn().mockReturnValue(true); - room.timeline = [event1, event2]; + jest.spyOn(room, "timeline", "get").mockReturnValue([event1, event2]); room.setUnread(NotificationCountType.Total, 45); room.setUnread(NotificationCountType.Highlight, 57); // Sanity check: diff --git a/src/models/read-receipt.ts b/src/models/read-receipt.ts index 08f0f4909a1..8dd743e7c40 100644 --- a/src/models/read-receipt.ts +++ b/src/models/read-receipt.ts @@ -79,7 +79,7 @@ export abstract class ReadReceipt< private receiptCacheByEventId: ReceiptCache = new Map(); public abstract getUnfilteredTimelineSet(): EventTimelineSet; - public abstract timeline: MatrixEvent[]; + public abstract get timeline(): MatrixEvent[]; /** * Gets the latest receipt for a given user in the room diff --git a/src/models/room.ts b/src/models/room.ts index 3d1f727da67..260d4c59f74 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -381,13 +381,6 @@ export class Room extends ReadReceipt { * The room summary. */ public summary: RoomSummary | null = null; - /** - * The live event timeline for this room, with the oldest event at index 0. - * - * @deprecated Present for backwards compatibility. - * Use getLiveTimeline().getEvents() instead - */ - public timeline!: MatrixEvent[]; /** * oldState The state of the room at the time of the oldest event in the live timeline. * @@ -793,6 +786,16 @@ export class Room extends ReadReceipt { return this.getUnfilteredTimelineSet().getLiveTimeline(); } + /** + * The live event timeline for this room, with the oldest event at index 0. + * + * @deprecated Present for backwards compatibility. + * Use getLiveTimeline().getEvents() instead + */ + public get timeline(): MatrixEvent[] { + return this.getLiveTimeline().getEvents(); + } + /** * Get the timestamp of the last message in the room * @@ -1221,11 +1224,9 @@ export class Room extends ReadReceipt { const previousOldState = this.oldState; const previousCurrentState = this.currentState; - // maintain this.timeline as a reference to the live timeline, - // and this.oldState and this.currentState as references to the + // maintain this.oldState and this.currentState as references to the // state at the start and end of that timeline. These are more // for backwards-compatibility than anything else. - this.timeline = this.getLiveTimeline().getEvents(); this.oldState = this.getLiveTimeline().getState(EventTimeline.BACKWARDS)!; this.currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS)!; diff --git a/src/models/thread.ts b/src/models/thread.ts index 96cea941b3c..32fd0621c28 100644 --- a/src/models/thread.ts +++ b/src/models/thread.ts @@ -84,7 +84,6 @@ export class Thread extends ReadReceipt