mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 07:25:20 +00:00
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:
@@ -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
|
||||
|
||||
@@ -16,8 +16,8 @@ object PoWPreferenceManager {
|
||||
private const val KEY_POW_DIFFICULTY = "pow_difficulty"
|
||||
|
||||
// Default values
|
||||
private const val DEFAULT_POW_ENABLED = true
|
||||
private const val DEFAULT_POW_DIFFICULTY = 10 // Reasonable default for geohash spam prevention
|
||||
private const val DEFAULT_POW_ENABLED = false
|
||||
private const val DEFAULT_POW_DIFFICULTY = 16 // Reasonable default for geohash spam prevention
|
||||
|
||||
// State flows for reactive UI
|
||||
private val _powEnabled = MutableStateFlow(DEFAULT_POW_ENABLED)
|
||||
|
||||
Reference in New Issue
Block a user