diff --git a/app/src/main/java/com/rosetta/messenger/database/DatabaseService.kt b/app/src/main/java/com/rosetta/messenger/database/DatabaseService.kt index d41c0fe..269394a 100644 --- a/app/src/main/java/com/rosetta/messenger/database/DatabaseService.kt +++ b/app/src/main/java/com/rosetta/messenger/database/DatabaseService.kt @@ -1,7 +1,6 @@ package com.rosetta.messenger.database import android.content.Context -import android.util.Log import com.rosetta.messenger.crypto.CryptoManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -44,8 +43,6 @@ class DatabaseService(context: Context) { seedPhraseEncrypted: String ): Boolean = withContext(Dispatchers.IO) { try { - Log.d(TAG, "💾 Saving encrypted account to database: ${publicKey.take(20)}...") - val account = EncryptedAccountEntity( publicKey = publicKey, privateKeyEncrypted = privateKeyEncrypted, @@ -60,10 +57,8 @@ class DatabaseService(context: Context) { // 🚀 ОПТИМИЗАЦИЯ: Обновляем кэш после сохранения accountCache[publicKey] = account - Log.d(TAG, "✅ Account saved successfully") true } catch (e: Exception) { - Log.e(TAG, "❌ Failed to save account", e) false } } @@ -89,7 +84,6 @@ class DatabaseService(context: Context) { } account } catch (e: Exception) { - Log.e(TAG, "❌ Failed to load account", e) null } } @@ -102,7 +96,6 @@ class DatabaseService(context: Context) { try { accountDao.getAllAccounts() } catch (e: Exception) { - Log.e(TAG, "❌ Failed to load accounts", e) emptyList() } } @@ -121,7 +114,6 @@ class DatabaseService(context: Context) { try { accountDao.updateLastUsed(publicKey, Instant.now().toString()) } catch (e: Exception) { - Log.e(TAG, "❌ Failed to update last used", e) } } @@ -131,10 +123,8 @@ class DatabaseService(context: Context) { suspend fun deleteAccount(publicKey: String): Boolean = withContext(Dispatchers.IO) { try { accountDao.deleteAccount(publicKey) - Log.d(TAG, "🗑️ Account deleted: ${publicKey.take(20)}...") true } catch (e: Exception) { - Log.e(TAG, "❌ Failed to delete account", e) false } } @@ -146,7 +136,6 @@ class DatabaseService(context: Context) { try { accountDao.getAccountCount() > 0 } catch (e: Exception) { - Log.e(TAG, "❌ Failed to check accounts", e) false } } @@ -160,10 +149,7 @@ class DatabaseService(context: Context) { password: String ): DecryptedAccountData? = withContext(Dispatchers.IO) { try { - Log.d(TAG, "🔓 Decrypting account: ${publicKey.take(20)}...") - val encryptedAccount = getEncryptedAccount(publicKey) ?: run { - Log.e(TAG, "❌ Account not found") return@withContext null } @@ -173,11 +159,9 @@ class DatabaseService(context: Context) { encryptedAccount.privateKeyEncrypted, password ) ?: run { - Log.e(TAG, "❌ Failed to decrypt private key - returned null") return@withContext null } } catch (e: Exception) { - Log.e(TAG, "❌ Failed to decrypt private key - wrong password?", e) return@withContext null } @@ -187,11 +171,9 @@ class DatabaseService(context: Context) { encryptedAccount.seedPhraseEncrypted, password ) ?: run { - Log.e(TAG, "❌ Failed to decrypt seed phrase - returned null") return@withContext null } } catch (e: Exception) { - Log.e(TAG, "❌ Failed to decrypt seed phrase - wrong password?", e) return@withContext null } @@ -200,12 +182,6 @@ class DatabaseService(context: Context) { // Generate private key hash for protocol val privateKeyHash = CryptoManager.generatePrivateKeyHash(privateKey) - Log.d(TAG, "✅ Account decrypted successfully") - Log.d(TAG, " - Public Key: ${publicKey.take(20)}...") - Log.d(TAG, " - Private Key: [DECRYPTED]") - Log.d(TAG, " - Private Key Hash: $privateKeyHash") - Log.d(TAG, " - Seed Phrase: ${seedPhrase.size} words") - DecryptedAccountData( publicKey = publicKey, privateKey = privateKey, @@ -213,7 +189,6 @@ class DatabaseService(context: Context) { seedPhrase = seedPhrase ) } catch (e: Exception) { - Log.e(TAG, "❌ Failed to decrypt account", e) null } } diff --git a/app/src/main/java/com/rosetta/messenger/network/Protocol.kt b/app/src/main/java/com/rosetta/messenger/network/Protocol.kt index dc39678..8f5aea6 100644 --- a/app/src/main/java/com/rosetta/messenger/network/Protocol.kt +++ b/app/src/main/java/com/rosetta/messenger/network/Protocol.kt @@ -1,6 +1,5 @@ package com.rosetta.messenger.network -import android.util.Log import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -35,7 +34,6 @@ class Protocol( } private fun log(message: String) { - Log.d(TAG, message) logger(message) } diff --git a/app/src/main/java/com/rosetta/messenger/network/ProtocolManager.kt b/app/src/main/java/com/rosetta/messenger/network/ProtocolManager.kt index 1bc08f8..e6369d2 100644 --- a/app/src/main/java/com/rosetta/messenger/network/ProtocolManager.kt +++ b/app/src/main/java/com/rosetta/messenger/network/ProtocolManager.kt @@ -1,7 +1,6 @@ package com.rosetta.messenger.network import android.content.Context -import android.util.Log import com.rosetta.messenger.data.MessageRepository import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow @@ -41,8 +40,6 @@ object ProtocolManager { fun addLog(message: String) { val timestamp = dateFormat.format(Date()) val logLine = "[$timestamp] $message" - // Только Logcat - быстро и не блокирует UI - Log.d(TAG, logLine) // UI логи отключены по умолчанию - вызывали ANR из-за перекомпозиций if (uiLogsEnabled) { diff --git a/app/src/main/java/com/rosetta/messenger/providers/AuthState.kt b/app/src/main/java/com/rosetta/messenger/providers/AuthState.kt index 5893ba8..3b5c306 100644 --- a/app/src/main/java/com/rosetta/messenger/providers/AuthState.kt +++ b/app/src/main/java/com/rosetta/messenger/providers/AuthState.kt @@ -1,7 +1,6 @@ package com.rosetta.messenger.providers import android.content.Context -import android.util.Log import androidx.compose.runtime.* import com.rosetta.messenger.crypto.CryptoManager import com.rosetta.messenger.database.DatabaseService @@ -61,7 +60,6 @@ class AuthStateManager( // 🚀 ОПТИМИЗАЦИЯ: Используем кэш если он свежий val currentTime = System.currentTimeMillis() if (accountsCache != null && (currentTime - lastAccountsLoadTime) < accountsCacheTTL) { - Log.d(TAG, "📚 Using cached accounts list") _state.update { it.copy( hasExistingAccounts = accountsCache!!.isNotEmpty(), availableAccounts = accountsCache!! @@ -77,14 +75,11 @@ class AuthStateManager( accountsCache = accountKeys lastAccountsLoadTime = currentTime - Log.d(TAG, "📚 Loaded ${accounts.size} accounts from database") - _state.update { it.copy( hasExistingAccounts = hasAccounts, availableAccounts = accountKeys - )} +)} } catch (e: Exception) { - Log.e(TAG, "❌ Failed to load accounts", e) } } @@ -101,7 +96,6 @@ class AuthStateManager( )} } } catch (e: Exception) { - Log.e(TAG, "❌ Failed to check auth status", e) _state.update { it.copy( status = AuthStatus.Unauthenticated )} @@ -118,31 +112,21 @@ class AuthStateManager( password: String ): Result = withContext(Dispatchers.Default) { try { - Log.d(TAG, "🔧 Creating new account from seed phrase") - Log.d(TAG, " - Seed phrase: ${seedPhrase.size} words") - Log.d(TAG, " - Password length: ${password.length}") - // Step 1: Generate key pair from seed phrase (using BIP39) val keyPair = CryptoManager.generateKeyPairFromSeed(seedPhrase) - Log.d(TAG, "🔑 Generated keys from seed phrase") - Log.d(TAG, " - Public Key: ${keyPair.publicKey.take(20)}...") - Log.d(TAG, " - Private Key length: ${keyPair.privateKey.length}") // Step 2: Generate private key hash for protocol val privateKeyHash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey) - Log.d(TAG, "🔐 Generated private key hash: $privateKeyHash") // Step 3: Encrypt private key with password val encryptedPrivateKey = CryptoManager.encryptWithPassword( keyPair.privateKey, password ) - Log.d(TAG, "🔒 Encrypted private key: ${encryptedPrivateKey.take(50)}...") // Step 4: Encrypt seed phrase with password val encryptedSeedPhrase = CryptoManager.encryptWithPassword( seedPhrase.joinToString(" "), password ) - Log.d(TAG, "🔒 Encrypted seed phrase: ${encryptedSeedPhrase.take(50)}...") // Step 5: Save to database val saved = withContext(Dispatchers.IO) { @@ -157,8 +141,6 @@ class AuthStateManager( return@withContext Result.failure(Exception("Failed to save account to database")) } - Log.d(TAG, "✅ Account saved to database successfully") - // Step 6: Create decrypted account object val decryptedAccount = DecryptedAccountData( publicKey = keyPair.publicKey, @@ -176,19 +158,15 @@ class AuthStateManager( loadAccounts() // Step 8: Connect and authenticate with protocol - Log.d(TAG, "🌐 Connecting to protocol server...") ProtocolManager.connect() // Give WebSocket time to connect before authenticating kotlinx.coroutines.delay(500) - Log.d(TAG, "🌐 Authenticating with protocol server...") ProtocolManager.authenticate(keyPair.publicKey, privateKeyHash) - Log.d(TAG, "✅ Account created and authenticated successfully!") Result.success(decryptedAccount) } catch (e: Exception) { - Log.e(TAG, "❌ Failed to create account", e) Result.failure(e) } } @@ -200,7 +178,6 @@ class AuthStateManager( seedPhrase: List, password: String ): Result { - Log.d(TAG, "📥 Importing account from seed phrase") return createAccount(seedPhrase, password) } @@ -213,24 +190,15 @@ class AuthStateManager( password: String ): Result = withContext(Dispatchers.Default) { try { - Log.d(TAG, "🔓 Unlocking account: ${publicKey.take(20)}...") - Log.d(TAG, " - Password length: ${password.length}") - // Decrypt account from database val decryptedAccount = withContext(Dispatchers.IO) { databaseService.decryptAccount(publicKey, password) } if (decryptedAccount == null) { - Log.e(TAG, "❌ Failed to decrypt account - wrong password or account not found") return@withContext Result.failure(Exception("Invalid password or account not found")) } - Log.d(TAG, "✅ Account decrypted successfully") - Log.d(TAG, " - Public Key: ${decryptedAccount.publicKey.take(20)}...") - Log.d(TAG, " - Private Key Hash: ${decryptedAccount.privateKeyHash}") - Log.d(TAG, " - Seed Phrase: ${decryptedAccount.seedPhrase.size} words") - // Update last used timestamp withContext(Dispatchers.IO) { databaseService.updateLastUsed(publicKey) @@ -243,19 +211,15 @@ class AuthStateManager( )} // Connect and authenticate with protocol - Log.d(TAG, "🌐 Connecting to protocol server...") ProtocolManager.connect() // Give WebSocket time to connect before authenticating kotlinx.coroutines.delay(500) - Log.d(TAG, "🌐 Authenticating with protocol server...") ProtocolManager.authenticate(decryptedAccount.publicKey, decryptedAccount.privateKeyHash) - Log.d(TAG, "✅ Account unlocked and authenticated successfully!") Result.success(decryptedAccount) } catch (e: Exception) { - Log.e(TAG, "❌ Failed to unlock account", e) Result.failure(e) } } @@ -264,7 +228,6 @@ class AuthStateManager( * Logout - clears decrypted account from memory */ fun logout() { - Log.d(TAG, "🚪 Logging out, clearing decrypted keys from memory") currentDecryptedAccount = null _state.update { it.copy( status = AuthStatus.Unauthenticated @@ -276,8 +239,6 @@ class AuthStateManager( */ suspend fun deleteAccount(publicKey: String): Result = withContext(Dispatchers.IO) { try { - Log.d(TAG, "🗑️ Deleting account: ${publicKey.take(20)}...") - val success = databaseService.deleteAccount(publicKey) if (!success) { return@withContext Result.failure(Exception("Failed to delete account")) @@ -291,10 +252,8 @@ class AuthStateManager( } loadAccounts() - Log.d(TAG, "✅ Account deleted successfully") Result.success(Unit) } catch (e: Exception) { - Log.e(TAG, "❌ Failed to delete account", e) Result.failure(e) } } diff --git a/app/src/main/java/com/rosetta/messenger/ui/auth/SetPasswordScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/auth/SetPasswordScreen.kt index 352d285..90e10b0 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/auth/SetPasswordScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/auth/SetPasswordScreen.kt @@ -1,6 +1,5 @@ package com.rosetta.messenger.ui.auth -import android.util.Log import androidx.compose.animation.* import androidx.compose.animation.core.* import androidx.compose.foundation.* @@ -497,7 +496,6 @@ fun SetPasswordScreen( // 🔌 Connect to server and authenticate val privateKeyHash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey) - Log.d("SetPasswordScreen", "🔌 Connecting to server...") ProtocolManager.connect() // Give WebSocket time to connect before authenticating kotlinx.coroutines.delay(500) diff --git a/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt index 3ccee7c..58d7671 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt @@ -1,6 +1,5 @@ package com.rosetta.messenger.ui.auth -import android.util.Log import androidx.compose.animation.* import androidx.compose.animation.core.* import androidx.compose.foundation.* @@ -86,7 +85,6 @@ fun UnlockScreen( LaunchedEffect(Unit) { // ⚡ СИНХРОННОЕ чтение последнего аккаунта ДО загрузки списка val lastLoggedKey = accountManager.getLastLoggedPublicKey() - Log.d("UnlockScreen", "🔍 Last logged account from SharedPrefs: ${lastLoggedKey?.take(16) ?: "none"}") val allAccounts = accountManager.getAllAccounts() accounts = allAccounts.map { acc -> @@ -97,26 +95,20 @@ fun UnlockScreen( ) } - Log.d("UnlockScreen", "📋 Available accounts: ${accounts.map { "${it.name}:${it.publicKey.take(8)}" }}") - // Find the target account - приоритет: selectedAccountId > lastLoggedKey > первый val targetAccount = when { !selectedAccountId.isNullOrEmpty() -> { - Log.d("UnlockScreen", "✅ Using selectedAccountId: ${selectedAccountId.take(16)}") accounts.find { it.publicKey == selectedAccountId } } !lastLoggedKey.isNullOrEmpty() -> { - Log.d("UnlockScreen", "✅ Using lastLoggedKey: ${lastLoggedKey.take(16)}") accounts.find { it.publicKey == lastLoggedKey } } else -> { - Log.d("UnlockScreen", "⚠️ No preference, using first account") accounts.firstOrNull() } } selectedAccount = targetAccount ?: accounts.firstOrNull() - Log.d("UnlockScreen", "🎯 Final selected: ${selectedAccount?.name} (${selectedAccount?.publicKey?.take(16)})") } // Filter accounts by search @@ -580,7 +572,6 @@ fun UnlockScreen( ) // Connect to server and authenticate - Log.d("UnlockScreen", "Connecting to server...") ProtocolManager.connect() // Give WebSocket time to connect before authenticating kotlinx.coroutines.delay(500) diff --git a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatViewModel.kt b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatViewModel.kt index 44222b8..bacdb48 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatViewModel.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatViewModel.kt @@ -1,7 +1,6 @@ package com.rosetta.messenger.ui.chats import android.app.Application -import android.util.Log import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.rosetta.messenger.crypto.CryptoManager @@ -203,7 +202,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { // 🔥 Проверяем блокировку (как в Архиве) val isBlocked = database.blacklistDao().isUserBlocked(packet.fromPublicKey, account) if (isBlocked) { - Log.d(TAG, "🚫 BLOCKED: Ignoring message from blocked user ${packet.fromPublicKey.take(20)}...") return@launch } @@ -315,7 +313,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { // (через markVisibleMessagesAsRead вызываемый из ChatDetailScreen) } catch (e: Exception) { - Log.e(TAG, "Incoming message error", e) } } } @@ -334,7 +331,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { try { messageDao.updateDeliveryStatus(account, messageId, delivered) } catch (e: Exception) { - Log.e(TAG, "Update delivery status error", e) } } @@ -485,7 +481,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { isLoadingMessages = false } catch (e: Exception) { - Log.e(TAG, "Error loading messages", e) withContext(Dispatchers.Main.immediate) { _isLoading.value = false } @@ -583,7 +578,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { isLoadingMessages = false } catch (e: Exception) { - Log.e(TAG, "Error loading more messages", e) withContext(Dispatchers.Main) { _isLoadingMore.value = false } @@ -729,7 +723,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { } null } catch (e: Exception) { - Log.e(TAG, "Error parsing reply from attachments", e) null } } @@ -839,8 +832,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { * - Поддержка Reply/Forward через attachments (как в React Native) */ fun sendMessage() { - Log.d(TAG, "🚀🚀🚀 sendMessage() CALLED 🚀🚀🚀") - val text = _inputText.value.trim() val recipient = opponentKey val sender = myPublicKey @@ -848,33 +839,20 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { val replyMsgs = _replyMessages.value val isForward = _isForwardMode.value - Log.d(TAG, "📝 Text: '$text'") - Log.d(TAG, "📧 Recipient: ${recipient?.take(16)}") - Log.d(TAG, "👤 Sender: ${sender?.take(16)}") - Log.d(TAG, "🔑 PrivateKey exists: ${privateKey != null}") - Log.d(TAG, "💬 ReplyMsgs: ${replyMsgs.size}") - - // Разрешаем отправку пустого текста если есть reply/forward if (text.isEmpty() && replyMsgs.isEmpty()) { - Log.e(TAG, "❌ Empty text and no reply") return } if (recipient == null) { - Log.e(TAG, "❌ No recipient") return } if (sender == null || privateKey == null) { - Log.e(TAG, "❌ No keys - sender: $sender, privateKey: $privateKey") return } if (isSending) { - Log.w(TAG, "⏳ Already sending...") return } - Log.d(TAG, "✅ All checks passed, starting send...") - isSending = true val messageId = UUID.randomUUID().toString().replace("-", "").take(32) @@ -969,18 +947,8 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { attachments = messageAttachments } - // 🔥 Log packet details before sending - Log.d(TAG, "📦 PACKET READY TO SEND:") - Log.d(TAG, " - messageId: $messageId") - Log.d(TAG, " - text: '$text'") - Log.d(TAG, " - attachments count: ${packet.attachments.size}") - packet.attachments.forEach { att -> - Log.d(TAG, " - attachment: type=${att.type}, id=${att.id}, blob.length=${att.blob.length}") - } - // Отправляем пакет ProtocolManager.send(packet) - Log.d(TAG, "✅ PACKET SENT via ProtocolManager.send()") // 3. 🎯 UI обновление в Main потоке withContext(Dispatchers.Main) { @@ -1016,7 +984,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { saveDialog(text, timestamp) } catch (e: Exception) { - Log.e(TAG, "Send error", e) withContext(Dispatchers.Main) { updateMessageStatus(messageId, MessageStatus.SENT) // Changed from ERROR } @@ -1038,10 +1005,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { // 🔥 КРИТИЧНО: Используем updateDialogFromMessages который пересчитывает счетчики // напрямую из таблицы messages, как в Архиве! dialogDao.updateDialogFromMessages(account, opponent) - - Log.d(TAG, "✅ Dialog saved/updated from messages table") } catch (e: Exception) { - Log.e(TAG, "Dialog save error", e) } } @@ -1056,10 +1020,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { // напрямую из таблицы messages, как в Архиве! // Это гарантирует что unread_count всегда соответствует реальному количеству непрочитанных dialogDao.updateDialogFromMessages(account, opponentKey) - - Log.d(TAG, "✅ Dialog updated from messages table for $opponentKey") } catch (e: Exception) { - Log.e(TAG, "updateDialog error", e) } } @@ -1121,7 +1082,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { val insertedId = messageDao.insertMessage(entity) } catch (e: Exception) { - Log.e(TAG, "Message save error", e) } } @@ -1166,7 +1126,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { ProtocolManager.send(packet) } catch (e: Exception) { - Log.e(TAG, "Typing send error", e) } } } @@ -1206,7 +1165,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { ProtocolManager.send(packet) readReceiptSentForCurrentDialog = true } catch (e: Exception) { - Log.e(TAG, "Read receipt send error", e) } } } @@ -1240,7 +1198,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { // 🔥 Пересчитываем счетчики из messages dialogDao.updateDialogFromMessages(account, opponent) } catch (e: Exception) { - Log.e(TAG, "Mark as read error", e) } } @@ -1266,7 +1223,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) { ProtocolManager.send(packet) } catch (e: Exception) { - Log.e(TAG, "Online subscribe error", e) } } } diff --git a/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiPicker.kt b/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiPicker.kt index a244f4e..dde9718 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiPicker.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/components/AppleEmojiPicker.kt @@ -1,7 +1,6 @@ package com.rosetta.messenger.ui.components import android.content.Context -import android.util.Log import androidx.compose.animation.core.* import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -402,9 +401,7 @@ object EmojiCache { allEmojis = emojis emojisByCategory = groupEmojis(emojis) - Log.d("EmojiCache", "Loaded ${emojis.size} emojis") } catch (e: Exception) { - Log.e("EmojiCache", "Error loading emojis", e) allEmojis = emptyList() emojisByCategory = emptyMap() }