feat: Remove debug logging from various components for cleaner code

This commit is contained in:
k1ngsterr1
2026-01-14 04:43:32 +05:00
parent 5f6cde3885
commit 42d2eb9e9c
8 changed files with 1 additions and 130 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}
}
}

View File

@@ -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()
}