From 9d7e656ceb70f607af06d36249567b50050d3cff Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 30 Aug 2025 17:17:57 +0200 Subject: [PATCH] pow works --- .../android/ui/MatrixEncryptionAnimation.kt | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/ui/MatrixEncryptionAnimation.kt b/app/src/main/java/com/bitchat/android/ui/MatrixEncryptionAnimation.kt index 9a8a5ea5..f16c2f89 100644 --- a/app/src/main/java/com/bitchat/android/ui/MatrixEncryptionAnimation.kt +++ b/app/src/main/java/com/bitchat/android/ui/MatrixEncryptionAnimation.kt @@ -282,14 +282,23 @@ private fun AnimatedMessageDisplay( // Create a temporary message with animated content for formatting val animatedMessage = message.copy(content = animatedContent) - // Use the EXACT same formatting function as normal messages, including timestamp - val annotatedText = formatMessageAsAnnotatedString( - message = animatedMessage, - currentUserNickname = currentUserNickname, - meshService = meshService, - colorScheme = colorScheme, - timeFormatter = timeFormatter - ) + // Use formatting function without timestamp during animation + val annotatedText = if (isAnimating) { + formatMessageAsAnnotatedStringWithoutTimestamp( + message = animatedMessage, + currentUserNickname = currentUserNickname, + meshService = meshService, + colorScheme = colorScheme + ) + } else { + formatMessageAsAnnotatedString( + message = animatedMessage, + currentUserNickname = currentUserNickname, + meshService = meshService, + colorScheme = colorScheme, + timeFormatter = timeFormatter + ) + } // Use IDENTICAL Text composable structure as normal message Text( @@ -305,3 +314,40 @@ private fun AnimatedMessageDisplay( } +/** + * Format message without timestamp and PoW badge for animation phase + * Identical to formatMessageAsAnnotatedString but excludes timestamp and PoW badge + */ +private fun formatMessageAsAnnotatedStringWithoutTimestamp( + message: com.bitchat.android.model.BitchatMessage, + currentUserNickname: String, + meshService: com.bitchat.android.mesh.BluetoothMeshService, + colorScheme: androidx.compose.material3.ColorScheme +): AnnotatedString { + // Get the full formatted text first + val timeFormatter = java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.getDefault()) + val fullText = formatMessageAsAnnotatedString( + message = message, + currentUserNickname = currentUserNickname, + meshService = meshService, + colorScheme = colorScheme, + timeFormatter = timeFormatter + ) + + // Find and remove the timestamp and PoW badge at the end + val text = fullText.text + val timestampPattern = """ \[\d{2}:\d{2}:\d{2}].*$""".toRegex() // Matches " [HH:mm:ss] 12b" or just " [HH:mm:ss]" + val match = timestampPattern.find(text) + + return if (match != null) { + // Remove timestamp and PoW portion + val endIndex = match.range.first + AnnotatedString( + text = text.substring(0, endIndex), + spanStyles = fullText.spanStyles.filter { it.end <= endIndex }, + paragraphStyles = fullText.paragraphStyles.filter { it.end <= endIndex } + ) + } else { + fullText + } +}