mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 01:45:20 +00:00
Merge pull request #44 from PubliusPseudis/fix/update-peerlist-on-main-thread
Fix: Ensure peer list updates on main thread
This commit is contained in:
@@ -2932,27 +2932,28 @@ extension ChatViewModel: BitchatDelegate {
|
||||
|
||||
func didUpdatePeerList(_ peers: [String]) {
|
||||
// print("[DEBUG] Updating peer list: \(peers.count) peers: \(peers)")
|
||||
connectedPeers = peers
|
||||
isConnected = !peers.isEmpty
|
||||
// UI updates must run on the main thread.
|
||||
// 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
|
||||
for (channel, memberIDs) in channelMembers {
|
||||
// Remove disconnected peers from channel members
|
||||
for (channel, memberIDs) in self.channelMembers {
|
||||
let activeMembers = memberIDs.filter { memberID in
|
||||
memberID == meshService.myPeerID || peers.contains(memberID)
|
||||
memberID == self.meshService.myPeerID || peers.contains(memberID)
|
||||
}
|
||||
if activeMembers != memberIDs {
|
||||
channelMembers[channel] = activeMembers
|
||||
self.channelMembers[channel] = activeMembers
|
||||
}
|
||||
}
|
||||
// Explicitly notify SwiftUI that the object has changed.
|
||||
self.objectWillChange.send()
|
||||
|
||||
// Force UI update
|
||||
objectWillChange.send()
|
||||
|
||||
// If we're in a private chat with someone who disconnected, exit the chat
|
||||
if let currentChatPeer = selectedPrivateChatPeer,
|
||||
if let currentChatPeer = self.selectedPrivateChatPeer,
|
||||
!peers.contains(currentChatPeer) {
|
||||
endPrivateChat()
|
||||
self.endPrivateChat()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user