Fix notifications timeline loading (IOS-176)

This commit is contained in:
Marcus Kida 2023-11-22 13:18:51 +01:00
parent 9ce078ce3e
commit d0893d5c69
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
1 changed files with 22 additions and 18 deletions

View File

@ -106,31 +106,35 @@ extension NotificationTimelineViewModel {
isLoadingLatest = true
defer { isLoadingLatest = false }
do {
_ = try await context.apiService.notifications(
maxID: nil,
scope: scope,
authenticationBox: authContext.mastodonAuthenticationBox
)
} catch {
didLoadLatest.send()
switch scope {
case .everything:
feedFetchedResultsController.loadInitial(kind: .notificationAll)
case .mentions:
feedFetchedResultsController.loadInitial(kind: .notificationMentions)
}
didLoadLatest.send()
}
// load timeline gap
func loadMore(item: NotificationItem) async {
guard case let .feedLoader(record) = item else { return }
// guard case let .feedLoader(record) = item else { return }
guard let maxID = record.notification?.id else { return }
// guard let maxID = record.notification?.id else { return }
// fetch data
if let notifications = try? await context.apiService.notifications(
maxID: maxID,
scope: scope,
authenticationBox: authContext.mastodonAuthenticationBox
) {
self.feedFetchedResultsController.records += notifications.value.map { MastodonFeed.fromNotification($0, kind: record.kind) }
// // fetch data
// if let notifications = try? await context.apiService.notifications(
// maxID: maxID,
// scope: scope,
// authenticationBox: authContext.mastodonAuthenticationBox
// ) {
// self.feedFetchedResultsController.records += notifications.value.map { MastodonFeed.fromNotification($0, kind: record.kind) }
// }
switch scope {
case .everything:
feedFetchedResultsController.loadNext(kind: .notificationAll)
case .mentions:
feedFetchedResultsController.loadNext(kind: .notificationMentions)
}
}
}