mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 01:45:22 +00:00
Merge branch 'main' into gossip-graph
This commit is contained in:
@@ -284,6 +284,13 @@ class BluetoothMeshService(private val context: Context) {
|
||||
|
||||
// Store fingerprint for the peer via centralized fingerprint manager
|
||||
val fingerprint = peerManager.storeFingerprintForPeer(newPeerID, publicKey)
|
||||
|
||||
// Index existing Nostr mapping by the new peerID if we have it
|
||||
try {
|
||||
com.bitchat.android.favorites.FavoritesPersistenceService.shared.findNostrPubkey(publicKey)?.let { npub ->
|
||||
com.bitchat.android.favorites.FavoritesPersistenceService.shared.updateNostrPublicKeyForPeerID(newPeerID, npub)
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
|
||||
// If there was a previous peer ID, remove it to avoid duplicates
|
||||
previousPeerID?.let { oldPeerID ->
|
||||
@@ -543,25 +550,13 @@ class BluetoothMeshService(private val context: Context) {
|
||||
*/
|
||||
fun sendPrivateMessage(content: String, recipientPeerID: String, recipientNickname: String, messageID: String? = null) {
|
||||
if (content.isEmpty() || recipientPeerID.isEmpty()) return
|
||||
if (!recipientPeerID.startsWith("nostr_") && recipientNickname.isEmpty()) return
|
||||
if (recipientNickname.isEmpty()) return
|
||||
|
||||
serviceScope.launch {
|
||||
val finalMessageID = messageID ?: java.util.UUID.randomUUID().toString()
|
||||
|
||||
Log.d(TAG, "📨 Sending PM to $recipientPeerID: ${content.take(30)}...")
|
||||
|
||||
// Check if this is a Nostr contact (geohash DM)
|
||||
if (recipientPeerID.startsWith("nostr_")) {
|
||||
// Get NostrGeohashService instance and send via Nostr
|
||||
try {
|
||||
val nostrGeohashService = com.bitchat.android.nostr.NostrGeohashService.getInstance(context.applicationContext as android.app.Application)
|
||||
nostrGeohashService.sendNostrGeohashDM(content, recipientPeerID, finalMessageID, myPeerID)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to send Nostr geohash DM: ${e.message}")
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Check if we have an established Noise session
|
||||
if (encryptionService.hasEstablishedSession(recipientPeerID)) {
|
||||
try {
|
||||
@@ -629,15 +624,14 @@ class BluetoothMeshService(private val context: Context) {
|
||||
serviceScope.launch {
|
||||
Log.d(TAG, "📖 Sending read receipt for message $messageID to $recipientPeerID")
|
||||
|
||||
// Check if this is a Nostr contact (geohash DM)
|
||||
if (recipientPeerID.startsWith("nostr_")) {
|
||||
// Get NostrGeohashService instance and send read receipt via Nostr
|
||||
try {
|
||||
val nostrGeohashService = com.bitchat.android.nostr.NostrGeohashService.getInstance(context.applicationContext as android.app.Application)
|
||||
nostrGeohashService.sendNostrGeohashReadReceipt(messageID, recipientPeerID, myPeerID)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to send Nostr geohash read receipt: ${e.message}")
|
||||
}
|
||||
// Route geohash read receipts via MessageRouter instead of here
|
||||
val geo = runCatching { com.bitchat.android.services.MessageRouter.tryGetInstance() }.getOrNull()
|
||||
val isGeoAlias = try {
|
||||
val map = com.bitchat.android.nostr.GeohashAliasRegistry.snapshot()
|
||||
map.containsKey(recipientPeerID)
|
||||
} catch (_: Exception) { false }
|
||||
if (isGeoAlias && geo != null) {
|
||||
geo.sendReadReceipt(com.bitchat.android.model.ReadReceipt(messageID), recipientPeerID)
|
||||
return@launch
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user