From cb241741e350222160f7095487a7310ec3051bfb Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 5 Sep 2024 16:53:38 -0700 Subject: [PATCH] notifications: add more logging needed this to debug stuff Signed-off-by: William Casarin --- DamusNotificationService/NotificationFormatter.swift | 3 ++- DamusNotificationService/NotificationService.swift | 10 ++++++++-- nostrdb/Ndb.swift | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DamusNotificationService/NotificationFormatter.swift b/DamusNotificationService/NotificationFormatter.swift index df8312d8..2c15f84c 100644 --- a/DamusNotificationService/NotificationFormatter.swift +++ b/DamusNotificationService/NotificationFormatter.swift @@ -93,10 +93,11 @@ struct NotificationFormatter { // If it does not work, try async formatting methods let content = UNMutableNotificationContent() - + switch notify.type { case .zap, .profile_zap: guard let zap = await get_zap(from: notify.event, state: state) else { + Log.debug("format_message: async get_zap failed", for: .push_notifications) return nil } content.title = Self.zap_notification_title(zap) diff --git a/DamusNotificationService/NotificationService.swift b/DamusNotificationService/NotificationService.swift index afced5af..fc44e3b4 100644 --- a/DamusNotificationService/NotificationService.swift +++ b/DamusNotificationService/NotificationService.swift @@ -58,6 +58,7 @@ class NotificationService: UNNotificationServiceExtension { } guard should_display_notification(state: state, event: nostr_event, mode: .push) else { + Log.debug("should_display_notification failed", for: .push_notifications) // We should not display notification for this event. Suppress notification. // contentHandler(UNNotificationContent()) // TODO: We cannot really suppress until we have the notification supression entitlement. Show the raw notification @@ -66,6 +67,7 @@ class NotificationService: UNNotificationServiceExtension { } guard let notification_object = generate_local_notification_object(from: nostr_event, state: state) else { + Log.debug("generate_local_notification_object failed", for: .push_notifications) // We could not process this notification. Probably an unsupported nostr event kind. Suppress. // contentHandler(UNNotificationContent()) // TODO: We cannot really suppress until we have the notification supression entitlement. Show the raw notification @@ -74,9 +76,13 @@ class NotificationService: UNNotificationServiceExtension { } Task { - if let (improvedContent, _) = await NotificationFormatter.shared.format_message(displayName: display_name, notify: notification_object, state: state) { - contentHandler(improvedContent) + guard let (improvedContent, _) = await NotificationFormatter.shared.format_message(displayName: name, notify: notification_object, state: state) else { + + Log.debug("NotificationFormatter.format_message failed", for: .push_notifications) + return } + + contentHandler(improvedContent) } } diff --git a/nostrdb/Ndb.swift b/nostrdb/Ndb.swift index fa828775..65616606 100644 --- a/nostrdb/Ndb.swift +++ b/nostrdb/Ndb.swift @@ -111,8 +111,10 @@ class Ndb { var ok = false while !ok && mapsize > 1024 * 1024 * 700 { var cfg = ndb_config(flags: 0, ingester_threads: ingest_threads, mapsize: mapsize, filter_context: nil, ingest_filter: nil) - ok = ndb_init(&ndb_p, testdir, &cfg) != 0 + let res = ndb_init(&ndb_p, testdir, &cfg) + ok = res != 0; if !ok { + Log.error("ndb_init failed: %d, reducing mapsize from %d to %d", for: .storage, res, mapsize, mapsize / 2) mapsize /= 2 } }