From 080243ae1747a7e8c1412b40f2adacaba66fdc19 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Tue, 14 Nov 2023 16:00:48 -0500 Subject: [PATCH] Remove Store.save calls --- ntfy/App/AppDelegate.swift | 25 ------------------- .../Persistence/NotificationsObservable.swift | 1 + .../Persistence/SubscriptionsObservable.swift | 2 +- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/ntfy/App/AppDelegate.swift b/ntfy/App/AppDelegate.swift index 4758ec3..2862acf 100644 --- a/ntfy/App/AppDelegate.swift +++ b/ntfy/App/AppDelegate.swift @@ -97,23 +97,6 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ) { let userInfo = notification.request.content.userInfo Log.d(tag, "Notification received via userNotificationCenter(willPresent)", userInfo) - - guard let message = Message.from(userInfo: userInfo) else { - Log.w(tag, "Cannot convert userInfo to message", userInfo) - completionHandler([]) - return - } - - let store = Store.shared - let baseUrl = userInfo["base_url"] as? String ?? Config.appBaseUrl - - guard let subscription = store.getSubscription(baseUrl: baseUrl, topic: message.topic) else { - Log.w(tag, "Subscription \(topicUrl(baseUrl: baseUrl, topic: message.topic)) unknown") - completionHandler([]) - return - } - Store.shared.save(notificationFromMessage: message, withSubscription: subscription) - completionHandler([[.banner, .sound]]) } @@ -131,17 +114,9 @@ extension AppDelegate: UNUserNotificationCenterDelegate { return } - let store = Store.shared let baseUrl = userInfo["base_url"] as? String ?? Config.appBaseUrl let action = message.actions?.first { $0.id == response.actionIdentifier } - guard let subscription = store.getSubscription(baseUrl: baseUrl, topic: message.topic) else { - Log.w(tag, "Subscription \(topicUrl(baseUrl: baseUrl, topic: message.topic)) unknown") - completionHandler() - return - } - Store.shared.save(notificationFromMessage: message, withSubscription: subscription) - // Show current topic if message.topic != "" { selectedBaseUrl = topicUrl(baseUrl: baseUrl, topic: message.topic) diff --git a/ntfy/Persistence/NotificationsObservable.swift b/ntfy/Persistence/NotificationsObservable.swift index 5b71507..7fea8bf 100644 --- a/ntfy/Persistence/NotificationsObservable.swift +++ b/ntfy/Persistence/NotificationsObservable.swift @@ -26,6 +26,7 @@ class NotificationsObservable: NSObject, ObservableObject { super.init() do { + Log.d(tag, "Fetching notifications") try self.fetchedResultsController.performFetch() self.notifications = self.fetchedResultsController.fetchedObjects ?? [] } catch { diff --git a/ntfy/Persistence/SubscriptionsObservable.swift b/ntfy/Persistence/SubscriptionsObservable.swift index 9e432d3..8a7aa1b 100644 --- a/ntfy/Persistence/SubscriptionsObservable.swift +++ b/ntfy/Persistence/SubscriptionsObservable.swift @@ -22,7 +22,7 @@ class SubscriptionsObservable: NSObject, ObservableObject { Log.d(tag, "Fetching subscriptions") try controller.performFetch() } catch { - Log.w(tag, "Failed to fetch items: \(error)", error) + Log.w(tag, "Failed to fetch subscriptions: \(error)", error) } return controller