Fix geohash block case sensitivity issue (#645)

Co-authored-by: a1denvalu3 <>
This commit is contained in:
a1denvalu3
2026-06-25 22:06:46 +02:00
committed by GitHub
co-authored by a1denvalu3 <>
parent 37a20ebf34
commit 8607ce84ba
2 changed files with 14 additions and 10 deletions
@@ -59,22 +59,25 @@ class GeohashMessageHandler(
} }
} }
// Normalize pubkey to lowercase for consistent blocking and storage
val pubkey = event.pubkey.lowercase()
// Blocked users check (use injected DataManager which has loaded state) // Blocked users check (use injected DataManager which has loaded state)
if (dataManager.isGeohashUserBlocked(event.pubkey)) return@launch if (dataManager.isGeohashUserBlocked(pubkey)) return@launch
// Update repository (participants, nickname, teleport) // Update repository (participants, nickname, teleport)
// Update repository on a background-safe path; repository will post updates to LiveData // Update repository on a background-safe path; repository will post updates to LiveData
// Update participant count (last seen) on BOTH Presence (20001) and Chat (20000) events // Update participant count (last seen) on BOTH Presence (20001) and Chat (20000) events
if (event.kind == NostrKind.GEOHASH_PRESENCE || event.kind == NostrKind.EPHEMERAL_EVENT) { if (event.kind == NostrKind.GEOHASH_PRESENCE || event.kind == NostrKind.EPHEMERAL_EVENT) {
repo.updateParticipant(subscribedGeohash, event.pubkey, Date(event.createdAt * 1000L)) repo.updateParticipant(subscribedGeohash, pubkey, Date(event.createdAt * 1000L))
} }
event.tags.find { it.size >= 2 && it[0] == "n" }?.let { repo.cacheNickname(event.pubkey, it[1]) } event.tags.find { it.size >= 2 && it[0] == "n" }?.let { repo.cacheNickname(pubkey, it[1]) }
event.tags.find { it.size >= 2 && it[0] == "t" && it[1] == "teleport" }?.let { repo.markTeleported(event.pubkey) } event.tags.find { it.size >= 2 && it[0] == "t" && it[1] == "teleport" }?.let { repo.markTeleported(pubkey) }
// Register a geohash DM alias for this participant so MessageRouter can route DMs via Nostr // Register a geohash DM alias for this participant so MessageRouter can route DMs via Nostr
try { try {
com.bitchat.android.nostr.GeohashAliasRegistry.put("nostr_${event.pubkey.take(16)}", event.pubkey) com.bitchat.android.nostr.GeohashAliasRegistry.put("nostr_${pubkey.take(16)}", pubkey)
} catch (_: Exception) { } } catch (_: Exception) { }
// Stop here for presence events - they don't produce chat messages // Stop here for presence events - they don't produce chat messages
@@ -82,13 +85,13 @@ class GeohashMessageHandler(
// Skip our own events for message emission // Skip our own events for message emission
val my = NostrIdentityBridge.deriveIdentity(subscribedGeohash, application) val my = NostrIdentityBridge.deriveIdentity(subscribedGeohash, application)
if (my.publicKeyHex.equals(event.pubkey, true)) return@launch if (my.publicKeyHex.equals(pubkey, true)) return@launch
val isTeleportPresence = event.tags.any { it.size >= 2 && it[0] == "t" && it[1] == "teleport" } && val isTeleportPresence = event.tags.any { it.size >= 2 && it[0] == "t" && it[1] == "teleport" } &&
event.content.trim().isEmpty() event.content.trim().isEmpty()
if (isTeleportPresence) return@launch if (isTeleportPresence) return@launch
val senderName = repo.displayNameForNostrPubkeyUI(event.pubkey) val senderName = repo.displayNameForNostrPubkeyUI(pubkey)
val hasNonce = try { NostrProofOfWork.hasNonce(event) } catch (_: Exception) { false } val hasNonce = try { NostrProofOfWork.hasNonce(event) } catch (_: Exception) { false }
val msg = BitchatMessage( val msg = BitchatMessage(
id = event.id, id = event.id,
@@ -96,8 +99,8 @@ class GeohashMessageHandler(
content = event.content, content = event.content,
timestamp = Date(event.createdAt * 1000L), timestamp = Date(event.createdAt * 1000L),
isRelay = false, isRelay = false,
originalSender = repo.displayNameForNostrPubkey(event.pubkey), originalSender = repo.displayNameForNostrPubkey(pubkey),
senderPeerID = "nostr:${event.pubkey.take(8)}", senderPeerID = "nostr:${pubkey.take(8)}",
mentions = null, mentions = null,
channel = "#$subscribedGeohash", channel = "#$subscribedGeohash",
powDifficulty = try { powDifficulty = try {
@@ -62,7 +62,8 @@ class NostrDirectMessageHandler(
return@launch return@launch
} }
val (content, senderPubkey, rumorTimestamp) = decryptResult val (content, rawSenderPubkey, rumorTimestamp) = decryptResult
val senderPubkey = rawSenderPubkey.lowercase()
// If sender is blocked for geohash contexts, drop any events from this pubkey // If sender is blocked for geohash contexts, drop any events from this pubkey
// Applies to both geohash DMs (geohash != "") and account DMs (geohash == "") // Applies to both geohash DMs (geohash != "") and account DMs (geohash == "")