feat: Update PacketOnlineSubscribe and PacketTyping to include privateKey and enhance logging
This commit is contained in:
@@ -330,10 +330,10 @@ fun ChatDetailScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Аватар
|
||||
// Аватар - используем publicKey для консистентности цвета везде
|
||||
val avatarColors =
|
||||
getAvatarColor(
|
||||
if (isSavedMessages) "SavedMessages" else user.title.ifEmpty { user.publicKey },
|
||||
if (isSavedMessages) "SavedMessages" else user.publicKey,
|
||||
isDarkTheme
|
||||
)
|
||||
|
||||
|
||||
@@ -151,19 +151,30 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
// Typing
|
||||
ProtocolManager.waitPacket(0x0B) { packet ->
|
||||
val typingPacket = packet as PacketTyping
|
||||
ProtocolManager.addLog("⌨️ TYPING received from: ${typingPacket.fromPublicKey.take(16)}...")
|
||||
ProtocolManager.addLog(" My opponent: ${opponentKey?.take(16)}...")
|
||||
if (typingPacket.fromPublicKey == opponentKey) {
|
||||
ProtocolManager.addLog(" ✅ Match! Showing typing indicator")
|
||||
showTypingIndicator()
|
||||
} else {
|
||||
ProtocolManager.addLog(" ❌ No match, ignoring")
|
||||
}
|
||||
}
|
||||
|
||||
// 🟢 Онлайн статус
|
||||
// 🟢 Онлайн статус (массив publicKey+state как в React Native)
|
||||
ProtocolManager.waitPacket(0x05) { packet ->
|
||||
val onlinePacket = packet as PacketOnlineState
|
||||
if (onlinePacket.publicKey == opponentKey) {
|
||||
viewModelScope.launch {
|
||||
_opponentOnline.value = onlinePacket.online == 1
|
||||
_opponentLastSeen.value = onlinePacket.lastSeen
|
||||
ProtocolManager.addLog("🟢 Online status: ${if (onlinePacket.online == 1) "online" else "offline"}")
|
||||
ProtocolManager.addLog("🟢 ONLINE STATUS received: ${onlinePacket.publicKeysState.size} entries")
|
||||
|
||||
onlinePacket.publicKeysState.forEach { item ->
|
||||
ProtocolManager.addLog(" Key: ${item.publicKey.take(16)}... State: ${item.state}")
|
||||
ProtocolManager.addLog(" My opponent: ${opponentKey?.take(16)}...")
|
||||
|
||||
if (item.publicKey == opponentKey) {
|
||||
ProtocolManager.addLog(" ✅ Match! Updating UI - online: ${item.state == OnlineState.ONLINE}")
|
||||
viewModelScope.launch {
|
||||
_opponentOnline.value = item.state == OnlineState.ONLINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -684,9 +695,18 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastTypingSentTime < TYPING_THROTTLE_MS) return
|
||||
|
||||
val opponent = opponentKey ?: return
|
||||
val sender = myPublicKey ?: return
|
||||
val privateKey = myPrivateKey ?: return
|
||||
val opponent = opponentKey ?: run {
|
||||
ProtocolManager.addLog("❌ Typing: No opponent key")
|
||||
return
|
||||
}
|
||||
val sender = myPublicKey ?: run {
|
||||
ProtocolManager.addLog("❌ Typing: No sender key")
|
||||
return
|
||||
}
|
||||
val privateKey = myPrivateKey ?: run {
|
||||
ProtocolManager.addLog("❌ Typing: No private key")
|
||||
return
|
||||
}
|
||||
|
||||
lastTypingSentTime = now
|
||||
|
||||
@@ -694,16 +714,22 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
try {
|
||||
val privateKeyHash = CryptoManager.generatePrivateKeyHash(privateKey)
|
||||
|
||||
ProtocolManager.addLog("⌨️ Sending typing...")
|
||||
ProtocolManager.addLog(" From: ${sender.take(16)}...")
|
||||
ProtocolManager.addLog(" To: ${opponent.take(16)}...")
|
||||
ProtocolManager.addLog(" PrivateHash: ${privateKeyHash.take(16)}...")
|
||||
|
||||
val packet = PacketTyping().apply {
|
||||
this.privateKey = privateKeyHash
|
||||
fromPublicKey = sender
|
||||
toPublicKey = opponent
|
||||
this.privateKey = privateKeyHash
|
||||
}
|
||||
|
||||
ProtocolManager.send(packet)
|
||||
ProtocolManager.addLog("⌨️ Typing indicator sent")
|
||||
ProtocolManager.addLog("⌨️ Typing indicator sent ✅")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Typing send error", e)
|
||||
ProtocolManager.addLog("❌ Typing send error: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -762,17 +788,22 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
||||
*/
|
||||
fun subscribeToOnlineStatus() {
|
||||
val opponent = opponentKey ?: return
|
||||
val privateKey = myPrivateKey ?: return
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val privateKeyHash = CryptoManager.generatePrivateKeyHash(privateKey)
|
||||
|
||||
val packet = PacketOnlineSubscribe().apply {
|
||||
publicKey = opponent
|
||||
this.privateKey = privateKeyHash
|
||||
addPublicKey(opponent)
|
||||
}
|
||||
|
||||
ProtocolManager.send(packet)
|
||||
ProtocolManager.addLog("🟢 Subscribed to online status: ${opponent.take(16)}...")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Online subscribe error", e)
|
||||
ProtocolManager.addLog("❌ Online subscribe error: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,10 +172,9 @@ fun ChatsListScreen(
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val secondaryTextColor = if (isDarkTheme) Color(0xFF8E8E8E) else Color(0xFF8E8E93)
|
||||
|
||||
// Protocol connection state - commented out due to compilation errors
|
||||
// val protocolState by ProtocolManager.state.collectAsState()
|
||||
// val debugLogs by ProtocolManager.debugLogs.collectAsState()
|
||||
val protocolState = ProtocolState.AUTHENTICATED // Temporary fix
|
||||
// Protocol connection state
|
||||
val protocolState by ProtocolManager.state.collectAsState()
|
||||
val debugLogs by ProtocolManager.debugLogs.collectAsState()
|
||||
|
||||
// Dialogs from database
|
||||
val dialogsList by chatsViewModel.dialogs.collectAsState()
|
||||
@@ -279,11 +278,18 @@ fun ChatsListScreen(
|
||||
|
||||
Divider(color = if (isDarkTheme) Color(0xFF3A3A3A) else Color(0xFFE8E8E8))
|
||||
|
||||
// Menu Items
|
||||
// Menu Items - прозрачный фон без странных цветов
|
||||
val drawerItemColors = NavigationDrawerItemDefaults.colors(
|
||||
unselectedContainerColor = Color.Transparent,
|
||||
unselectedIconColor = if (isDarkTheme) Color.White else Color.Black,
|
||||
unselectedTextColor = textColor
|
||||
)
|
||||
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(Icons.Outlined.Person, contentDescription = null) },
|
||||
label = { Text("My Profile") },
|
||||
selected = false,
|
||||
colors = drawerItemColors,
|
||||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
onProfileClick()
|
||||
@@ -294,6 +300,7 @@ fun ChatsListScreen(
|
||||
icon = { Icon(Icons.Outlined.Settings, contentDescription = null) },
|
||||
label = { Text("Settings") },
|
||||
selected = false,
|
||||
colors = drawerItemColors,
|
||||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
onSettingsClick()
|
||||
@@ -310,6 +317,7 @@ fun ChatsListScreen(
|
||||
},
|
||||
label = { Text(if (isDarkTheme) "Light Mode" else "Dark Mode") },
|
||||
selected = false,
|
||||
colors = drawerItemColors,
|
||||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
onToggleTheme()
|
||||
@@ -331,6 +339,9 @@ fun ChatsListScreen(
|
||||
},
|
||||
label = { Text("Log Out", color = Color(0xFFFF3B30)) },
|
||||
selected = false,
|
||||
colors = NavigationDrawerItemDefaults.colors(
|
||||
unselectedContainerColor = Color.Transparent
|
||||
),
|
||||
onClick = {
|
||||
scope.launch {
|
||||
drawerState.close()
|
||||
|
||||
@@ -111,10 +111,10 @@ private fun SearchResultItem(
|
||||
val secondaryTextColor = if (isDarkTheme) Color(0xFF8E8E93) else Color(0xFF666666)
|
||||
val dividerColor = if (isDarkTheme) Color(0xFF3A3A3A) else Color(0xFFE8E8E8)
|
||||
|
||||
// Получаем цвета аватара
|
||||
// Получаем цвета аватара - используем publicKey для консистентности
|
||||
val avatarColors =
|
||||
getAvatarColor(
|
||||
if (isOwnAccount) "SavedMessages" else (user.title.ifEmpty { user.publicKey }),
|
||||
if (isOwnAccount) "SavedMessages" else user.publicKey,
|
||||
isDarkTheme
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user