From 6d74893eb37e1f9142e4b71cdd456bf29cca30b5 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 30 Aug 2025 16:59:06 +0200 Subject: [PATCH] pow in message timestamp --- .../java/com/bitchat/android/model/BitchatMessage.kt | 3 ++- .../com/bitchat/android/nostr/NostrGeohashService.kt | 10 ++++++++-- .../main/java/com/bitchat/android/ui/ChatUIUtils.kt | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/model/BitchatMessage.kt b/app/src/main/java/com/bitchat/android/model/BitchatMessage.kt index c3681720..5bce45a9 100644 --- a/app/src/main/java/com/bitchat/android/model/BitchatMessage.kt +++ b/app/src/main/java/com/bitchat/android/model/BitchatMessage.kt @@ -59,7 +59,8 @@ data class BitchatMessage( val channel: String? = null, val encryptedContent: ByteArray? = null, val isEncrypted: Boolean = false, - val deliveryStatus: DeliveryStatus? = null + val deliveryStatus: DeliveryStatus? = null, + val powDifficulty: Int? = null ) : Parcelable { /** diff --git a/app/src/main/java/com/bitchat/android/nostr/NostrGeohashService.kt b/app/src/main/java/com/bitchat/android/nostr/NostrGeohashService.kt index 88d5c762..17462712 100644 --- a/app/src/main/java/com/bitchat/android/nostr/NostrGeohashService.kt +++ b/app/src/main/java/com/bitchat/android/nostr/NostrGeohashService.kt @@ -247,6 +247,7 @@ class NostrGeohashService( val tempMessageId = "temp_${System.currentTimeMillis()}_${Random.nextInt(1000)}" // Add local echo message IMMEDIATELY (with temporary ID) + val powSettingsLocal = PoWPreferenceManager.getCurrentSettings() val localMessage = BitchatMessage( id = tempMessageId, sender = nickname ?: myPeerID, @@ -254,7 +255,8 @@ class NostrGeohashService( timestamp = Date(), isRelay = false, senderPeerID = "geohash:${channel.geohash}", - channel = "#${channel.geohash}" + channel = "#${channel.geohash}", + powDifficulty = if (powSettingsLocal.enabled) powSettingsLocal.difficulty else null ) // Store and display the message immediately @@ -1272,6 +1274,9 @@ class NostrGeohashService( // Note: mentions parsing needs peer nicknames parameter // 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( id = event.id, sender = senderName, @@ -1281,7 +1286,8 @@ class NostrGeohashService( originalSender = senderHandle, senderPeerID = "nostr:${event.pubkey.take(8)}", 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 diff --git a/app/src/main/java/com/bitchat/android/ui/ChatUIUtils.kt b/app/src/main/java/com/bitchat/android/ui/ChatUIUtils.kt index bdb2fa1f..29f40176 100644 --- a/app/src/main/java/com/bitchat/android/ui/ChatUIUtils.kt +++ b/app/src/main/java/com/bitchat/android/ui/ChatUIUtils.kt @@ -117,11 +117,18 @@ fun formatMessageAsAnnotatedString( appendIOSFormattedContent(builder, message.content, message.mentions, currentUserNickname, baseColor, isSelf, isDark) // iOS-style timestamp at the END (smaller, grey) + // Timestamp (and optional PoW badge) builder.pushStyle(SpanStyle( color = Color.Gray.copy(alpha = 0.7f), fontSize = (BASE_FONT_SIZE - 4).sp )) 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() } else {