forked from mystiq/hydrogen-web
detect when hitting beginning of timeline when loading timeline
This commit is contained in:
parent
e1eb313ffa
commit
6f6346d5c3
2 changed files with 11 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue