Fix room member list display logic

- Always include self in room member list if we're a member
- Simplify empty room detection
- Add more debug logging to diagnose member tracking
This commit is contained in:
jack
2025-07-05 19:35:37 +02:00
parent 10ee001728
commit 4a834ac571
+9 -8
View File
@@ -585,8 +585,8 @@ struct ContentView: View {
.foregroundColor(secondaryTextColor) .foregroundColor(secondaryTextColor)
.padding(.horizontal) .padding(.horizontal)
} else if let currentRoom = viewModel.currentRoom, } else if let currentRoom = viewModel.currentRoom,
viewModel.roomMembers[currentRoom]?.isEmpty ?? true, let roomMemberIDs = viewModel.roomMembers[currentRoom],
!viewModel.connectedPeers.contains(viewModel.meshService.myPeerID) { roomMemberIDs.isEmpty {
Text("No one in this room yet") Text("No one in this room yet")
.font(.system(size: 14, design: .monospaced)) .font(.system(size: 14, design: .monospaced))
.foregroundColor(secondaryTextColor) .foregroundColor(secondaryTextColor)
@@ -603,17 +603,18 @@ struct ContentView: View {
// Show only peers who have sent messages to this room (including self) // Show only peers who have sent messages to this room (including self)
print("[DEBUG-VIEW] Room \(currentRoom) has members: \(roomMemberIDs)") print("[DEBUG-VIEW] Room \(currentRoom) has members: \(roomMemberIDs)")
print("[DEBUG-VIEW] Connected peers: \(viewModel.connectedPeers)") print("[DEBUG-VIEW] Connected peers: \(viewModel.connectedPeers)")
print("[DEBUG-VIEW] My peer ID: \(myPeerID)")
// Start with room members who are also connected
var memberPeers = viewModel.connectedPeers.filter { roomMemberIDs.contains($0) } var memberPeers = viewModel.connectedPeers.filter { roomMemberIDs.contains($0) }
// Always include ourselves if we're connected
if viewModel.connectedPeers.contains(myPeerID) && roomMemberIDs.contains(myPeerID) { // Always include ourselves if we're a room member
if !memberPeers.contains(myPeerID) { if roomMemberIDs.contains(myPeerID) && !memberPeers.contains(myPeerID) {
memberPeers.append(myPeerID) memberPeers.append(myPeerID)
}
} }
print("[DEBUG-VIEW] Peers to show in room: \(memberPeers)") print("[DEBUG-VIEW] Peers to show in room: \(memberPeers)")
return Array(Set(memberPeers)) // Remove duplicates return memberPeers
} else { } else {
// Show all connected peers in main chat // Show all connected peers in main chat
return viewModel.connectedPeers return viewModel.connectedPeers