feat: Enhance logging in MessageRepository and ChatsListViewModel for better debugging and flow tracking
This commit is contained in:
@@ -392,6 +392,8 @@ class Protocol(
|
||||
*/
|
||||
fun waitPacket(packetId: Int, callback: (Packet) -> Unit) {
|
||||
packetWaiters.getOrPut(packetId) { mutableListOf() }.add(callback)
|
||||
val count = packetWaiters[packetId]?.size ?: 0
|
||||
log("📝 waitPacket(0x${Integer.toHexString(packetId)}) registered. Total handlers for 0x${Integer.toHexString(packetId)}: $count")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,8 +62,10 @@ object ProtocolManager {
|
||||
* Инициализация с контекстом для доступа к MessageRepository
|
||||
*/
|
||||
fun initialize(context: Context) {
|
||||
addLog("🚀 ProtocolManager.initialize() called")
|
||||
messageRepository = MessageRepository.getInstance(context)
|
||||
setupPacketHandlers()
|
||||
addLog("🚀 ProtocolManager.initialize() completed")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,10 +81,15 @@ object ProtocolManager {
|
||||
* Настройка обработчиков пакетов
|
||||
*/
|
||||
private fun setupPacketHandlers() {
|
||||
addLog("📦 setupPacketHandlers() - Registering packet handlers...")
|
||||
|
||||
// Обработчик входящих сообщений (0x06)
|
||||
waitPacket(0x06) { packet ->
|
||||
addLog("📦 ⚡⚡⚡ PACKET 0x06 RECEIVED IN PROTOCOL_MANAGER!!! ⚡⚡⚡")
|
||||
val messagePacket = packet as PacketMessage
|
||||
addLog("📩 Incoming message from ${messagePacket.fromPublicKey.take(16)}...")
|
||||
addLog(" messageRepository = ${if (messageRepository != null) "OK" else "NULL"}")
|
||||
addLog(" messageRepository.isInitialized = ${messageRepository?.isInitialized() ?: false}")
|
||||
|
||||
// ⚡ ВАЖНО: Отправляем подтверждение доставки обратно серверу
|
||||
// Без этого сервер не будет отправлять следующие сообщения!
|
||||
@@ -94,7 +101,12 @@ object ProtocolManager {
|
||||
addLog("✅ Sent delivery confirmation for message ${messagePacket.messageId.take(16)}...")
|
||||
|
||||
scope.launch {
|
||||
messageRepository?.handleIncomingMessage(messagePacket)
|
||||
try {
|
||||
messageRepository?.handleIncomingMessage(messagePacket)
|
||||
addLog("✅ handleIncomingMessage completed!")
|
||||
} catch (e: Exception) {
|
||||
addLog("❌ handleIncomingMessage ERROR: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user