notifications: don't fail if we don't have display_name

This isn't even a standard field anyways

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-09-05 16:42:44 -07:00
committed by Daniel D’Aquino
parent da7af491d0
commit d9bbca1005

View File

@@ -27,9 +27,9 @@ class NotificationService: UNNotificationServiceExtension {
// Log that we got a push notification // Log that we got a push notification
Log.debug("Got nostr event push notification from pubkey %s", for: .push_notifications, nostr_event.pubkey.hex()) Log.debug("Got nostr event push notification from pubkey %s", for: .push_notifications, nostr_event.pubkey.hex())
guard let state = NotificationExtensionState(), guard let state = NotificationExtensionState() else {
let display_name = state.ndb.lookup_profile(nostr_event.pubkey)?.unsafeUnownedValue?.profile?.display_name // We are not holding the txn here. Log.debug("Failed to open nostrdb", for: .push_notifications)
else {
// Something failed to initialize so let's go for the next best thing // 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 { guard let improved_content = NotificationFormatter.shared.format_message(event: nostr_event) else {
// We cannot format this nostr event. Suppress notification. // We cannot format this nostr event. Suppress notification.
@@ -40,6 +40,10 @@ class NotificationService: UNNotificationServiceExtension {
return 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. // 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 // 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) { if state.mutelist_manager.is_event_muted(nostr_event) {