feat(notifications): unify DM notifications across transports; notify for unread+recent even in foreground; delegate suppresses if chat open

This commit is contained in:
jack
2025-08-24 13:11:36 +02:00
parent 75c8933091
commit 54499560e8
+8 -15
View File
@@ -833,16 +833,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
self.sentReadReceipts.insert(messageId) self.sentReadReceipts.insert(messageId)
} }
} else { } else {
// Optionally notify if app backgrounded and message is truly unread // Notify for truly unread and recent messages when not viewing
#if os(iOS) if shouldMarkUnread {
if shouldMarkUnread && UIApplication.shared.applicationState != .active {
NotificationService.shared.sendPrivateMessageNotification( NotificationService.shared.sendPrivateMessageNotification(
from: senderName, from: senderName,
message: pm.content, message: pm.content,
peerID: convKey peerID: convKey
) )
} }
#endif
} }
self.objectWillChange.send() self.objectWillChange.send()
case .delivered: case .delivered:
@@ -1521,19 +1519,14 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
} else { } else {
// pared back: omit defer READ log // pared back: omit defer READ log
} }
// Notify only when app is backgrounded and not viewing, and only if not already read // Notify for truly unread and recent messages when not viewing
#if os(iOS)
if !isViewing && shouldMarkUnread { if !isViewing && shouldMarkUnread {
if UIApplication.shared.applicationState != .active { NotificationService.shared.sendPrivateMessageNotification(
NotificationService.shared.sendPrivateMessageNotification( from: senderName,
from: senderName, message: pm.content,
message: pm.content, peerID: convKey
peerID: convKey )
)
// pared back: omit notification log
}
} }
#endif
self.objectWillChange.send() self.objectWillChange.send()
default: default:
// Handle delivered/read receipts for our sent messages // Handle delivered/read receipts for our sent messages