mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:25:20 +00:00
Fix: Ensure peer list updates on main thread
This commit is contained in:
@@ -2906,27 +2906,28 @@ extension ChatViewModel: BitchatDelegate {
|
|||||||
|
|
||||||
func didUpdatePeerList(_ peers: [String]) {
|
func didUpdatePeerList(_ peers: [String]) {
|
||||||
// print("[DEBUG] Updating peer list: \(peers.count) peers: \(peers)")
|
// print("[DEBUG] Updating peer list: \(peers.count) peers: \(peers)")
|
||||||
connectedPeers = peers
|
// UI updates must run on the main thread.
|
||||||
isConnected = !peers.isEmpty
|
// The delegate callback is not guaranteed to be on the main thread.
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.connectedPeers = peers
|
||||||
|
self.isConnected = !peers.isEmpty
|
||||||
|
|
||||||
// Clean up channel members who disconnected
|
// Clean up channel members who disconnected
|
||||||
for (channel, memberIDs) in channelMembers {
|
for (channel, memberIDs) in self.channelMembers {
|
||||||
// Remove disconnected peers from channel members
|
|
||||||
let activeMembers = memberIDs.filter { memberID in
|
let activeMembers = memberIDs.filter { memberID in
|
||||||
memberID == meshService.myPeerID || peers.contains(memberID)
|
memberID == self.meshService.myPeerID || peers.contains(memberID)
|
||||||
}
|
}
|
||||||
if activeMembers != memberIDs {
|
if activeMembers != memberIDs {
|
||||||
channelMembers[channel] = activeMembers
|
self.channelMembers[channel] = activeMembers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Explicitly notify SwiftUI that the object has changed.
|
||||||
|
self.objectWillChange.send()
|
||||||
|
|
||||||
// Force UI update
|
if let currentChatPeer = self.selectedPrivateChatPeer,
|
||||||
objectWillChange.send()
|
|
||||||
|
|
||||||
// If we're in a private chat with someone who disconnected, exit the chat
|
|
||||||
if let currentChatPeer = selectedPrivateChatPeer,
|
|
||||||
!peers.contains(currentChatPeer) {
|
!peers.contains(currentChatPeer) {
|
||||||
endPrivateChat()
|
self.endPrivateChat()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user