Better safeguard around timeline refresh
This commit is contained in:
parent
b48e921699
commit
9897307c79
|
@ -164,9 +164,7 @@ public struct TimelineView: View {
|
|||
case .active:
|
||||
if wasBackgrounded {
|
||||
wasBackgrounded = false
|
||||
Task {
|
||||
await viewModel.fetchNewestStatuses()
|
||||
}
|
||||
viewModel.refreshTimeline()
|
||||
}
|
||||
case .background:
|
||||
wasBackgrounded = true
|
||||
|
|
|
@ -157,11 +157,19 @@ extension TimelineViewModel {
|
|||
|
||||
extension TimelineViewModel: StatusesFetcher {
|
||||
func pullToRefresh() async {
|
||||
timelineTask?.cancel()
|
||||
if !timeline.supportNewestPagination {
|
||||
await reset()
|
||||
}
|
||||
await fetchNewestStatuses()
|
||||
}
|
||||
|
||||
func refreshTimeline() {
|
||||
timelineTask?.cancel()
|
||||
timelineTask = Task {
|
||||
await fetchNewestStatuses()
|
||||
}
|
||||
}
|
||||
|
||||
func fetchNewestStatuses() async {
|
||||
guard let client else { return }
|
||||
|
@ -304,7 +312,10 @@ extension TimelineViewModel: StatusesFetcher {
|
|||
|
||||
// We trigger a new fetch so we can get the next new statuses if any.
|
||||
// If none, it'll stop there.
|
||||
if !Task.isCancelled, let latest = await datasource.get().first {
|
||||
// Only do that in the context of the home timeline as other don't worth catching up that much.
|
||||
if timeline == .home,
|
||||
!Task.isCancelled,
|
||||
let latest = await datasource.get().first {
|
||||
try await fetchNewPagesFrom(latestStatus: latest, client: client)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue