mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-27 02:14:45 +00:00
StatusDataController: Update on timeline fetch
This commit is contained in:
parent
3c047c9bb5
commit
d2d297f019
1 changed files with 6 additions and 2 deletions
|
@ -217,6 +217,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
offset: 0))
|
offset: 0))
|
||||||
|
|
||||||
ReblogCache.shared.removeDuplicateReblogs(&statuses)
|
ReblogCache.shared.removeDuplicateReblogs(&statuses)
|
||||||
|
StatusDataControllerProvider.shared.updateDataControllers(for: statuses, client: client)
|
||||||
|
|
||||||
await datasource.set(statuses)
|
await datasource.set(statuses)
|
||||||
await cacheHome()
|
await cacheHome()
|
||||||
|
@ -228,7 +229,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch pages from the top most status of the tomeline.
|
// Fetch pages from the top most status of the tomeline.
|
||||||
private func fetchNewPagesFrom(latestStatus: Status, client _: Client) async throws {
|
private func fetchNewPagesFrom(latestStatus: Status, client: Client) async throws {
|
||||||
canStreamEvents = false
|
canStreamEvents = false
|
||||||
let initialTimeline = timeline
|
let initialTimeline = timeline
|
||||||
var newStatuses: [Status] = await fetchNewPages(minId: latestStatus.id, maxPages: 10)
|
var newStatuses: [Status] = await fetchNewPages(minId: latestStatus.id, maxPages: 10)
|
||||||
|
@ -240,6 +241,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
||||||
|
StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client)
|
||||||
|
|
||||||
// If no new statuses, resume streaming and exit.
|
// If no new statuses, resume streaming and exit.
|
||||||
guard !newStatuses.isEmpty else {
|
guard !newStatuses.isEmpty else {
|
||||||
|
@ -302,7 +304,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
|
|
||||||
// We trigger a new fetch so we can get the next new statuses if any.
|
// We trigger a new fetch so we can get the next new statuses if any.
|
||||||
// If none, it'll stop there.
|
// If none, it'll stop there.
|
||||||
if !Task.isCancelled, let latest = await datasource.get().first, let client {
|
if !Task.isCancelled, let latest = await datasource.get().first {
|
||||||
try await fetchNewPagesFrom(latestStatus: latest, client: client)
|
try await fetchNewPagesFrom(latestStatus: latest, client: client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,6 +328,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
pagesLoaded += 1
|
pagesLoaded += 1
|
||||||
|
|
||||||
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
||||||
|
StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client)
|
||||||
|
|
||||||
allStatuses.insert(contentsOf: newStatuses, at: 0)
|
allStatuses.insert(contentsOf: newStatuses, at: 0)
|
||||||
latestMinId = newStatuses.first?.id ?? ""
|
latestMinId = newStatuses.first?.id ?? ""
|
||||||
|
@ -349,6 +352,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
ReblogCache.shared.removeDuplicateReblogs(&newStatuses)
|
||||||
|
|
||||||
await datasource.append(contentOf: newStatuses)
|
await datasource.append(contentOf: newStatuses)
|
||||||
|
StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client)
|
||||||
|
|
||||||
statusesState = await .display(statuses: datasource.get(),
|
statusesState = await .display(statuses: datasource.get(),
|
||||||
nextPageState: newStatuses.count < 20 ? .none : .hasNextPage)
|
nextPageState: newStatuses.count < 20 ? .none : .hasNextPage)
|
||||||
|
|
Loading…
Reference in a new issue