mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-23 14:28:15 +00:00
Better safeguard around timeline refresh
This commit is contained in:
parent
b48e921699
commit
9897307c79
2 changed files with 13 additions and 4 deletions
|
@ -164,9 +164,7 @@ public struct TimelineView: View {
|
||||||
case .active:
|
case .active:
|
||||||
if wasBackgrounded {
|
if wasBackgrounded {
|
||||||
wasBackgrounded = false
|
wasBackgrounded = false
|
||||||
Task {
|
viewModel.refreshTimeline()
|
||||||
await viewModel.fetchNewestStatuses()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case .background:
|
case .background:
|
||||||
wasBackgrounded = true
|
wasBackgrounded = true
|
||||||
|
|
|
@ -157,12 +157,20 @@ extension TimelineViewModel {
|
||||||
|
|
||||||
extension TimelineViewModel: StatusesFetcher {
|
extension TimelineViewModel: StatusesFetcher {
|
||||||
func pullToRefresh() async {
|
func pullToRefresh() async {
|
||||||
|
timelineTask?.cancel()
|
||||||
if !timeline.supportNewestPagination {
|
if !timeline.supportNewestPagination {
|
||||||
await reset()
|
await reset()
|
||||||
}
|
}
|
||||||
await fetchNewestStatuses()
|
await fetchNewestStatuses()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshTimeline() {
|
||||||
|
timelineTask?.cancel()
|
||||||
|
timelineTask = Task {
|
||||||
|
await fetchNewestStatuses()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func fetchNewestStatuses() async {
|
func fetchNewestStatuses() async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
|
@ -304,7 +312,10 @@ 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 {
|
// 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)
|
try await fetchNewPagesFrom(latestStatus: latest, client: client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue