1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Make timelineSet public readonly

This commit is contained in:
Germain Souquet
2021-09-09 17:23:45 +01:00
parent 4d2286c5be
commit 33c9471112

View File

@@ -32,7 +32,7 @@ export class Thread extends EventEmitter {
* A reference to all the events ID at the bottom of the threads * A reference to all the events ID at the bottom of the threads
*/ */
public readonly tail = new Set<string>(); public readonly tail = new Set<string>();
private _timelineSet: EventTimelineSet; public readonly timelineSet: EventTimelineSet;
constructor( constructor(
events: MatrixEvent[] = [], events: MatrixEvent[] = [],
@@ -40,7 +40,7 @@ export class Thread extends EventEmitter {
public readonly client: MatrixClient, public readonly client: MatrixClient,
) { ) {
super(); super();
this._timelineSet = new EventTimelineSet(room, { this.timelineSet = new EventTimelineSet(room, {
unstableClientRelationAggregation: true, unstableClientRelationAggregation: true,
timelineSupport: true, timelineSupport: true,
}); });
@@ -54,7 +54,7 @@ export class Thread extends EventEmitter {
* @param event The event to add * @param event The event to add
*/ */
public async addEvent(event: MatrixEvent): Promise<void> { public async addEvent(event: MatrixEvent): Promise<void> {
if (this._timelineSet.findEventById(event.getId()) || event.status !== null) { if (this.timelineSet.findEventById(event.getId()) || event.status !== null) {
return; return;
} }
@@ -63,19 +63,17 @@ export class Thread extends EventEmitter {
} }
this.tail.add(event.getId()); this.tail.add(event.getId());
if (!event.replyEventId || !this._timelineSet.findEventById(event.replyEventId)) { if (!event.replyEventId || !this.timelineSet.findEventById(event.replyEventId)) {
this.root = event.getId(); this.root = event.getId();
} }
event.setThread(this); event.setThread(this);
this._timelineSet.addLiveEvent(event); this.timelineSet.addLiveEvent(event);
if (this.ready) { if (this.ready) {
this.client.decryptEventIfNeeded(event, {}); this.client.decryptEventIfNeeded(event, {});
this.emit("Thread.update", this);
} else {
this.emit("Thread.update", this);
} }
this.emit("Thread.update", this);
} }
/** /**
@@ -105,7 +103,7 @@ export class Thread extends EventEmitter {
private async decryptEvents(): Promise<void> { private async decryptEvents(): Promise<void> {
await Promise.allSettled( await Promise.allSettled(
Array.from(this._timelineSet.getLiveTimeline().getEvents()).map(event => { Array.from(this.timelineSet.getLiveTimeline().getEvents()).map(event => {
return this.client.decryptEventIfNeeded(event, {}); return this.client.decryptEventIfNeeded(event, {});
}), }),
); );
@@ -127,7 +125,7 @@ export class Thread extends EventEmitter {
* Finds an event by ID in the current thread * Finds an event by ID in the current thread
*/ */
public findEventById(eventId: string) { public findEventById(eventId: string) {
return this._timelineSet.findEventById(eventId); return this.timelineSet.findEventById(eventId);
} }
/** /**
@@ -169,13 +167,6 @@ export class Thread extends EventEmitter {
return participants; return participants;
} }
/**
* A read-only getter to access the timeline set
*/
public get timelineSet(): EventTimelineSet {
return this._timelineSet;
}
/** /**
* A getter for the last event added to the thread * A getter for the last event added to the thread
*/ */
@@ -185,7 +176,7 @@ export class Thread extends EventEmitter {
} }
public get events(): MatrixEvent[] { public get events(): MatrixEvent[] {
return this._timelineSet.getLiveTimeline().getEvents(); return this.timelineSet.getLiveTimeline().getEvents();
} }
public merge(thread: Thread): void { public merge(thread: Thread): void {
@@ -194,4 +185,8 @@ export class Thread extends EventEmitter {
}); });
this.events.forEach(event => event.setThread(this)); this.events.forEach(event => event.setThread(this));
} }
public has(eventId: string): boolean {
return this.timelineSet.findEventById(eventId) instanceof MatrixEvent;
}
} }