Geohash count: use the same pruned/sorted list for toolbar and peer list (visibleGeohashPeople) to ensure consistency

This commit is contained in:
jack
2025-08-22 12:51:40 +02:00
parent 16fdb7b49e
commit 4bfe9ac80d
3 changed files with 17 additions and 2 deletions
+11
View File
@@ -1473,6 +1473,17 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
// MARK: - Public helpers (iOS)
#if os(iOS)
/// Return the current, pruned, sorted people list for the active geohash without mutating state.
@MainActor
func visibleGeohashPeople() -> [GeoPerson] {
guard let gh = currentGeohash else { return [] }
let cutoff = Date().addingTimeInterval(-5 * 60)
let map = (geoParticipants[gh] ?? [:]).filter { $0.value >= cutoff }
let people = map
.map { (pub, seen) in GeoPerson(id: pub, displayName: displayNameForNostrPubkey(pub), lastSeen: seen) }
.sorted { $0.lastSeen > $1.lastSeen }
return people
}
/// Returns the current participant count for a specific geohash, using the 5-minute activity window.
@MainActor
func geohashParticipantCount(for geohash: String) -> Int {
+5 -1
View File
@@ -871,8 +871,12 @@ struct ContentView: View {
// Unread icon immediately to the left of the channel badge (independent from channel button)
#if os(iOS)
let cc = channelPeopleCountAndColor()
let otherPeersCount = cc.0
var otherPeersCount = cc.0
let countColor = cc.1
// Ensure geohash count matches the actual pruned list used in the sidebar
if case .location = locationManager.selectedChannel {
otherPeersCount = viewModel.visibleGeohashPeople().count
}
#else
let peerCounts = viewModel.allPeers.reduce(into: (others: 0, mesh: 0)) { counts, peer in
guard peer.id != viewModel.meshService.myPeerID else { return }
+1 -1
View File
@@ -24,7 +24,7 @@ struct GeohashPeopleList: View {
}
return nil
}()
let ordered = viewModel.geohashPeople.sorted { a, b in
let ordered = viewModel.visibleGeohashPeople().sorted { a, b in
if let me = myHex {
if a.id == me && b.id != me { return true }
if b.id == me && a.id != me { return false }