Remove unnecessary logging statements across various components to clean up code and improve readability. This includes removing debug, error, and warning logs from attachment handling, image processing, media loading, and profile management functionalities. Additionally, a script has been added to automate the removal of log statements from Kotlin files.

This commit is contained in:
k1ngsterr1
2026-01-31 05:20:32 +05:00
parent 430c7d9007
commit c249278421
28 changed files with 0 additions and 506 deletions

View File

@@ -1,7 +1,6 @@
package com.rosetta.messenger.data
import android.content.Context
import android.util.Log
import com.rosetta.messenger.crypto.CryptoManager
import com.rosetta.messenger.crypto.MessageCrypto
import com.rosetta.messenger.database.*
@@ -204,7 +203,6 @@ class MessageRepository private constructor(private val context: Context) {
// 🔑 КРИТИЧНО: Сохраняем ЗАШИФРОВАННЫЙ chacha_key (как в Desktop!)
// Desktop хранит зашифрованный ключ, расшифровывает только при использовании
android.util.Log.d("MessageRepository", "🔑 Outgoing chacha_key (encrypted): ${encryptedKey.length} chars")
// Сериализуем attachments в JSON
val attachmentsJson = serializeAttachments(attachments)
@@ -235,16 +233,13 @@ class MessageRepository private constructor(private val context: Context) {
)
messageDao.insertMessage(entity)
Log.d("MessageRepository", "<EFBFBD> Inserted OUTGOING message: fromMe=1, delivered=${entity.delivered}, read=0")
}
// 🔥 КРИТИЧНО: Обновляем диалог через updateDialogFromMessages
Log.d("MessageRepository", "🔄 Calling updateDialogFromMessages after sending...")
dialogDao.updateDialogFromMessages(account, toPublicKey)
// 🔥 Логируем что записалось в диалог
val dialog = dialogDao.getDialog(account, toPublicKey)
Log.d("MessageRepository", "🎯 DIALOG AFTER SEND: lastMsgFromMe=${dialog?.lastMessageFromMe}, delivered=${dialog?.lastMessageDelivered}, read=${dialog?.lastMessageRead}")
// 🔥 Отмечаем что я отправлял сообщения в этот диалог (перемещает из requests в chats)
val updatedRows = dialogDao.markIHaveSent(account, toPublicKey)
@@ -316,7 +311,6 @@ class MessageRepository private constructor(private val context: Context) {
// 🔑 КРИТИЧНО: Сохраняем ЗАШИФРОВАННЫЙ chacha_key (как в Desktop!)
// Desktop: хранит зашифрованный ключ, расшифровывает только при использовании
// Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8')
android.util.Log.d("MessageRepository", "🔑 Incoming chacha_key (encrypted): ${packet.chachaKey.length} chars")
// Расшифровываем
val plainText = MessageCrypto.decryptIncoming(
@@ -365,16 +359,13 @@ class MessageRepository private constructor(private val context: Context) {
// Сохраняем в БД только если сообщения нет
messageDao.insertMessage(entity)
Log.d("MessageRepository", "<EFBFBD> Inserted INCOMING message: fromMe=0, delivered=${entity.delivered}, read=0")
}
// 🔥 КРИТИЧНО: Обновляем диалог через updateDialogFromMessages
Log.d("MessageRepository", "🔄 Calling updateDialogFromMessages after incoming message...")
dialogDao.updateDialogFromMessages(account, packet.fromPublicKey)
// 🔥 Логируем что записалось в диалог
val dialog = dialogDao.getDialog(account, packet.fromPublicKey)
Log.d("MessageRepository", "🎯 DIALOG AFTER INCOMING: lastMsgFromMe=${dialog?.lastMessageFromMe}, delivered=${dialog?.lastMessageDelivered}, read=${dialog?.lastMessageRead}")
// 🔥 Запрашиваем информацию о пользователе для отображения имени вместо ключа
requestUserInfo(packet.fromPublicKey)
@@ -416,19 +407,15 @@ class MessageRepository private constructor(private val context: Context) {
suspend fun handleRead(packet: PacketRead) {
val account = currentAccount ?: return
Log.d("MessageRepository", "🔥🔥🔥 handleRead START: fromPublicKey=${packet.fromPublicKey.take(16)}...")
// Проверяем последнее сообщение ДО обновления
val lastMsgBefore = messageDao.getLastMessageDebug(account, packet.fromPublicKey)
Log.d("MessageRepository", "📊 BEFORE markAllAsRead: fromMe=${lastMsgBefore?.fromMe}, delivered=${lastMsgBefore?.delivered}, read=${lastMsgBefore?.read}, timestamp=${lastMsgBefore?.timestamp}")
// Отмечаем все наши исходящие сообщения к этому собеседнику как прочитанные
messageDao.markAllAsRead(account, packet.fromPublicKey)
Log.d("MessageRepository", "✅ markAllAsRead completed")
// 🔥 DEBUG: Проверяем последнее сообщение ПОСЛЕ обновления
val lastMsgAfter = messageDao.getLastMessageDebug(account, packet.fromPublicKey)
Log.d("MessageRepository", "📊 AFTER markAllAsRead: fromMe=${lastMsgAfter?.fromMe}, delivered=${lastMsgAfter?.delivered}, read=${lastMsgAfter?.read}, timestamp=${lastMsgAfter?.timestamp}")
// Обновляем кэш - все исходящие сообщения помечаем как прочитанные
val dialogKey = getDialogKey(packet.fromPublicKey)
@@ -440,13 +427,10 @@ class MessageRepository private constructor(private val context: Context) {
}
// 🔥 КРИТИЧНО: Обновляем диалог чтобы lastMessageRead обновился
Log.d("MessageRepository", "🔄 Calling updateDialogFromMessages...")
dialogDao.updateDialogFromMessages(account, packet.fromPublicKey)
// Логируем что записалось в диалог
val dialog = dialogDao.getDialog(account, packet.fromPublicKey)
Log.d("MessageRepository", "🎯 DIALOG AFTER UPDATE: lastMsgFromMe=${dialog?.lastMessageFromMe}, delivered=${dialog?.lastMessageDelivered}, read=${dialog?.lastMessageRead}")
Log.d("MessageRepository", "🔥🔥🔥 handleRead END")
}
/**
@@ -640,19 +624,15 @@ class MessageRepository private constructor(private val context: Context) {
suspend fun updateDialogUserInfo(publicKey: String, title: String, username: String, verified: Int) {
val account = currentAccount ?: return
android.util.Log.d("MessageRepo", "🔄 updateDialogUserInfo: ${publicKey.take(16)}... title='$title' username='$username'")
// Проверяем существует ли диалог с этим пользователем
val existing = dialogDao.getDialog(account, publicKey)
if (existing != null) {
android.util.Log.d("MessageRepo", "✅ Updating dialog opponent info in DB for ${publicKey.take(16)}...")
dialogDao.updateOpponentInfo(account, publicKey, title, username, verified)
// 🔥 Проверим что данные сохранились
val updated = dialogDao.getDialog(account, publicKey)
android.util.Log.d("MessageRepo", "📝 After update: title='${updated?.opponentTitle}' username='${updated?.opponentUsername}'")
} else {
android.util.Log.w("MessageRepo", "⚠️ Dialog not found for ${publicKey.take(16)}...")
}
}
@@ -769,14 +749,11 @@ class MessageRepository private constructor(private val context: Context) {
encryptedKey: String,
privateKey: String
) {
Log.d("MessageRepository", "📸 processAvatarAttachments: ${attachments.size} attachments from ${fromPublicKey.take(16)}")
for (attachment in attachments) {
Log.d("MessageRepository", "📸 Attachment type=${attachment.type} (AVATAR=${AttachmentType.AVATAR}), blob size=${attachment.blob.length}")
if (attachment.type == AttachmentType.AVATAR && attachment.blob.isNotEmpty()) {
try {
Log.d("MessageRepository", "📸 Found AVATAR attachment! Decrypting...")
// 1. Расшифровываем blob с ChaCha ключом сообщения
val decryptedBlob = MessageCrypto.decryptAttachmentBlob(
@@ -785,12 +762,10 @@ class MessageRepository private constructor(private val context: Context) {
privateKey
)
Log.d("MessageRepository", "📸 Decrypted blob: ${decryptedBlob?.take(50) ?: "NULL"}")
if (decryptedBlob != null) {
// 2. Сохраняем аватар в кэш
val filePath = AvatarFileManager.saveAvatar(context, decryptedBlob, fromPublicKey)
Log.d("MessageRepository", "📸 Avatar saved to: $filePath")
val entity = AvatarCacheEntity(
publicKey = fromPublicKey,
@@ -798,17 +773,13 @@ class MessageRepository private constructor(private val context: Context) {
timestamp = System.currentTimeMillis()
)
avatarDao.insertAvatar(entity)
Log.d("MessageRepository", "📸 Avatar inserted to DB for ${fromPublicKey.take(16)}")
// 3. Очищаем старые аватары (оставляем последние 5)
avatarDao.deleteOldAvatars(fromPublicKey, 5)
Log.d("MessageRepository", "📸 ✅ Successfully saved avatar for $fromPublicKey")
} else {
Log.w("MessageRepository", "📸 ⚠️ Decryption returned null!")
}
} catch (e: Exception) {
Log.e("MessageRepository", "📸 ❌ Failed to process avatar attachment", e)
}
}
}
@@ -830,7 +801,6 @@ class MessageRepository private constructor(private val context: Context) {
// Сохраняем только IMAGE, не FILE (файлы загружаются с CDN при необходимости)
if (attachment.type == AttachmentType.IMAGE && attachment.blob.isNotEmpty()) {
try {
Log.d("MessageRepository", "🖼️ Processing IMAGE attachment: ${attachment.id}")
// 1. Расшифровываем blob с ChaCha ключом сообщения
val decryptedBlob = MessageCrypto.decryptAttachmentBlob(
@@ -850,15 +820,11 @@ class MessageRepository private constructor(private val context: Context) {
)
if (saved) {
Log.d("MessageRepository", "🖼️ ✅ Image saved to file: ${attachment.id}")
} else {
Log.w("MessageRepository", "🖼️ ⚠️ Failed to save image to file")
}
} else {
Log.w("MessageRepository", "🖼️ ⚠️ Decryption returned null for image")
}
} catch (e: Exception) {
Log.e("MessageRepository", "🖼️ ❌ Failed to process image attachment", e)
}
}
}