From a4cd40c2f8874daad21bf07793266ea0e65ad62a Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 5 Nov 2021 17:25:29 +0530 Subject: [PATCH 1/2] Keep filling gap until sibling changes --- .../session/room/timeline/tiles/GapTile.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index 1db2100e..2efe9712 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -23,6 +23,7 @@ export class GapTile extends SimpleTile { this._loading = false; this._error = null; this._isAtTop = true; + this._siblingChanged = false; } async fill() { @@ -42,11 +43,19 @@ export class GapTile extends SimpleTile { this._loading = false; this.emitChange("isLoading"); } + return true; } + return false; } - notifyVisible() { - this.fill(); + async notifyVisible() { + let depth = 0; + let result; + do { + result = await this.fill(); + depth = depth + 1; + } while (depth < 10 && !this._siblingChanged && result && !this.isDisposed) + this._siblingChanged = false; } get isAtTop() { @@ -60,6 +69,11 @@ export class GapTile extends SimpleTile { this._isAtTop = isAtTop; this.emitChange("isAtTop"); } + this._siblingChanged = true; + } + + updateNextSibling() { + this._siblingChanged = true; } updateEntry(entry, params) { From 781147bf0e453557eb499bc0da238568792b5936 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 5 Nov 2021 15:42:07 +0100 Subject: [PATCH 2/2] add some comments and rename for clarity --- src/domain/session/room/timeline/tiles/GapTile.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index 2efe9712..c1fed69f 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -49,13 +49,15 @@ export class GapTile extends SimpleTile { } async notifyVisible() { + // we do (up to 10) backfills while no new tiles have been added to the timeline + // because notifyVisible won't be called again until something gets added to the timeline let depth = 0; - let result; - do { - result = await this.fill(); - depth = depth + 1; - } while (depth < 10 && !this._siblingChanged && result && !this.isDisposed) + let canFillMore; this._siblingChanged = false; + do { + canFillMore = await this.fill(); + depth = depth + 1; + } while (depth < 10 && !this._siblingChanged && canFillMore && !this.isDisposed); } get isAtTop() { @@ -73,6 +75,9 @@ export class GapTile extends SimpleTile { } updateNextSibling() { + // if the sibling of the gap changed while calling room.fill(), + // we intepret this as at least one new tile has been added to + // the timeline. See notifyVisible why this is important. this._siblingChanged = true; }