From 9f894858ae8edb1bc2d53ace39bf970ffc41883f Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 16 Feb 2023 07:28:52 +0100 Subject: [PATCH] Don't load new pages if the timeline changed --- Packages/Timeline/Sources/Timeline/TimelineViewModel.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift index 37563c65..21769fc2 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineViewModel.swift @@ -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. @@ -247,6 +248,12 @@ extension TimelineViewModel: StatusesFetcher { canStreamEvents = true 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