Exclude notifications that are missing statuses

It's still unclear why this ever happens, but crashing is untenable

See #274
This commit is contained in:
Shadowfacts 2023-04-16 13:59:38 -04:00
parent f89d2c1cca
commit ab8ccbb408
1 changed files with 18 additions and 13 deletions

View File

@ -165,16 +165,21 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
} }
} }
private func validateNotifications(_ notifications: [Pachyderm.Notification]) { private func validateNotifications(_ notifications: [Pachyderm.Notification]) -> [Pachyderm.Notification] {
for notif in notifications where notif.status == nil && (notif.kind == .mention || notif.kind == .reblog || notif.kind == .favourite) { return notifications.compactMap { notif in
let crumb = Breadcrumb(level: .fatal, category: "notifications") if notif.status == nil && (notif.kind == .mention || notif.kind == .reblog || notif.kind == .favourite) {
crumb.data = [ let crumb = Breadcrumb(level: .fatal, category: "notifications")
"id": notif.id, crumb.data = [
"type": notif.kind.rawValue, "id": notif.id,
"created_at": notif.createdAt.formatted(.iso8601), "type": notif.kind.rawValue,
"account": notif.account.id, "created_at": notif.createdAt.formatted(.iso8601),
] "account": notif.account.id,
SentrySDK.addBreadcrumb(crumb) ]
SentrySDK.addBreadcrumb(crumb)
return nil
} else {
return notif
}
} }
} }
@ -185,7 +190,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
completion(.failure(.client(error))) completion(.failure(.client(error)))
case let .success(notifications, _): case let .success(notifications, _):
self.validateNotifications(notifications) let notifications = self.validateNotifications(notifications)
let groups = NotificationGroup.createGroups(notifications: notifications, only: self.groupTypes) let groups = NotificationGroup.createGroups(notifications: notifications, only: self.groupTypes)
if !notifications.isEmpty { if !notifications.isEmpty {
@ -215,7 +220,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
completion(.failure(.client(error))) completion(.failure(.client(error)))
case let .success(newNotifications, _): case let .success(newNotifications, _):
self.validateNotifications(newNotifications) let newNotifications = self.validateNotifications(newNotifications)
if !newNotifications.isEmpty { if !newNotifications.isEmpty {
self.older = .before(id: newNotifications.last!.id, count: nil) self.older = .before(id: newNotifications.last!.id, count: nil)
} }
@ -246,7 +251,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
completion(.failure(.client(error))) completion(.failure(.client(error)))
case let .success(newNotifications, _): case let .success(newNotifications, _):
self.validateNotifications(newNotifications) let newNotifications = self.validateNotifications(newNotifications)
guard !newNotifications.isEmpty else { guard !newNotifications.isEmpty else {
completion(.failure(.allCaughtUp)) completion(.failure(.allCaughtUp))
return return