mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 11:05:19 +00:00
Remove debug logging from notification system
- Clean up all temporary logging statements - Production-ready notification implementation - Network notifications trigger when peers become available
This commit is contained in:
@@ -1353,19 +1353,16 @@ class BluetoothMeshService: NSObject {
|
|||||||
// Check if we should reset the notification flag
|
// Check if we should reset the notification flag
|
||||||
if let emptyTime = networkBecameEmptyTime {
|
if let emptyTime = networkBecameEmptyTime {
|
||||||
let currentNetworkSize = collectionsQueue.sync { activePeers.count }
|
let currentNetworkSize = collectionsQueue.sync { activePeers.count }
|
||||||
print("📱 Checking network empty state: size=\(currentNetworkSize), emptyTime=\(emptyTime)")
|
|
||||||
if currentNetworkSize == 0 {
|
if currentNetworkSize == 0 {
|
||||||
// Network is still empty, check if enough time has passed
|
// Network is still empty, check if enough time has passed
|
||||||
let timeSinceEmpty = Date().timeIntervalSince(emptyTime)
|
let timeSinceEmpty = Date().timeIntervalSince(emptyTime)
|
||||||
if timeSinceEmpty >= networkEmptyResetDelay {
|
if timeSinceEmpty >= networkEmptyResetDelay {
|
||||||
// Reset the flag after network has been empty for the delay period
|
// Reset the flag after network has been empty for the delay period
|
||||||
print("📱 Resetting notification flag after \(timeSinceEmpty)s of empty network")
|
|
||||||
hasNotifiedNetworkAvailable = false
|
hasNotifiedNetworkAvailable = false
|
||||||
// Keep the empty time set so we don't immediately notify again
|
// Keep the empty time set so we don't immediately notify again
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Network is no longer empty, clear the empty time
|
// Network is no longer empty, clear the empty time
|
||||||
print("📱 Network no longer empty, clearing empty time")
|
|
||||||
networkBecameEmptyTime = nil
|
networkBecameEmptyTime = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1978,7 +1975,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Check if we've already announced this peer
|
// Check if we've already announced this peer
|
||||||
let isFirstAnnounce = !announcedPeers.contains(senderID)
|
let isFirstAnnounce = !announcedPeers.contains(senderID)
|
||||||
print("📱 Peer announce: \(senderID), isFirstAnnounce: \(isFirstAnnounce)")
|
|
||||||
|
|
||||||
// Clean up stale peer IDs with the same nickname
|
// Clean up stale peer IDs with the same nickname
|
||||||
collectionsQueue.sync(flags: .barrier) {
|
collectionsQueue.sync(flags: .barrier) {
|
||||||
@@ -2103,9 +2099,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
if wasInserted {
|
if wasInserted {
|
||||||
print("📱 Added peer \(senderID) (\(nickname)) to active peers")
|
// Added peer \(senderID) (\(nickname)) to active peers
|
||||||
} else {
|
|
||||||
print("📱 Peer \(senderID) already in active peers")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show join message only for first announce AND if we actually added the peer
|
// Show join message only for first announce AND if we actually added the peer
|
||||||
@@ -2121,8 +2115,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Send network available notification if appropriate
|
// Send network available notification if appropriate
|
||||||
let currentNetworkSize = collectionsQueue.sync { self.activePeers.count }
|
let currentNetworkSize = collectionsQueue.sync { self.activePeers.count }
|
||||||
print("📱 Network size after peer announce: \(currentNetworkSize), hasNotified: \(hasNotifiedNetworkAvailable)")
|
|
||||||
|
|
||||||
if currentNetworkSize > 0 {
|
if currentNetworkSize > 0 {
|
||||||
// Clear empty time since network is active
|
// Clear empty time since network is active
|
||||||
networkBecameEmptyTime = nil
|
networkBecameEmptyTime = nil
|
||||||
@@ -2134,24 +2126,17 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
if let lastNotification = lastNetworkNotificationTime {
|
if let lastNotification = lastNetworkNotificationTime {
|
||||||
let timeSinceLastNotification = now.timeIntervalSince(lastNotification)
|
let timeSinceLastNotification = now.timeIntervalSince(lastNotification)
|
||||||
print("📱 Time since last notification: \(timeSinceLastNotification)s, cooldown: \(networkNotificationCooldown)s")
|
|
||||||
if timeSinceLastNotification < networkNotificationCooldown {
|
if timeSinceLastNotification < networkNotificationCooldown {
|
||||||
// Too soon to send another notification
|
// Too soon to send another notification
|
||||||
shouldSendNotification = false
|
shouldSendNotification = false
|
||||||
print("📱 Skipping notification - cooldown period active")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldSendNotification {
|
if shouldSendNotification {
|
||||||
print("📱 Triggering network availability notification for \(currentNetworkSize) peers")
|
|
||||||
hasNotifiedNetworkAvailable = true
|
hasNotifiedNetworkAvailable = true
|
||||||
lastNetworkNotificationTime = now
|
lastNetworkNotificationTime = now
|
||||||
NotificationService.shared.sendNetworkAvailableNotification(peerCount: currentNetworkSize)
|
NotificationService.shared.sendNetworkAvailableNotification(peerCount: currentNetworkSize)
|
||||||
} else {
|
|
||||||
print("📱 Not sending notification - cooldown active")
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
print("📱 Not sending notification - already notified")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ class NotificationService {
|
|||||||
func requestAuthorization() {
|
func requestAuthorization() {
|
||||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
||||||
if granted {
|
if granted {
|
||||||
print("📱 Notification permission granted")
|
// Permission granted
|
||||||
} else {
|
} else {
|
||||||
print("📱 Notification permission denied: \(error?.localizedDescription ?? "Unknown")")
|
// Permission denied
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,12 +44,8 @@ class NotificationService {
|
|||||||
trigger: nil // Deliver immediately
|
trigger: nil // Deliver immediately
|
||||||
)
|
)
|
||||||
|
|
||||||
UNUserNotificationCenter.current().add(request) { error in
|
UNUserNotificationCenter.current().add(request) { _ in
|
||||||
if let error = error {
|
// Notification added
|
||||||
print("📱 Error sending local notification: \(error)")
|
|
||||||
} else {
|
|
||||||
print("📱 Local notification sent: \(title)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,8 +67,6 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendFavoriteOnlineNotification(nickname: String) {
|
func sendFavoriteOnlineNotification(nickname: String) {
|
||||||
print("📱 sendFavoriteOnlineNotification called for: \(nickname)")
|
|
||||||
|
|
||||||
// Send directly without checking app state for favorites
|
// Send directly without checking app state for favorites
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let content = UNMutableNotificationContent()
|
let content = UNMutableNotificationContent()
|
||||||
@@ -86,25 +80,17 @@ class NotificationService {
|
|||||||
trigger: nil
|
trigger: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
UNUserNotificationCenter.current().add(request) { error in
|
UNUserNotificationCenter.current().add(request) { _ in
|
||||||
if let error = error {
|
// Notification added
|
||||||
print("📱 Error sending favorite notification: \(error)")
|
|
||||||
} else {
|
|
||||||
print("📱 Favorite notification sent successfully")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNetworkAvailableNotification(peerCount: Int) {
|
func sendNetworkAvailableNotification(peerCount: Int) {
|
||||||
print("📱 sendNetworkAvailableNotification called with peerCount: \(peerCount)")
|
|
||||||
|
|
||||||
let title = "👥 bitchatters nearby!"
|
let title = "👥 bitchatters nearby!"
|
||||||
let body = peerCount == 1 ? "1 person around" : "\(peerCount) people around"
|
let body = peerCount == 1 ? "1 person around" : "\(peerCount) people around"
|
||||||
let identifier = "network-available-\(Date().timeIntervalSince1970)"
|
let identifier = "network-available-\(Date().timeIntervalSince1970)"
|
||||||
|
|
||||||
print("📱 Sending network notification: \(body)")
|
|
||||||
|
|
||||||
// For network notifications, we want to show them even in foreground
|
// For network notifications, we want to show them even in foreground
|
||||||
// No app state check - let the notification delegate handle presentation
|
// No app state check - let the notification delegate handle presentation
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@@ -120,12 +106,8 @@ class NotificationService {
|
|||||||
trigger: nil // Deliver immediately
|
trigger: nil // Deliver immediately
|
||||||
)
|
)
|
||||||
|
|
||||||
UNUserNotificationCenter.current().add(request) { error in
|
UNUserNotificationCenter.current().add(request) { _ in
|
||||||
if let error = error {
|
// Notification added
|
||||||
print("📱 Error sending network notification: \(error)")
|
|
||||||
} else {
|
|
||||||
print("📱 Network notification sent successfully")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user