Refactors cleanup (#372)

* cleanup peermanager

* cleanup geohash code

* direct connections fix

* pow display

* track disconnects too

* display pow only if enabled

* display pow only if enabled

* direct connection tracking
This commit is contained in:
callebtc
2025-09-02 22:09:44 +02:00
committed by GitHub
parent bbf5918896
commit 8b3dc71dc6
13 changed files with 181 additions and 147 deletions
@@ -242,10 +242,9 @@ class NostrGeohashService(
*/
fun sendGeohashMessage(content: String, channel: com.bitchat.android.geohash.GeohashChannel, myPeerID: String, nickname: String?) {
coroutineScope.launch {
// Generate a temporary message ID for tracking animation
val tempMessageId = "temp_${System.currentTimeMillis()}_${Random.nextInt(1000)}"
try {
// Generate a temporary message ID for tracking animation
val tempMessageId = "temp_${System.currentTimeMillis()}_${Random.nextInt(1000)}"
// Add local echo message IMMEDIATELY (with temporary ID)
val powSettingsLocal = PoWPreferenceManager.getCurrentSettings()
val localMessage = BitchatMessage(
@@ -289,12 +288,6 @@ class NostrGeohashService(
teleported = teleported
)
// Stop animation when PoW completes
if (powSettings.enabled && powSettings.difficulty > 0) {
com.bitchat.android.ui.PoWMiningTracker.stopMiningMessage(tempMessageId)
Log.d(TAG, "🎭 Stopped matrix animation for message: $tempMessageId")
}
val nostrRelayManager = NostrRelayManager.getInstance(application)
nostrRelayManager.sendEventToGeohash(
event = event,
@@ -307,8 +300,8 @@ class NostrGeohashService(
} catch (e: Exception) {
Log.e(TAG, "Failed to send geohash message: ${e.message}")
// Make sure to stop animation even if there's an error
com.bitchat.android.ui.PoWMiningTracker.stopMiningMessage("temp_${System.currentTimeMillis()}")
} finally {
com.bitchat.android.ui.PoWMiningTracker.stopMiningMessage(tempMessageId)
}
}
}
@@ -1275,6 +1268,7 @@ class NostrGeohashService(
// val mentions = messageManager.parseMentions(content, peerNicknames, nickname)
// Calculate actual PoW difficulty from the finalized event ID so we can show it for incoming messages too
val eventHasNonseTag = event.tags.any { it.isNotEmpty() && it[0] == "nonce" }
val actualPow = try { NostrProofOfWork.calculateDifficulty(event.id) } catch (e: Exception) { 0 }
val message = BitchatMessage(
@@ -1287,7 +1281,7 @@ class NostrGeohashService(
senderPeerID = "nostr:${event.pubkey.take(8)}",
mentions = null, // mentions need to be passed from outside
channel = "#$geohash",
powDifficulty = actualPow.takeIf { it > 0 }
powDifficulty = actualPow.takeIf { it > 0 && eventHasNonseTag } ?: null
)
// Store in geohash history for persistence across channel switches