diff --git a/app/src/main/java/com/bitchat/android/nostr/GeohashMessageHandler.kt b/app/src/main/java/com/bitchat/android/nostr/GeohashMessageHandler.kt index ec3af4e6..b318ef69 100644 --- a/app/src/main/java/com/bitchat/android/nostr/GeohashMessageHandler.kt +++ b/app/src/main/java/com/bitchat/android/nostr/GeohashMessageHandler.kt @@ -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) - if (dataManager.isGeohashUserBlocked(event.pubkey)) return@launch + if (dataManager.isGeohashUserBlocked(pubkey)) return@launch // Update repository (participants, nickname, teleport) // 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 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] == "t" && it[1] == "teleport" }?.let { repo.markTeleported(event.pubkey) } + 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(pubkey) } // Register a geohash DM alias for this participant so MessageRouter can route DMs via Nostr 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) { } // Stop here for presence events - they don't produce chat messages @@ -82,13 +85,13 @@ class GeohashMessageHandler( // Skip our own events for message emission 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" } && event.content.trim().isEmpty() 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 msg = BitchatMessage( id = event.id, @@ -96,8 +99,8 @@ class GeohashMessageHandler( content = event.content, timestamp = Date(event.createdAt * 1000L), isRelay = false, - originalSender = repo.displayNameForNostrPubkey(event.pubkey), - senderPeerID = "nostr:${event.pubkey.take(8)}", + originalSender = repo.displayNameForNostrPubkey(pubkey), + senderPeerID = "nostr:${pubkey.take(8)}", mentions = null, channel = "#$subscribedGeohash", powDifficulty = try { diff --git a/app/src/main/java/com/bitchat/android/nostr/NostrDirectMessageHandler.kt b/app/src/main/java/com/bitchat/android/nostr/NostrDirectMessageHandler.kt index 18c12e4d..b2526810 100644 --- a/app/src/main/java/com/bitchat/android/nostr/NostrDirectMessageHandler.kt +++ b/app/src/main/java/com/bitchat/android/nostr/NostrDirectMessageHandler.kt @@ -62,7 +62,8 @@ class NostrDirectMessageHandler( 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 // Applies to both geohash DMs (geohash != "") and account DMs (geohash == "")