feat: enhance avatar handling and file attachment functionality with improved UI interactions

This commit is contained in:
2026-02-15 11:54:09 +05:00
parent e301478d92
commit b543ef4d6f
11 changed files with 177 additions and 101 deletions

View File

@@ -313,17 +313,29 @@ class Protocol(
log(" Public key: ${publicKey.take(20)}...")
log(" Private hash: ${privateHash.take(20)}...")
log(" Current state: ${_state.value}")
// Detect account switch: already authenticated but with different credentials
val switchingAccount = (_state.value == ProtocolState.AUTHENTICATED || _state.value == ProtocolState.HANDSHAKING) &&
lastPublicKey != null && lastPublicKey != publicKey
// Save credentials for reconnection
lastPublicKey = publicKey
lastPrivateHash = privateHash
// If switching accounts, force disconnect and reconnect with new credentials
if (switchingAccount) {
log("🔄 Account switch detected, forcing reconnect with new credentials")
disconnect()
connect() // Will auto-handshake with saved credentials (publicKey, privateHash) on connect
return
}
// КРИТИЧНО: если уже в handshake или authenticated, не начинаем заново
if (_state.value == ProtocolState.HANDSHAKING) {
log("⚠️ HANDSHAKE IGNORED: Already handshaking")
return
}
if (_state.value == ProtocolState.AUTHENTICATED) {
log("⚠️ HANDSHAKE IGNORED: Already authenticated")
return

View File

@@ -35,6 +35,10 @@ object ProtocolManager {
// Typing status
private val _typingUsers = MutableStateFlow<Set<String>>(emptySet())
val typingUsers: StateFlow<Set<String>> = _typingUsers.asStateFlow()
// Сигнал обновления own profile (username/name загружены с сервера)
private val _ownProfileUpdated = MutableStateFlow(0L)
val ownProfileUpdated: StateFlow<Long> = _ownProfileUpdated.asStateFlow()
// 🔍 Global user info cache (like Desktop's InformationProvider.cachedUsers)
// publicKey → SearchUser (resolved via PacketSearch 0x03)
@@ -200,6 +204,7 @@ object ProtocolManager {
if (user.username.isNotBlank()) {
accountManager.updateAccountUsername(user.publicKey, user.username)
}
_ownProfileUpdated.value = System.currentTimeMillis()
}
}
}