1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-04 05:02:41 +03:00

Add explicit options to disable pending events (#1993)

This commit is contained in:
Germain
2021-10-22 09:23:12 +01:00
committed by GitHub
parent 0385f265e8
commit 0c47e27f9f
3 changed files with 12 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ interface IOpts {
timelineSupport?: boolean;
filter?: Filter;
unstableClientRelationAggregation?: boolean;
pendingEvents?: boolean;
}
export enum DuplicateStrategy {
@@ -54,6 +55,7 @@ export enum DuplicateStrategy {
export class EventTimelineSet extends EventEmitter {
private readonly timelineSupport: boolean;
private unstableClientRelationAggregation: boolean;
private displayPendingEvents: boolean;
private liveTimeline: EventTimeline;
private timelines: EventTimeline[];
private _eventIdToTimeline: Record<string, EventTimeline>;
@@ -102,6 +104,7 @@ export class EventTimelineSet extends EventEmitter {
this.timelineSupport = Boolean(opts.timelineSupport);
this.liveTimeline = new EventTimeline(this);
this.unstableClientRelationAggregation = !!opts.unstableClientRelationAggregation;
this.displayPendingEvents = opts.pendingEvents !== false;
// just a list - *not* ordered.
this.timelines = [this.liveTimeline];
@@ -151,7 +154,7 @@ export class EventTimelineSet extends EventEmitter {
* @throws If <code>opts.pendingEventOrdering</code> was not 'detached'
*/
public getPendingEvents(): MatrixEvent[] {
if (!this.room) {
if (!this.room || !this.displayPendingEvents) {
return [];
}

View File

@@ -1287,8 +1287,8 @@ export class Room extends EventEmitter {
events.unshift(rootEvent);
}
thread = new Thread(events, this, this.client);
this.reEmitter.reEmit(thread, [ThreadEvent.Update, ThreadEvent.Ready]);
this.threads.set(thread.id, thread);
this.reEmitter.reEmit(thread, [ThreadEvent.Update, ThreadEvent.Ready]);
this.emit(ThreadEvent.New, thread);
}
this.emit(ThreadEvent.Update, thread);

View File

@@ -38,7 +38,7 @@ export class Thread extends EventEmitter {
/**
* A reference to all the events ID at the bottom of the threads
*/
public readonly timelineSet: EventTimelineSet;
public readonly timelineSet;
constructor(
events: MatrixEvent[] = [],
@@ -46,9 +46,14 @@ export class Thread extends EventEmitter {
public readonly client: MatrixClient,
) {
super();
this.timelineSet = new EventTimelineSet(null, {
if (events.length === 0) {
throw new Error("Can't create an empty thread");
}
this.timelineSet = new EventTimelineSet(this.room, {
unstableClientRelationAggregation: true,
timelineSupport: true,
pendingEvents: false,
});
events.forEach(event => this.addEvent(event));
}
@@ -93,14 +98,6 @@ export class Thread extends EventEmitter {
this.emit(ThreadEvent.Update, this);
}
private async decryptEvents(): Promise<void> {
await Promise.allSettled(
Array.from(this.timelineSet.getLiveTimeline().getEvents()).map(event => {
return this.client.decryptEventIfNeeded(event, {});
}),
);
}
/**
* Finds an event by ID in the current thread
*/