Fix active peer notification in background logic

This commit is contained in:
callebtc
2026-01-18 02:20:59 +07:00
parent ab04764212
commit 6eb7d79ed0
2 changed files with 13 additions and 0 deletions
@@ -178,6 +178,14 @@ class BluetoothMeshService(private val context: Context) {
try { com.bitchat.android.services.AppStateStore.setPeers(peerIDs) } catch (_: Exception) { } try { com.bitchat.android.services.AppStateStore.setPeers(peerIDs) } catch (_: Exception) { }
// Then notify UI delegate if attached // Then notify UI delegate if attached
delegate?.didUpdatePeerList(peerIDs) delegate?.didUpdatePeerList(peerIDs)
// If UI is detached (background), update notification manager directly
if (delegate == null) {
try {
serviceNotificationManager.setAppBackgroundState(true)
serviceNotificationManager.showActiveUserNotification(peerIDs)
} catch (_: Exception) { }
}
} }
override fun onPeerRemoved(peerID: String) { override fun onPeerRemoved(peerID: String) {
try { gossipSyncManager.removeAnnouncementForPeer(peerID) } catch (_: Exception) { } try { gossipSyncManager.removeAnnouncementForPeer(peerID) } catch (_: Exception) { }
@@ -174,6 +174,11 @@ class NotificationManager(
} }
fun showActiveUserNotification(peers: List<String>) { fun showActiveUserNotification(peers: List<String>) {
if (peers.isEmpty()) {
notificationIntervalManager.recentlySeenPeers.clear()
return
}
val currentTime = System.currentTimeMillis() val currentTime = System.currentTimeMillis()
val activePeerNotificationIntervalExceeded = val activePeerNotificationIntervalExceeded =
(currentTime - notificationIntervalManager.lastNetworkNotificationTime) > ACTIVE_PEERS_NOTIFICATION_TIME_INTERVAL (currentTime - notificationIntervalManager.lastNetworkNotificationTime) > ACTIVE_PEERS_NOTIFICATION_TIME_INTERVAL