From eb6a054dac97ba3629b3caabd7d68b84212e0a97 Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Tue, 11 Oct 2022 14:21:50 +0200 Subject: [PATCH] Disable promise short circuiting for now --- src/timeline-window.ts | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/timeline-window.ts b/src/timeline-window.ts index 0172eae40fa..538eaa1a534 100644 --- a/src/timeline-window.ts +++ b/src/timeline-window.ts @@ -99,7 +99,7 @@ export class TimelineWindow { * * @return {Promise} */ - public load(initialEventId?: string, initialWindowSize = 20): Promise { + public async load(initialEventId?: string, initialWindowSize = 20): Promise { // given an EventTimeline, find the event we were looking for, and initialise our // fields so that the event in question is in the middle of the window. const initFields = (timeline: EventTimeline) => { @@ -127,20 +127,11 @@ export class TimelineWindow { // We avoid delaying the resolution of the promise by a reactor tick if we already have the data we need, // which is important to keep room-switching feeling snappy. - if (initialEventId) { - const timeline = this.timelineSet.getTimelineForEvent(initialEventId); - if (timeline) { - // hot-path optimization to save a reactor tick by replicating the sync check getTimelineForEvent does. - initFields(timeline); - return Promise.resolve(); - } + const timeline = initialEventId + ? await this.client.getEventTimeline(this.timelineSet, initialEventId) + : this.timelineSet.getLiveTimeline(); - return this.client.getEventTimeline(this.timelineSet, initialEventId).then(initFields); - } else { - const tl = this.timelineSet.getLiveTimeline(); - initFields(tl); - return Promise.resolve(); - } + return initFields(timeline); } /** @@ -257,7 +248,7 @@ export class TimelineWindow { * @return {Promise} Resolves to a boolean which is true if more events * were successfully retrieved. */ - public paginate( + public async paginate( direction: Direction, size: number, makeRequest = true, @@ -269,7 +260,7 @@ export class TimelineWindow { if (!tl) { debuglog("TimelineWindow: no timeline yet"); - return Promise.resolve(false); + return false; } if (tl.pendingPaginate) { @@ -278,20 +269,20 @@ export class TimelineWindow { // try moving the cap if (this.extend(direction, size)) { - return Promise.resolve(true); + return true; } if (!makeRequest || requestLimit === 0) { // todo: should we return something different to indicate that there // might be more events out there, but we haven't found them yet? - return Promise.resolve(false); + return false; } // try making a pagination request const token = tl.timeline.getPaginationToken(direction); if (!token) { debuglog("TimelineWindow: no token"); - return Promise.resolve(false); + return false; } debuglog("TimelineWindow: starting request");