From d9bbca1005721788e98f1dc954a8f0c5b5c44943 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 5 Sep 2024 16:42:44 -0700 Subject: [PATCH] notifications: don't fail if we don't have display_name This isn't even a standard field anyways Signed-off-by: William Casarin --- DamusNotificationService/NotificationService.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/DamusNotificationService/NotificationService.swift b/DamusNotificationService/NotificationService.swift index 4c6601cb..afced5af 100644 --- a/DamusNotificationService/NotificationService.swift +++ b/DamusNotificationService/NotificationService.swift @@ -27,9 +27,9 @@ class NotificationService: UNNotificationServiceExtension { // Log that we got a push notification Log.debug("Got nostr event push notification from pubkey %s", for: .push_notifications, nostr_event.pubkey.hex()) - guard let state = NotificationExtensionState(), - let display_name = state.ndb.lookup_profile(nostr_event.pubkey)?.unsafeUnownedValue?.profile?.display_name // We are not holding the txn here. - else { + guard let state = NotificationExtensionState() else { + Log.debug("Failed to open nostrdb", for: .push_notifications) + // Something failed to initialize so let's go for the next best thing guard let improved_content = NotificationFormatter.shared.format_message(event: nostr_event) else { // We cannot format this nostr event. Suppress notification. @@ -39,7 +39,11 @@ class NotificationService: UNNotificationServiceExtension { contentHandler(improved_content) return } - + + let txn = state.ndb.lookup_profile(nostr_event.pubkey) + let profile = txn?.unsafeUnownedValue?.profile + let name = Profile.displayName(profile: profile, pubkey: nostr_event.pubkey).displayName + // Don't show notification details that match mute list. // TODO: Remove this code block once we get notification suppression entitlement from Apple. It will be covered by the `guard should_display_notification` block if state.mutelist_manager.is_event_muted(nostr_event) {