diff --git a/damus/ContentView.swift b/damus/ContentView.swift index e8efd7d2..b8619102 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -832,6 +832,12 @@ func save_last_event(_ ev: NostrEvent, timeline: Timeline) { UserDefaults.standard.set(String(ev.created_at), forKey: "last_\(str)_time") } +func save_last_event(_ ev_id: NoteId, created_at: UInt32, timeline: Timeline) { + let str = timeline.rawValue + UserDefaults.standard.set(ev_id.hex(), forKey: "last_\(str)") + UserDefaults.standard.set(String(created_at), forKey: "last_\(str)_time") +} + func update_filters_with_since(last_of_kind: [UInt32: NostrEvent], filters: [NostrFilter]) -> [NostrFilter] { return filters.map { filter in diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index ee460ad0..82d5bde1 100644 --- a/damus/Models/HomeModel.swift +++ b/damus/Models/HomeModel.swift @@ -309,9 +309,14 @@ class HomeModel: ContactsDelegate { @MainActor func handle_damus_app_notification(_ notification: DamusAppNotification) async { if self.notifications.insert_app_notification(notification: notification) { - // If we successfully inserted a new Damus App notification, switch ON the Damus App notification bit on our NewsEventsBits - // This will cause the bell icon on the tab bar to display the purple dot indicating there is an unread notification - self.notification_status.new_events = NewEventsBits(rawValue: self.notification_status.new_events.rawValue | NewEventsBits.damus_app_notifications.rawValue) + let last_notification = get_last_event(.notifications) + if last_notification == nil || last_notification!.created_at < notification.last_event_at { + save_last_event(NoteId.empty, created_at: notification.last_event_at, timeline: .notifications) + // If we successfully inserted a new Damus App notification, switch ON the Damus App notification bit on our NewsEventsBits + // This will cause the bell icon on the tab bar to display the purple dot indicating there is an unread notification + self.notification_status.new_events = NewEventsBits(rawValue: self.notification_status.new_events.rawValue | NewEventsBits.damus_app_notifications.rawValue) + } + return } }