feat: Disable logging in Protocol and ProtocolManager for improved performance and cleaner UI
This commit is contained in:
@@ -34,7 +34,7 @@ class Protocol(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun log(message: String) {
|
private fun log(message: String) {
|
||||||
logger(message)
|
// Logging disabled for UI connection status
|
||||||
}
|
}
|
||||||
|
|
||||||
private val client = OkHttpClient.Builder()
|
private val client = OkHttpClient.Builder()
|
||||||
|
|||||||
@@ -59,11 +59,9 @@ object ProtocolManager {
|
|||||||
* Инициализация с контекстом для доступа к MessageRepository
|
* Инициализация с контекстом для доступа к MessageRepository
|
||||||
*/
|
*/
|
||||||
fun initialize(context: Context) {
|
fun initialize(context: Context) {
|
||||||
addLog("🚀 ProtocolManager.initialize() called")
|
|
||||||
messageRepository = MessageRepository.getInstance(context)
|
messageRepository = MessageRepository.getInstance(context)
|
||||||
setupPacketHandlers()
|
setupPacketHandlers()
|
||||||
setupStateMonitoring()
|
setupStateMonitoring()
|
||||||
addLog("🚀 ProtocolManager.initialize() completed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +70,7 @@ object ProtocolManager {
|
|||||||
private fun setupStateMonitoring() {
|
private fun setupStateMonitoring() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
getProtocol().state.collect { newState ->
|
getProtocol().state.collect { newState ->
|
||||||
addLog("📡 STATE CHANGED: $newState")
|
// State monitoring without logging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +80,6 @@ object ProtocolManager {
|
|||||||
* Должен вызываться после авторизации пользователя
|
* Должен вызываться после авторизации пользователя
|
||||||
*/
|
*/
|
||||||
fun initializeAccount(publicKey: String, privateKey: String) {
|
fun initializeAccount(publicKey: String, privateKey: String) {
|
||||||
addLog("🔐 Initializing account for message handling: ${publicKey.take(16)}...")
|
|
||||||
messageRepository?.initialize(publicKey, privateKey)
|
messageRepository?.initialize(publicKey, privateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,15 +87,9 @@ object ProtocolManager {
|
|||||||
* Настройка обработчиков пакетов
|
* Настройка обработчиков пакетов
|
||||||
*/
|
*/
|
||||||
private fun setupPacketHandlers() {
|
private fun setupPacketHandlers() {
|
||||||
addLog("📦 setupPacketHandlers() - Registering packet handlers...")
|
|
||||||
|
|
||||||
// Обработчик входящих сообщений (0x06)
|
// Обработчик входящих сообщений (0x06)
|
||||||
waitPacket(0x06) { packet ->
|
waitPacket(0x06) { packet ->
|
||||||
addLog("📦 ⚡⚡⚡ PACKET 0x06 RECEIVED IN PROTOCOL_MANAGER!!! ⚡⚡⚡")
|
|
||||||
val messagePacket = packet as PacketMessage
|
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
|
toPublicKey = messagePacket.fromPublicKey
|
||||||
}
|
}
|
||||||
send(deliveryPacket)
|
send(deliveryPacket)
|
||||||
addLog("✅ Sent delivery confirmation for message ${messagePacket.messageId.take(16)}...")
|
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
messageRepository?.handleIncomingMessage(messagePacket)
|
messageRepository?.handleIncomingMessage(messagePacket)
|
||||||
addLog("✅ handleIncomingMessage completed!")
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
addLog("❌ handleIncomingMessage ERROR: ${e.message}")
|
// Silent error handling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,7 +111,6 @@ object ProtocolManager {
|
|||||||
// Обработчик доставки (0x08)
|
// Обработчик доставки (0x08)
|
||||||
waitPacket(0x08) { packet ->
|
waitPacket(0x08) { packet ->
|
||||||
val deliveryPacket = packet as PacketDelivery
|
val deliveryPacket = packet as PacketDelivery
|
||||||
addLog("✓ Delivered: ${deliveryPacket.messageId.take(16)}...")
|
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
messageRepository?.handleDelivery(deliveryPacket)
|
messageRepository?.handleDelivery(deliveryPacket)
|
||||||
@@ -133,7 +121,6 @@ object ProtocolManager {
|
|||||||
// В Desktop PacketRead не содержит messageId - сообщает что собеседник прочитал сообщения
|
// В Desktop PacketRead не содержит messageId - сообщает что собеседник прочитал сообщения
|
||||||
waitPacket(0x07) { packet ->
|
waitPacket(0x07) { packet ->
|
||||||
val readPacket = packet as PacketRead
|
val readPacket = packet as PacketRead
|
||||||
addLog("✓✓ Read from: ${readPacket.fromPublicKey.take(16)}...")
|
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
messageRepository?.handleRead(readPacket)
|
messageRepository?.handleRead(readPacket)
|
||||||
@@ -143,19 +130,12 @@ object ProtocolManager {
|
|||||||
// 🟢 Обработчик онлайн-статуса (0x05)
|
// 🟢 Обработчик онлайн-статуса (0x05)
|
||||||
waitPacket(0x05) { packet ->
|
waitPacket(0x05) { packet ->
|
||||||
val onlinePacket = packet as PacketOnlineState
|
val onlinePacket = packet as PacketOnlineState
|
||||||
addLog("🟢 Online status received: ${onlinePacket.publicKeysState.size} entries")
|
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (messageRepository == null) {
|
if (messageRepository != null) {
|
||||||
addLog("❌ ERROR: messageRepository is NULL!")
|
|
||||||
} else {
|
|
||||||
addLog("✅ messageRepository is initialized")
|
|
||||||
onlinePacket.publicKeysState.forEach { item ->
|
onlinePacket.publicKeysState.forEach { item ->
|
||||||
val isOnline = item.state == OnlineState.ONLINE
|
val isOnline = item.state == OnlineState.ONLINE
|
||||||
addLog(" ${item.publicKey.take(16)}... -> ${if (isOnline) "ONLINE" else "OFFLINE"}")
|
|
||||||
addLog(" Calling updateOnlineStatus...")
|
|
||||||
messageRepository?.updateOnlineStatus(item.publicKey, isOnline)
|
messageRepository?.updateOnlineStatus(item.publicKey, isOnline)
|
||||||
addLog(" updateOnlineStatus called")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +144,6 @@ object ProtocolManager {
|
|||||||
// Обработчик typing (0x0B)
|
// Обработчик typing (0x0B)
|
||||||
waitPacket(0x0B) { packet ->
|
waitPacket(0x0B) { packet ->
|
||||||
val typingPacket = packet as PacketTyping
|
val typingPacket = packet as PacketTyping
|
||||||
addLog("⌨️ Typing: ${typingPacket.fromPublicKey.take(16)}...")
|
|
||||||
|
|
||||||
// Добавляем в set и удаляем через 3 секунды
|
// Добавляем в set и удаляем через 3 секунды
|
||||||
_typingUsers.value = _typingUsers.value + typingPacket.fromPublicKey
|
_typingUsers.value = _typingUsers.value + typingPacket.fromPublicKey
|
||||||
@@ -178,14 +157,12 @@ object ProtocolManager {
|
|||||||
// Обновляет информацию о пользователе в диалогах когда приходит ответ от сервера
|
// Обновляет информацию о пользователе в диалогах когда приходит ответ от сервера
|
||||||
waitPacket(0x03) { packet ->
|
waitPacket(0x03) { packet ->
|
||||||
val searchPacket = packet as PacketSearch
|
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")
|
android.util.Log.d("Protocol", "🔍 Search/UserInfo response: ${searchPacket.users.size} users")
|
||||||
|
|
||||||
// Обновляем информацию о пользователях в диалогах
|
// Обновляем информацию о пользователях в диалогах
|
||||||
if (searchPacket.users.isNotEmpty()) {
|
if (searchPacket.users.isNotEmpty()) {
|
||||||
scope.launch(Dispatchers.IO) { // 🔥 Запускаем на IO потоке для работы с БД
|
scope.launch(Dispatchers.IO) { // 🔥 Запускаем на IO потоке для работы с БД
|
||||||
searchPacket.users.forEach { user ->
|
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}'")
|
android.util.Log.d("Protocol", "📝 Updating user info: ${user.publicKey.take(16)}... title='${user.title}' username='${user.username}'")
|
||||||
messageRepository?.updateDialogUserInfo(
|
messageRepository?.updateDialogUserInfo(
|
||||||
user.publicKey,
|
user.publicKey,
|
||||||
@@ -204,7 +181,6 @@ object ProtocolManager {
|
|||||||
*/
|
*/
|
||||||
fun getProtocol(): Protocol {
|
fun getProtocol(): Protocol {
|
||||||
if (protocol == null) {
|
if (protocol == null) {
|
||||||
addLog("🔌 Creating new Protocol instance for $SERVER_ADDRESS")
|
|
||||||
protocol = Protocol(SERVER_ADDRESS) { msg -> addLog(msg) }
|
protocol = Protocol(SERVER_ADDRESS) { msg -> addLog(msg) }
|
||||||
}
|
}
|
||||||
return protocol!!
|
return protocol!!
|
||||||
@@ -226,7 +202,6 @@ object ProtocolManager {
|
|||||||
* Connect to server
|
* Connect to server
|
||||||
*/
|
*/
|
||||||
fun connect() {
|
fun connect() {
|
||||||
addLog("🔌 CONNECT REQUESTED - calling Protocol.connect()")
|
|
||||||
getProtocol().connect()
|
getProtocol().connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +209,6 @@ object ProtocolManager {
|
|||||||
* Authenticate with server
|
* Authenticate with server
|
||||||
*/
|
*/
|
||||||
fun authenticate(publicKey: String, privateHash: String) {
|
fun authenticate(publicKey: String, privateHash: String) {
|
||||||
addLog("🔐 AUTHENTICATE REQUESTED for ${publicKey.take(16)}...")
|
|
||||||
getProtocol().startHandshake(publicKey, privateHash)
|
getProtocol().startHandshake(publicKey, privateHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,27 +255,19 @@ fun ChatsListScreen(
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Enable UI logs when status dialog is shown
|
// Status dialog
|
||||||
LaunchedEffect(showStatusDialog) {
|
|
||||||
ProtocolManager.enableUILogs(showStatusDialog)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Status dialog with logs
|
|
||||||
if (showStatusDialog) {
|
if (showStatusDialog) {
|
||||||
val clipboardManager = androidx.compose.ui.platform.LocalClipboardManager.current
|
|
||||||
val scrollState = rememberScrollState()
|
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { showStatusDialog = false },
|
onDismissRequest = { showStatusDialog = false },
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
"Connection Status & Logs",
|
"Connection Status",
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = textColor
|
color = textColor
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
Column(modifier = Modifier.fillMaxWidth().heightIn(max = 500.dp)) {
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
// Status indicator
|
// Status indicator
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
@@ -313,110 +305,6 @@ fun ChatsListScreen(
|
|||||||
color = textColor
|
color = textColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Divider(
|
|
||||||
color = if (isDarkTheme) Color(0xFF424242) else Color(0xFFE0E0E0),
|
|
||||||
modifier = Modifier.padding(vertical = 8.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Logs header with copy button
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"Debug Logs:",
|
|
||||||
fontSize = 14.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = secondaryTextColor
|
|
||||||
)
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
val logsText = debugLogs.joinToString("\n")
|
|
||||||
clipboardManager.setText(
|
|
||||||
androidx.compose.ui.text.AnnotatedString(logsText)
|
|
||||||
)
|
|
||||||
android.widget.Toast.makeText(
|
|
||||||
context,
|
|
||||||
"Logs copied to clipboard!",
|
|
||||||
android.widget.Toast.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
.show()
|
|
||||||
},
|
|
||||||
enabled = debugLogs.isNotEmpty()
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"Copy All",
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color =
|
|
||||||
if (debugLogs.isNotEmpty()) PrimaryBlue
|
|
||||||
else Color.Gray
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logs content
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.weight(1f, fill = false)
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.background(
|
|
||||||
if (isDarkTheme) Color(0xFF1A1A1A)
|
|
||||||
else Color(0xFFF5F5F5)
|
|
||||||
)
|
|
||||||
.padding(8.dp)
|
|
||||||
) {
|
|
||||||
if (debugLogs.isEmpty()) {
|
|
||||||
Text(
|
|
||||||
"No logs available.\nLogs are disabled by default for performance.\n\nEnable with:\nProtocolManager.enableUILogs(true)",
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = secondaryTextColor,
|
|
||||||
modifier = Modifier.padding(8.dp)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Column(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth().verticalScroll(scrollState)
|
|
||||||
) {
|
|
||||||
debugLogs.forEach { log ->
|
|
||||||
Text(
|
|
||||||
log,
|
|
||||||
fontSize = 11.sp,
|
|
||||||
fontFamily = FontFamily.Monospace,
|
|
||||||
color = textColor,
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.padding(vertical = 2.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable/Disable logs button
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
ProtocolManager.enableUILogs(!debugLogs.isNotEmpty())
|
|
||||||
android.widget.Toast.makeText(
|
|
||||||
context,
|
|
||||||
if (debugLogs.isEmpty()) "Logs enabled"
|
|
||||||
else "Logs disabled",
|
|
||||||
android.widget.Toast.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
.show()
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
if (debugLogs.isEmpty()) "⚠️ Enable Logs" else "Disable Logs",
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color =
|
|
||||||
if (debugLogs.isEmpty()) Color(0xFFFFC107)
|
|
||||||
else Color.Gray
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
|
|||||||
Reference in New Issue
Block a user