diff --git a/bitchat/Services/GeohashParticipantTracker.swift b/bitchat/Services/GeohashParticipantTracker.swift index ac8d6226..cf70354f 100644 --- a/bitchat/Services/GeohashParticipantTracker.swift +++ b/bitchat/Services/GeohashParticipantTracker.swift @@ -80,7 +80,10 @@ final class GeohashParticipantTracker: ObservableObject { /// Record activity from a participant in a specific geohash func recordParticipant(pubkeyHex: String, geohash: String) { let key = pubkeyHex.lowercased() - guard context?.isBlocked(key) != true else { return } + if context?.isBlocked(key) == true { + removeParticipant(pubkeyHex: key) + return + } var map = participants[geohash] ?? [:] map[key] = Date() diff --git a/bitchatTests/GeohashParticipantTrackerTests.swift b/bitchatTests/GeohashParticipantTrackerTests.swift index fe9190cc..7056b4a0 100644 --- a/bitchatTests/GeohashParticipantTrackerTests.swift +++ b/bitchatTests/GeohashParticipantTrackerTests.swift @@ -158,6 +158,20 @@ struct GeohashParticipantTrackerTests { #expect(tracker.visiblePeople.isEmpty) } + @Test func recordParticipant_blockedRepeatRemovesStaleVisibleParticipant() { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + tracker.recordParticipant(pubkeyHex: "later-blocked") + + context.blockedPubkeys.insert("later-blocked") + tracker.recordParticipant(pubkeyHex: "LATER-BLOCKED") + + #expect(tracker.participantCount(for: "abc123") == 0) + #expect(tracker.visiblePeople.isEmpty) + } + @Test func participantCount_matchesVisiblePeopleWithMixedBlockStatus() { let tracker = GeohashParticipantTracker() let context = MockParticipantContext()