From 1e67bb4fd1ba8595d92212cbe61ca0c2b4d59d1d Mon Sep 17 00:00:00 2001 From: jack Date: Wed, 23 Jul 2025 10:59:21 +0200 Subject: [PATCH] Improve UI update triggers for encryption status Added multiple UI update triggers to ensure the lock icon updates: 1. In onPeerAuthenticated callback when handshake completes 2. When detecting an already established session on reconnect This ensures the encryption status is reflected in the UI immediately after: - Initial handshake completion - Reconnection with existing session - Peer authentication events --- bitchat/Services/BluetoothMeshService.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bitchat/Services/BluetoothMeshService.swift b/bitchat/Services/BluetoothMeshService.swift index 63e767a9..38f03ec9 100644 --- a/bitchat/Services/BluetoothMeshService.swift +++ b/bitchat/Services/BluetoothMeshService.swift @@ -551,6 +551,9 @@ class BluetoothMeshService: NSObject { // Register with ChatViewModel for verification tracking DispatchQueue.main.async { (self?.delegate as? ChatViewModel)?.registerPeerPublicKey(peerID: peerID, publicKeyData: publicKeyData) + + // Force UI to update encryption status after authentication + (self?.delegate as? ChatViewModel)?.updateEncryptionStatusForPeers() } } @@ -3299,6 +3302,12 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate { // Clear any lingering handshake attempt time handshakeAttemptTimes.removeValue(forKey: peerID) handshakeCoordinator.recordHandshakeSuccess(peerID: peerID) + + // Force UI update since we have an existing session + DispatchQueue.main.async { [weak self] in + (self?.delegate as? ChatViewModel)?.updateEncryptionStatusForPeers() + } + return } @@ -3421,14 +3430,6 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate { // Send any cached store-and-forward messages sendCachedMessages(to: peerID) - - // Notify delegate to update UI encryption status - DispatchQueue.main.async { [weak self] in - // Force UI to refresh by sending a peer list update - if let peers = self?.collectionsQueue.sync(execute: { Array(self?.activePeers ?? []) }) { - self?.delegate?.didUpdatePeerList(peers) - } - } } } catch NoiseSessionError.alreadyEstablished { // Session already established, ignore handshake