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

View File

@@ -1287,8 +1287,8 @@ export class Room extends EventEmitter {
events.unshift(rootEvent); events.unshift(rootEvent);
} }
thread = new Thread(events, this, this.client); thread = new Thread(events, this, this.client);
this.reEmitter.reEmit(thread, [ThreadEvent.Update, ThreadEvent.Ready]);
this.threads.set(thread.id, thread); this.threads.set(thread.id, thread);
this.reEmitter.reEmit(thread, [ThreadEvent.Update, ThreadEvent.Ready]);
this.emit(ThreadEvent.New, thread); this.emit(ThreadEvent.New, thread);
} }
this.emit(ThreadEvent.Update, 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 * A reference to all the events ID at the bottom of the threads
*/ */
public readonly timelineSet: EventTimelineSet; public readonly timelineSet;
constructor( constructor(
events: MatrixEvent[] = [], events: MatrixEvent[] = [],
@@ -46,9 +46,14 @@ export class Thread extends EventEmitter {
public readonly client: MatrixClient, public readonly client: MatrixClient,
) { ) {
super(); 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, unstableClientRelationAggregation: true,
timelineSupport: true, timelineSupport: true,
pendingEvents: false,
}); });
events.forEach(event => this.addEvent(event)); events.forEach(event => this.addEvent(event));
} }
@@ -93,14 +98,6 @@ export class Thread extends EventEmitter {
this.emit(ThreadEvent.Update, this); 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 * Finds an event by ID in the current thread
*/ */