detect when hitting beginning of timeline when loading timeline

This commit is contained in:
Bruno Windels 2021-03-02 19:29:55 +01:00
parent e1eb313ffa
commit 6f6346d5c3
2 changed files with 11 additions and 4 deletions

View File

@ -55,8 +55,8 @@ export class TimelineViewModel extends ViewModel {
if (firstTile.shape === "gap") { if (firstTile.shape === "gap") {
return await firstTile.fill(); return await firstTile.fill();
} else { } else {
await this._timeline.loadAtTop(10); const topReached = await this._timeline.loadAtTop(10);
return false; return topReached;
} }
} }

View File

@ -74,13 +74,19 @@ export class Timeline {
} }
// tries to prepend `amount` entries to the `entries` list. // 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) { async loadAtTop(amount) {
if (this._disposables.isDisposed) { if (this._disposables.isDisposed) {
return; return true;
} }
const firstEventEntry = this._remoteEntries.array.find(e => !!e.eventType); const firstEventEntry = this._remoteEntries.array.find(e => !!e.eventType);
if (!firstEventEntry) { if (!firstEventEntry) {
return; return true;
} }
const readerRequest = this._disposables.track(this._timelineReader.readFrom( const readerRequest = this._disposables.track(this._timelineReader.readFrom(
firstEventEntry.asEventKey(), firstEventEntry.asEventKey(),
@ -90,6 +96,7 @@ export class Timeline {
try { try {
const entries = await readerRequest.complete(); const entries = await readerRequest.complete();
this._remoteEntries.setManySorted(entries); this._remoteEntries.setManySorted(entries);
return entries.length < amount;
} finally { } finally {
this._disposables.disposeTracked(readerRequest); this._disposables.disposeTracked(readerRequest);
} }