Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timeline a getter #4022

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/models/read-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,6 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
* 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.
*
Expand Down Expand Up @@ -793,6 +786,16 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
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
*
Expand Down Expand Up @@ -1221,11 +1224,9 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
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)!;

Expand Down
16 changes: 10 additions & 6 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
* A reference to all the events ID at the bottom of the threads
*/
public readonly timelineSet: EventTimelineSet;
public timeline: MatrixEvent[] = [];

private _currentUserParticipated = false;

Expand Down Expand Up @@ -323,7 +322,6 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
fromCache: false,
roomState: this.roomState,
});
this.timeline = this.events;
}
}

Expand All @@ -350,9 +348,6 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
return;
}
this.timelineSet.insertEventIntoTimeline(event, this.liveTimeline, this.roomState);

// As far as we know, timeline should always be the same as events
this.timeline = this.events;
}

public addEvents(events: MatrixEvent[], toStartOfTimeline: boolean): void {
Expand Down Expand Up @@ -483,7 +478,6 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
this.setEventMetadata(event);
await this.fetchEditsWhereNeeded(event);
}
this.timeline = this.events;
}

/**
Expand Down Expand Up @@ -727,6 +721,16 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
return this.lastPendingEvent ?? this.lastEvent ?? this.lastReply();
}

/**
* The live event timeline for this thread.
* @deprecated Present for backwards compatibility.
* Use this.events instead
* @returns The live event timeline for this thread.
*/
public get timeline(): MatrixEvent[] {
return this.events;
}

public get events(): MatrixEvent[] {
return this.liveTimeline.getEvents();
}
Expand Down
Loading