From 92efee6f4680b833fa586d9bdf311dffeb8b863e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 8 Jun 2022 18:02:48 -0400 Subject: [PATCH] Fix crash when loading older/newer notifications on Pixelfed Damn Pixelfed returning nonsensical pagination links Closes #166 --- .../NotificationsTableViewController.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index 6e32353e22..45d4beb032 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -107,11 +107,13 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< case let .failure(error): completion(.failure(.client(error))) - case let .success(notifications, pagination): + case let .success(notifications, _): let groups = NotificationGroup.createGroups(notifications: notifications, only: self.groupTypes) - self.newer = pagination?.newer - self.older = pagination?.older + if !notifications.isEmpty { + self.newer = .after(id: notifications.first!.id, count: nil) + self.older = .before(id: notifications.last!.id, count: nil) + } self.mastodonController.persistentContainer.addAll(notifications: notifications) { var snapshot = Snapshot() @@ -135,9 +137,9 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< case let .failure(error): completion(.failure(.client(error))) - case let .success(newNotifications, pagination): - if let older = pagination?.older { - self.older = older + case let .success(newNotifications, _): + if !newNotifications.isEmpty { + self.older = .before(id: newNotifications.last!.id, count: nil) } let olderGroups = NotificationGroup.createGroups(notifications: newNotifications, only: self.groupTypes) @@ -166,15 +168,13 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< case let .failure(error): completion(.failure(.client(error))) - case let .success(newNotifications, pagination): + case let .success(newNotifications, _): guard !newNotifications.isEmpty else { completion(.failure(.allCaughtUp)) return } - if let newer = pagination?.newer { - self.newer = newer - } + self.newer = .after(id: newNotifications.first!.id, count: nil) let newerGroups = NotificationGroup.createGroups(notifications: newNotifications, only: self.groupTypes)