feat: Disable logging in Protocol and ProtocolManager for improved performance and cleaner UI

This commit is contained in:
k1ngsterr1
2026-01-18 22:57:53 +05:00
parent 89d639a474
commit 6b839d2729
3 changed files with 7 additions and 145 deletions

View File

@@ -34,7 +34,7 @@ class Protocol(
}
private fun log(message: String) {
logger(message)
// Logging disabled for UI connection status
}
private val client = OkHttpClient.Builder()

View File

@@ -59,11 +59,9 @@ object ProtocolManager {
* Инициализация с контекстом для доступа к MessageRepository
*/
fun initialize(context: Context) {
addLog("🚀 ProtocolManager.initialize() called")
messageRepository = MessageRepository.getInstance(context)
setupPacketHandlers()
setupStateMonitoring()
addLog("🚀 ProtocolManager.initialize() completed")
}
/**
@@ -72,7 +70,7 @@ object ProtocolManager {
private fun setupStateMonitoring() {
scope.launch {
getProtocol().state.collect { newState ->
addLog("📡 STATE CHANGED: $newState")
// State monitoring without logging
}
}
}
@@ -82,7 +80,6 @@ object ProtocolManager {
* Должен вызываться после авторизации пользователя
*/
fun initializeAccount(publicKey: String, privateKey: String) {
addLog("🔐 Initializing account for message handling: ${publicKey.take(16)}...")
messageRepository?.initialize(publicKey, privateKey)
}
@@ -90,15 +87,9 @@ 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}")
// ⚡ ВАЖНО: Отправляем подтверждение доставки обратно серверу
// Без этого сервер не будет отправлять следующие сообщения!
@@ -107,14 +98,12 @@ object ProtocolManager {
toPublicKey = messagePacket.fromPublicKey
}
send(deliveryPacket)
addLog("✅ Sent delivery confirmation for message ${messagePacket.messageId.take(16)}...")
scope.launch {
try {
messageRepository?.handleIncomingMessage(messagePacket)
addLog("✅ handleIncomingMessage completed!")
} catch (e: Exception) {
addLog("❌ handleIncomingMessage ERROR: ${e.message}")
// Silent error handling
}
}
}
@@ -122,7 +111,6 @@ object ProtocolManager {
// Обработчик доставки (0x08)
waitPacket(0x08) { packet ->
val deliveryPacket = packet as PacketDelivery
addLog("✓ Delivered: ${deliveryPacket.messageId.take(16)}...")
scope.launch {
messageRepository?.handleDelivery(deliveryPacket)
@@ -133,7 +121,6 @@ object ProtocolManager {
// В Desktop PacketRead не содержит messageId - сообщает что собеседник прочитал сообщения
waitPacket(0x07) { packet ->
val readPacket = packet as PacketRead
addLog("✓✓ Read from: ${readPacket.fromPublicKey.take(16)}...")
scope.launch {
messageRepository?.handleRead(readPacket)
@@ -143,19 +130,12 @@ object ProtocolManager {
// 🟢 Обработчик онлайн-статуса (0x05)
waitPacket(0x05) { packet ->
val onlinePacket = packet as PacketOnlineState
addLog("🟢 Online status received: ${onlinePacket.publicKeysState.size} entries")
scope.launch {
if (messageRepository == null) {
addLog("❌ ERROR: messageRepository is NULL!")
} else {
addLog("✅ messageRepository is initialized")
if (messageRepository != null) {
onlinePacket.publicKeysState.forEach { item ->
val isOnline = item.state == OnlineState.ONLINE
addLog(" ${item.publicKey.take(16)}... -> ${if (isOnline) "ONLINE" else "OFFLINE"}")
addLog(" Calling updateOnlineStatus...")
messageRepository?.updateOnlineStatus(item.publicKey, isOnline)
addLog(" updateOnlineStatus called")
}
}
}
@@ -164,7 +144,6 @@ object ProtocolManager {
// Обработчик typing (0x0B)
waitPacket(0x0B) { packet ->
val typingPacket = packet as PacketTyping
addLog("⌨️ Typing: ${typingPacket.fromPublicKey.take(16)}...")
// Добавляем в set и удаляем через 3 секунды
_typingUsers.value = _typingUsers.value + typingPacket.fromPublicKey
@@ -178,14 +157,12 @@ object ProtocolManager {
// Обновляет информацию о пользователе в диалогах когда приходит ответ от сервера
waitPacket(0x03) { packet ->
val searchPacket = packet as PacketSearch
addLog("🔍 Search/UserInfo response: ${searchPacket.users.size} users")
android.util.Log.d("Protocol", "🔍 Search/UserInfo response: ${searchPacket.users.size} users")
// Обновляем информацию о пользователях в диалогах
if (searchPacket.users.isNotEmpty()) {
scope.launch(Dispatchers.IO) { // 🔥 Запускаем на IO потоке для работы с БД
searchPacket.users.forEach { user ->
addLog(" 📝 Updating user info: ${user.publicKey.take(16)}... title='${user.title}' username='${user.username}'")
android.util.Log.d("Protocol", "📝 Updating user info: ${user.publicKey.take(16)}... title='${user.title}' username='${user.username}'")
messageRepository?.updateDialogUserInfo(
user.publicKey,
@@ -204,7 +181,6 @@ object ProtocolManager {
*/
fun getProtocol(): Protocol {
if (protocol == null) {
addLog("🔌 Creating new Protocol instance for $SERVER_ADDRESS")
protocol = Protocol(SERVER_ADDRESS) { msg -> addLog(msg) }
}
return protocol!!
@@ -226,7 +202,6 @@ object ProtocolManager {
* Connect to server
*/
fun connect() {
addLog("🔌 CONNECT REQUESTED - calling Protocol.connect()")
getProtocol().connect()
}
@@ -234,7 +209,6 @@ object ProtocolManager {
* Authenticate with server
*/
fun authenticate(publicKey: String, privateHash: String) {
addLog("🔐 AUTHENTICATE REQUESTED for ${publicKey.take(16)}...")
getProtocol().startHandshake(publicKey, privateHash)
}