diff --git a/src/models/event-timeline-set.ts b/src/models/event-timeline-set.ts index b4333e52c..10cfb8d5d 100644 --- a/src/models/event-timeline-set.ts +++ b/src/models/event-timeline-set.ts @@ -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; @@ -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 opts.pendingEventOrdering was not 'detached' */ public getPendingEvents(): MatrixEvent[] { - if (!this.room) { + if (!this.room || !this.displayPendingEvents) { return []; } diff --git a/src/models/room.ts b/src/models/room.ts index 38a6a7311..d2c46a3fa 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -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); diff --git a/src/models/thread.ts b/src/models/thread.ts index fbad42c2f..a1150d494 100644 --- a/src/models/thread.ts +++ b/src/models/thread.ts @@ -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 { - 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 */