mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
detect when hitting beginning of timeline when loading timeline
This commit is contained in:
parent
e1eb313ffa
commit
6f6346d5c3
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user