feat: Remove debug logging from message sending and user blocking/unblocking functions
This commit is contained in:
@@ -41,19 +41,15 @@ class AccountManager(private val context: Context) {
|
||||
// Synchronous read from SharedPreferences - always up to date
|
||||
fun getLastLoggedPublicKey(): String? {
|
||||
val publicKey = sharedPrefs.getString(KEY_LAST_LOGGED, null)
|
||||
android.util.Log.d("AccountManager", "📖 getLastLoggedPublicKey: ${publicKey?.take(16) ?: "null"}")
|
||||
return publicKey
|
||||
}
|
||||
|
||||
// Synchronous write to SharedPreferences
|
||||
fun setLastLoggedPublicKey(publicKey: String) {
|
||||
android.util.Log.d("AccountManager", "💾 Saving last logged account: ${publicKey.take(16)}...")
|
||||
val success = sharedPrefs.edit().putString(KEY_LAST_LOGGED, publicKey).commit() // commit() is synchronous
|
||||
android.util.Log.d("AccountManager", "💾 Save result: $success")
|
||||
|
||||
// Verify immediately
|
||||
val saved = sharedPrefs.getString(KEY_LAST_LOGGED, null)
|
||||
android.util.Log.d("AccountManager", "💾 Verification read: ${saved?.take(16) ?: "null"}")
|
||||
}
|
||||
|
||||
suspend fun saveAccount(account: EncryptedAccount) {
|
||||
@@ -86,7 +82,6 @@ class AccountManager(private val context: Context) {
|
||||
}
|
||||
|
||||
suspend fun setCurrentAccount(publicKey: String) {
|
||||
android.util.Log.d("AccountManager", "🔐 setCurrentAccount called for: ${publicKey.take(16)}...")
|
||||
|
||||
// ⚡ ВАЖНО: Сначала сохраняем в SharedPreferences синхронно
|
||||
setLastLoggedPublicKey(publicKey)
|
||||
@@ -97,7 +92,6 @@ class AccountManager(private val context: Context) {
|
||||
preferences[IS_LOGGED_IN] = true
|
||||
}
|
||||
|
||||
android.util.Log.d("AccountManager", "✅ setCurrentAccount completed for: ${publicKey.take(16)}...")
|
||||
}
|
||||
|
||||
suspend fun logout() {
|
||||
|
||||
@@ -93,14 +93,12 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
* Инициализация с текущим аккаунтом
|
||||
*/
|
||||
fun initialize(publicKey: String, privateKey: String) {
|
||||
android.util.Log.d("MessageRepository", "🔐 initialize() called with publicKey: ${publicKey.take(16)}...")
|
||||
currentAccount = publicKey
|
||||
currentPrivateKey = privateKey
|
||||
|
||||
// Загрузка диалогов
|
||||
scope.launch {
|
||||
dialogDao.getDialogsFlow(publicKey).collect { entities ->
|
||||
android.util.Log.d("MessageRepository", "📋 MessageRepository dialogsFlow emitted: ${entities.size} dialogs")
|
||||
_dialogs.value = entities.map { it.toDialog() }
|
||||
|
||||
// 🔥 Запрашиваем информацию о пользователях, у которых нет имени
|
||||
@@ -238,23 +236,17 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
* Обработка входящего сообщения
|
||||
*/
|
||||
suspend fun handleIncomingMessage(packet: PacketMessage) {
|
||||
android.util.Log.d("MessageRepository", "═══════════════════════════════════════")
|
||||
android.util.Log.d("MessageRepository", "📩 handleIncomingMessage START")
|
||||
android.util.Log.d("MessageRepository", " from: ${packet.fromPublicKey.take(20)}...")
|
||||
|
||||
val account = currentAccount ?: run {
|
||||
android.util.Log.e("MessageRepository", "❌ ABORT: currentAccount is NULL!")
|
||||
return
|
||||
}
|
||||
val privateKey = currentPrivateKey ?: run {
|
||||
android.util.Log.e("MessageRepository", "❌ ABORT: currentPrivateKey is NULL!")
|
||||
return
|
||||
}
|
||||
|
||||
// 🔥 Проверяем, не заблокирован ли отправитель
|
||||
val isBlocked = database.blacklistDao().isUserBlocked(packet.fromPublicKey, account)
|
||||
if (isBlocked) {
|
||||
android.util.Log.d("MessageRepository", "🚫 BLOCKED: Ignoring message from blocked user ${packet.fromPublicKey.take(20)}...")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -264,20 +256,14 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
} else {
|
||||
packet.messageId
|
||||
}
|
||||
android.util.Log.d("MessageRepository", " messageId: $messageId (original: ${packet.messageId})")
|
||||
android.util.Log.d("MessageRepository", " currentAccount: ${account.take(20)}...")
|
||||
android.util.Log.d("MessageRepository", " currentPrivateKey: SET")
|
||||
|
||||
// Проверяем, не дубликат ли (используем сгенерированный messageId)
|
||||
val isDuplicate = messageDao.messageExists(account, messageId)
|
||||
android.util.Log.d("MessageRepository", " isDuplicate: $isDuplicate")
|
||||
if (isDuplicate) {
|
||||
android.util.Log.d("MessageRepository", "⚠️ Skipping duplicate message")
|
||||
return
|
||||
}
|
||||
|
||||
val dialogKey = getDialogKey(packet.fromPublicKey)
|
||||
android.util.Log.d("MessageRepository", " dialogKey: $dialogKey")
|
||||
|
||||
try {
|
||||
// Расшифровываем
|
||||
@@ -314,12 +300,9 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
dialogKey = dialogKey
|
||||
)
|
||||
messageDao.insertMessage(entity)
|
||||
android.util.Log.d("MessageRepository", "✅ Message saved to DB: ${packet.messageId.take(16)}...")
|
||||
|
||||
// Обновляем диалог
|
||||
android.util.Log.d("MessageRepository", "🔄 Calling updateDialog for ${packet.fromPublicKey.take(16)}...")
|
||||
updateDialog(packet.fromPublicKey, plainText, packet.timestamp, incrementUnread = true)
|
||||
android.util.Log.d("MessageRepository", "✅ updateDialog completed!")
|
||||
|
||||
// 🔥 Запрашиваем информацию о пользователе для отображения имени вместо ключа
|
||||
requestUserInfo(packet.fromPublicKey)
|
||||
@@ -329,7 +312,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
updateMessageCache(dialogKey, message)
|
||||
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MessageRepository", "❌ Error handling incoming message", e)
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
@@ -382,7 +364,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
// чтобы unread_count обновился моментально
|
||||
dialogDao.updateDialogFromMessages(account, opponentKey)
|
||||
|
||||
android.util.Log.d("MessageRepository", "✅ Dialog marked as read and updated from messages")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,13 +450,10 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
val account = currentAccount ?: return
|
||||
val privateKey = currentPrivateKey ?: return
|
||||
|
||||
android.util.Log.d("MessageRepository", "📝 Updating dialog for ${opponentKey.take(16)}...")
|
||||
android.util.Log.d("MessageRepository", " lastMessage: ${lastMessage.take(50)}")
|
||||
|
||||
try {
|
||||
// 🔥 КРИТИЧНО: Сначала считаем реальное количество непрочитанных из messages
|
||||
val unreadCount = messageDao.getUnreadCountForDialog(account, opponentKey)
|
||||
android.util.Log.d("MessageRepository", " unreadCount from messages: $unreadCount")
|
||||
|
||||
// 🔒 Шифруем lastMessage
|
||||
val encryptedLastMessage = CryptoManager.encryptWithPassword(lastMessage, privateKey)
|
||||
@@ -485,12 +463,10 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
|
||||
if (existing != null) {
|
||||
// Обновляем существующий диалог
|
||||
android.util.Log.d("MessageRepository", " ✏️ Updating existing dialog...")
|
||||
dialogDao.updateLastMessage(account, opponentKey, encryptedLastMessage, timestamp)
|
||||
dialogDao.updateUnreadCount(account, opponentKey, unreadCount)
|
||||
} else {
|
||||
// Создаем новый диалог
|
||||
android.util.Log.d("MessageRepository", " ➕ Creating new dialog...")
|
||||
dialogDao.insertDialog(DialogEntity(
|
||||
account = account,
|
||||
opponentKey = opponentKey,
|
||||
@@ -500,9 +476,7 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
))
|
||||
}
|
||||
|
||||
android.util.Log.d("MessageRepository", " ✅ Dialog updated successfully!")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MessageRepository", " ❌ Error updating dialog", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,7 +494,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
lastSeen = if (!isOnline) System.currentTimeMillis() else 0
|
||||
)
|
||||
|
||||
android.util.Log.d("MessageRepository", "🟢 Updated online status for ${publicKey.take(16)}... isOnline=$isOnline")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -534,7 +507,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
val existing = dialogDao.getDialog(account, publicKey)
|
||||
if (existing != null) {
|
||||
dialogDao.updateOpponentInfo(account, publicKey, title, username, verified)
|
||||
android.util.Log.d("MessageRepository", "✅ Updated user info for ${publicKey.take(16)}... title=$title")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +523,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
this.search = publicKey
|
||||
}
|
||||
ProtocolManager.send(packet)
|
||||
android.util.Log.d("MessageRepository", "📤 Requested user info for ${publicKey.take(16)}...")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,7 +534,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
try {
|
||||
CryptoManager.decryptWithPassword(plainMessage, privateKey) ?: plainMessage
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MessageRepository", "Failed to decrypt plainMessage: ${e.message}")
|
||||
plainMessage // Fallback на зашифрованный текст если расшифровка не удалась
|
||||
}
|
||||
} else {
|
||||
@@ -649,7 +619,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
jsonObj.put("preview", decryptedBlob) // Для совместимости
|
||||
jsonObj.put("width", attachment.width)
|
||||
jsonObj.put("height", attachment.height)
|
||||
android.util.Log.d("MessageRepository", "✅ Decrypted MESSAGES blob: ${decryptedBlob.take(100)}")
|
||||
} else {
|
||||
// Fallback - сохраняем как есть
|
||||
jsonObj.put("id", attachment.id)
|
||||
@@ -660,7 +629,6 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
jsonObj.put("height", attachment.height)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MessageRepository", "❌ Failed to decrypt MESSAGES blob", e)
|
||||
// Fallback - сохраняем как есть
|
||||
jsonObj.put("id", attachment.id)
|
||||
jsonObj.put("blob", attachment.blob)
|
||||
|
||||
Reference in New Issue
Block a user