pow in message timestamp

This commit is contained in:
callebtc
2025-08-30 16:59:06 +02:00
parent 9d9ee1e413
commit 6d74893eb3
3 changed files with 17 additions and 3 deletions
@@ -59,7 +59,8 @@ data class BitchatMessage(
val channel: String? = null, val channel: String? = null,
val encryptedContent: ByteArray? = null, val encryptedContent: ByteArray? = null,
val isEncrypted: Boolean = false, val isEncrypted: Boolean = false,
val deliveryStatus: DeliveryStatus? = null val deliveryStatus: DeliveryStatus? = null,
val powDifficulty: Int? = null
) : Parcelable { ) : Parcelable {
/** /**
@@ -247,6 +247,7 @@ class NostrGeohashService(
val tempMessageId = "temp_${System.currentTimeMillis()}_${Random.nextInt(1000)}" val tempMessageId = "temp_${System.currentTimeMillis()}_${Random.nextInt(1000)}"
// Add local echo message IMMEDIATELY (with temporary ID) // Add local echo message IMMEDIATELY (with temporary ID)
val powSettingsLocal = PoWPreferenceManager.getCurrentSettings()
val localMessage = BitchatMessage( val localMessage = BitchatMessage(
id = tempMessageId, id = tempMessageId,
sender = nickname ?: myPeerID, sender = nickname ?: myPeerID,
@@ -254,7 +255,8 @@ class NostrGeohashService(
timestamp = Date(), timestamp = Date(),
isRelay = false, isRelay = false,
senderPeerID = "geohash:${channel.geohash}", senderPeerID = "geohash:${channel.geohash}",
channel = "#${channel.geohash}" channel = "#${channel.geohash}",
powDifficulty = if (powSettingsLocal.enabled) powSettingsLocal.difficulty else null
) )
// Store and display the message immediately // Store and display the message immediately
@@ -1272,6 +1274,9 @@ class NostrGeohashService(
// Note: mentions parsing needs peer nicknames parameter // Note: mentions parsing needs peer nicknames parameter
// val mentions = messageManager.parseMentions(content, peerNicknames, nickname) // 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 actualPow = try { NostrProofOfWork.calculateDifficulty(event.id) } catch (e: Exception) { 0 }
val message = BitchatMessage( val message = BitchatMessage(
id = event.id, id = event.id,
sender = senderName, sender = senderName,
@@ -1281,7 +1286,8 @@ class NostrGeohashService(
originalSender = senderHandle, originalSender = senderHandle,
senderPeerID = "nostr:${event.pubkey.take(8)}", senderPeerID = "nostr:${event.pubkey.take(8)}",
mentions = null, // mentions need to be passed from outside mentions = null, // mentions need to be passed from outside
channel = "#$geohash" channel = "#$geohash",
powDifficulty = actualPow.takeIf { it > 0 }
) )
// Store in geohash history for persistence across channel switches // Store in geohash history for persistence across channel switches
@@ -117,11 +117,18 @@ fun formatMessageAsAnnotatedString(
appendIOSFormattedContent(builder, message.content, message.mentions, currentUserNickname, baseColor, isSelf, isDark) appendIOSFormattedContent(builder, message.content, message.mentions, currentUserNickname, baseColor, isSelf, isDark)
// iOS-style timestamp at the END (smaller, grey) // iOS-style timestamp at the END (smaller, grey)
// Timestamp (and optional PoW badge)
builder.pushStyle(SpanStyle( builder.pushStyle(SpanStyle(
color = Color.Gray.copy(alpha = 0.7f), color = Color.Gray.copy(alpha = 0.7f),
fontSize = (BASE_FONT_SIZE - 4).sp fontSize = (BASE_FONT_SIZE - 4).sp
)) ))
builder.append(" [${timeFormatter.format(message.timestamp)}]") builder.append(" [${timeFormatter.format(message.timestamp)}]")
// If message has valid PoW difficulty, append bits immediately after timestamp with minimal spacing
message.powDifficulty?.let { bits ->
if (bits > 0) {
builder.append(" ${bits}b")
}
}
builder.pop() builder.pop()
} else { } else {