Don't load new pages if the timeline changed

This commit is contained in:
Thomas Ricouard 2023-02-16 07:28:52 +01:00
parent 3843d18f2f
commit 9f894858ae

View file

@ -221,6 +221,7 @@ extension TimelineViewModel: StatusesFetcher {
// Fetch pages from the top most status of the tomeline.
private func fetchNewPagesFrom(latestStatus: Status, client _: Client) async throws {
canStreamEvents = false
let initialTimeline = timeline
var newStatuses: [Status] = await fetchNewPages(minId: latestStatus.id, maxPages: 10)
// Dedup statuses, a status with the same id could have been streamed in.
@ -248,6 +249,12 @@ extension TimelineViewModel: StatusesFetcher {
return
}
// As this is a long runnign task we need to ensure that the user didn't changed the timeline filter.
guard initialTimeline == timeline else {
canStreamEvents = true
return
}
// Keep track of the top most status, so we can scroll back to it after view update.
let topStatusId = statuses.first?.id