From ab8ccbb408a4690ce9859b1a95554b78fe241ae5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 16 Apr 2023 13:59:38 -0400 Subject: [PATCH] Exclude notifications that are missing statuses It's still unclear why this ever happens, but crashing is untenable See #274 --- .../NotificationsTableViewController.swift | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index ea750ccb..e8e0261e 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -165,16 +165,21 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< } } - private func validateNotifications(_ notifications: [Pachyderm.Notification]) { - for notif in notifications where notif.status == nil && (notif.kind == .mention || notif.kind == .reblog || notif.kind == .favourite) { - let crumb = Breadcrumb(level: .fatal, category: "notifications") - crumb.data = [ - "id": notif.id, - "type": notif.kind.rawValue, - "created_at": notif.createdAt.formatted(.iso8601), - "account": notif.account.id, - ] - SentrySDK.addBreadcrumb(crumb) + private func validateNotifications(_ notifications: [Pachyderm.Notification]) -> [Pachyderm.Notification] { + return notifications.compactMap { notif in + if notif.status == nil && (notif.kind == .mention || notif.kind == .reblog || notif.kind == .favourite) { + let crumb = Breadcrumb(level: .fatal, category: "notifications") + crumb.data = [ + "id": notif.id, + "type": notif.kind.rawValue, + "created_at": notif.createdAt.formatted(.iso8601), + "account": notif.account.id, + ] + SentrySDK.addBreadcrumb(crumb) + return nil + } else { + return notif + } } } @@ -185,7 +190,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< completion(.failure(.client(error))) case let .success(notifications, _): - self.validateNotifications(notifications) + let notifications = self.validateNotifications(notifications) let groups = NotificationGroup.createGroups(notifications: notifications, only: self.groupTypes) if !notifications.isEmpty { @@ -215,7 +220,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< completion(.failure(.client(error))) case let .success(newNotifications, _): - self.validateNotifications(newNotifications) + let newNotifications = self.validateNotifications(newNotifications) if !newNotifications.isEmpty { self.older = .before(id: newNotifications.last!.id, count: nil) } @@ -246,7 +251,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< completion(.failure(.client(error))) case let .success(newNotifications, _): - self.validateNotifications(newNotifications) + let newNotifications = self.validateNotifications(newNotifications) guard !newNotifications.isEmpty else { completion(.failure(.allCaughtUp)) return