From 54499560e8aa3294768dbb9a86ee9bbe60ee5bec Mon Sep 17 00:00:00 2001 From: jack Date: Sun, 24 Aug 2025 13:11:36 +0200 Subject: [PATCH] feat(notifications): unify DM notifications across transports; notify for unread+recent even in foreground; delegate suppresses if chat open --- bitchat/ViewModels/ChatViewModel.swift | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 72e27c55..c1d7881a 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -833,16 +833,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate { self.sentReadReceipts.insert(messageId) } } else { - // Optionally notify if app backgrounded and message is truly unread - #if os(iOS) - if shouldMarkUnread && UIApplication.shared.applicationState != .active { + // Notify for truly unread and recent messages when not viewing + if shouldMarkUnread { NotificationService.shared.sendPrivateMessageNotification( from: senderName, message: pm.content, peerID: convKey ) } - #endif } self.objectWillChange.send() case .delivered: @@ -1521,19 +1519,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate { } else { // pared back: omit defer READ log } - // Notify only when app is backgrounded and not viewing, and only if not already read - #if os(iOS) + // Notify for truly unread and recent messages when not viewing if !isViewing && shouldMarkUnread { - if UIApplication.shared.applicationState != .active { - NotificationService.shared.sendPrivateMessageNotification( - from: senderName, - message: pm.content, - peerID: convKey - ) - // pared back: omit notification log - } + NotificationService.shared.sendPrivateMessageNotification( + from: senderName, + message: pm.content, + peerID: convKey + ) } - #endif self.objectWillChange.send() default: // Handle delivered/read receipts for our sent messages