From 6f6346d5c38de3bbcfdf5500e3a30fa3eede14ed Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 2 Mar 2021 19:29:55 +0100 Subject: [PATCH] detect when hitting beginning of timeline when loading timeline --- src/domain/session/room/timeline/TimelineViewModel.js | 4 ++-- src/matrix/room/timeline/Timeline.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index b40a6dcb..a5dcee07 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -55,8 +55,8 @@ export class TimelineViewModel extends ViewModel { if (firstTile.shape === "gap") { return await firstTile.fill(); } else { - await this._timeline.loadAtTop(10); - return false; + const topReached = await this._timeline.loadAtTop(10); + return topReached; } } diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 1b7c8a18..a737728c 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -74,13 +74,19 @@ export class Timeline { } // tries to prepend `amount` entries to the `entries` list. + /** + * [loadAtTop description] + * @param {[type]} amount [description] + * @return {boolean} true if the top of the timeline has been reached + * + */ async loadAtTop(amount) { if (this._disposables.isDisposed) { - return; + return true; } const firstEventEntry = this._remoteEntries.array.find(e => !!e.eventType); if (!firstEventEntry) { - return; + return true; } const readerRequest = this._disposables.track(this._timelineReader.readFrom( firstEventEntry.asEventKey(), @@ -90,6 +96,7 @@ export class Timeline { try { const entries = await readerRequest.complete(); this._remoteEntries.setManySorted(entries); + return entries.length < amount; } finally { this._disposables.disposeTracked(readerRequest); }