Fix #1376 for real
This commit is contained in:
parent
3229bf0cb5
commit
3a3cae21b0
|
@ -46,7 +46,6 @@ struct TimelineUnreadStatusesView: View {
|
||||||
if observer.isLoadingNewStatuses {
|
if observer.isLoadingNewStatuses {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.tint(theme.labelColor)
|
.tint(theme.labelColor)
|
||||||
.transition(.scale)
|
|
||||||
}
|
}
|
||||||
if observer.pendingStatusesCount > 0 {
|
if observer.pendingStatusesCount > 0 {
|
||||||
Text("\(observer.pendingStatusesCount)")
|
Text("\(observer.pendingStatusesCount)")
|
||||||
|
|
|
@ -137,14 +137,14 @@ import SwiftUI
|
||||||
await datasource.insert(newStatus, at: 0)
|
await datasource.insert(newStatus, at: 0)
|
||||||
await cache()
|
await cache()
|
||||||
StatusDataControllerProvider.shared.updateDataControllers(for: [event.status], client: client)
|
StatusDataControllerProvider.shared.updateDataControllers(for: [event.status], client: client)
|
||||||
let statuses = await datasource.get()
|
let statuses = await datasource.getFiltered()
|
||||||
withAnimation {
|
withAnimation {
|
||||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||||
}
|
}
|
||||||
} else if let event = event as? StreamEventDelete {
|
} else if let event = event as? StreamEventDelete {
|
||||||
await datasource.remove(event.status)
|
await datasource.remove(event.status)
|
||||||
await cache()
|
await cache()
|
||||||
let statuses = await datasource.get()
|
let statuses = await datasource.getFiltered()
|
||||||
withAnimation {
|
withAnimation {
|
||||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,8 @@ import SwiftUI
|
||||||
if let originalIndex = await datasource.indexOf(statusId: event.status.id) {
|
if let originalIndex = await datasource.indexOf(statusId: event.status.id) {
|
||||||
StatusDataControllerProvider.shared.updateDataControllers(for: [event.status], client: client)
|
StatusDataControllerProvider.shared.updateDataControllers(for: [event.status], client: client)
|
||||||
await datasource.replace(event.status, at: originalIndex)
|
await datasource.replace(event.status, at: originalIndex)
|
||||||
let statuses = await datasource.get()
|
|
||||||
await cache()
|
await cache()
|
||||||
|
let statuses = await datasource.getFiltered()
|
||||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
!UserPreferences.shared.fastRefreshEnabled
|
!UserPreferences.shared.fastRefreshEnabled
|
||||||
{
|
{
|
||||||
await datasource.set(cachedStatuses)
|
await datasource.set(cachedStatuses)
|
||||||
let statuses = await datasource.get()
|
let statuses = await datasource.getFiltered()
|
||||||
if let latestSeenId = await cache.getLatestSeenStatus(for: client, filter: timeline.id)?.first,
|
if let latestSeenId = await cache.getLatestSeenStatus(for: client, filter: timeline.id)?.first,
|
||||||
let index = await datasource.indexOf(statusId: latestSeenId),
|
let index = await datasource.indexOf(statusId: latestSeenId),
|
||||||
index > 0
|
index > 0
|
||||||
|
@ -287,8 +287,8 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
StatusDataControllerProvider.shared.updateDataControllers(for: statuses, client: client)
|
StatusDataControllerProvider.shared.updateDataControllers(for: statuses, client: client)
|
||||||
|
|
||||||
await datasource.set(statuses)
|
await datasource.set(statuses)
|
||||||
statuses = await datasource.get()
|
|
||||||
await cache()
|
await cache()
|
||||||
|
statuses = await datasource.getFiltered()
|
||||||
|
|
||||||
withAnimation {
|
withAnimation {
|
||||||
statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||||
|
@ -336,7 +336,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of the top most status, so we can scroll back to it after view update.
|
// Keep track of the top most status, so we can scroll back to it after view update.
|
||||||
let topStatus = await datasource.get().first
|
let topStatus = await datasource.getFiltered().first
|
||||||
|
|
||||||
// Insert new statuses in internal datasource.
|
// Insert new statuses in internal datasource.
|
||||||
await datasource.insert(contentOf: newStatuses, at: 0)
|
await datasource.insert(contentOf: newStatuses, at: 0)
|
||||||
|
@ -351,7 +351,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
// We need to update the statuses state, and then scroll to the previous top most status.
|
// We need to update the statuses state, and then scroll to the previous top most status.
|
||||||
if let topStatus, visibileStatuses.contains(where: { $0.id == topStatus.id}), scrollToTopVisible {
|
if let topStatus, visibileStatuses.contains(where: { $0.id == topStatus.id}), scrollToTopVisible {
|
||||||
pendingStatusesObserver.disableUpdate = true
|
pendingStatusesObserver.disableUpdate = true
|
||||||
let statuses = await datasource.get()
|
let statuses = await datasource.getFiltered()
|
||||||
statusesState = .display(statuses: statuses,
|
statusesState = .display(statuses: statuses,
|
||||||
nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||||
scrollToIndexAnimated = false
|
scrollToIndexAnimated = false
|
||||||
|
@ -362,7 +362,7 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This will keep the scroll position (if the list is scrolled) and prepend statuses on the top.
|
// This will keep the scroll position (if the list is scrolled) and prepend statuses on the top.
|
||||||
let statuses = await datasource.get()
|
let statuses = await datasource.getFiltered()
|
||||||
withAnimation {
|
withAnimation {
|
||||||
statusesState = .display(statuses: statuses,
|
statusesState = .display(statuses: statuses,
|
||||||
nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||||
|
@ -415,19 +415,20 @@ extension TimelineViewModel: StatusesFetcher {
|
||||||
func fetchNextPage() async {
|
func fetchNextPage() async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
guard let lastId = await datasource.get().last?.id else { return }
|
let statuses = await datasource.get()
|
||||||
statusesState = await .display(statuses: datasource.get(), nextPageState: .loadingNextPage)
|
guard let lastId = statuses.last?.id else { return }
|
||||||
|
statusesState = await .display(statuses: datasource.getFiltered(), nextPageState: .loadingNextPage)
|
||||||
var newStatuses: [Status] = try await client.get(endpoint: timeline.endpoint(sinceId: nil,
|
var newStatuses: [Status] = try await client.get(endpoint: timeline.endpoint(sinceId: nil,
|
||||||
maxId: lastId,
|
maxId: lastId,
|
||||||
minId: nil,
|
minId: nil,
|
||||||
offset: datasource.get().count))
|
offset: statuses.count))
|
||||||
|
|
||||||
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)
|
StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client)
|
||||||
|
|
||||||
statusesState = await .display(statuses: datasource.get(),
|
statusesState = await .display(statuses: datasource.getFiltered(),
|
||||||
nextPageState: newStatuses.count < 20 ? .none : .hasNextPage)
|
nextPageState: newStatuses.count < 20 ? .none : .hasNextPage)
|
||||||
} catch {
|
} catch {
|
||||||
statusesState = .error(error: error)
|
statusesState = .error(error: error)
|
||||||
|
|
|
@ -9,6 +9,10 @@ actor TimelineDatasource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func get() -> [Status] {
|
func get() -> [Status] {
|
||||||
|
statuses
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFiltered() -> [Status] {
|
||||||
statuses.filter{ !$0.isHidden }
|
statuses.filter{ !$0.isHidden }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue