mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 06:05:21 +00:00
pow in message timestamp
This commit is contained in:
@@ -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 {
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user