Ускорено подключение, исправлен кэш участников групп и обновлена версия до 1.1.5
This commit is contained in:
@@ -2,20 +2,24 @@ package com.rosetta.messenger.ui.auth
|
||||
|
||||
import com.rosetta.messenger.network.ProtocolManager
|
||||
import com.rosetta.messenger.network.ProtocolState
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
internal fun startAuthHandshakeFast(publicKey: String, privateKeyHash: String) {
|
||||
// Desktop parity: start connection+handshake immediately, without artificial waits.
|
||||
ProtocolManager.connect()
|
||||
ProtocolManager.authenticate(publicKey, privateKeyHash)
|
||||
ProtocolManager.reconnectNowIfNeeded("auth_fast_start")
|
||||
}
|
||||
|
||||
internal suspend fun awaitAuthHandshakeState(
|
||||
publicKey: String,
|
||||
privateKeyHash: String,
|
||||
attempts: Int = 2,
|
||||
timeoutMs: Long = 25_000L
|
||||
): ProtocolState? {
|
||||
repeat(attempts) {
|
||||
ProtocolManager.disconnect()
|
||||
delay(200)
|
||||
ProtocolManager.authenticate(publicKey, privateKeyHash)
|
||||
repeat(attempts) { attempt ->
|
||||
startAuthHandshakeFast(publicKey, privateKeyHash)
|
||||
|
||||
val state = withTimeoutOrNull(timeoutMs) {
|
||||
ProtocolManager.state.first {
|
||||
@@ -26,6 +30,7 @@ internal suspend fun awaitAuthHandshakeState(
|
||||
if (state != null) {
|
||||
return state
|
||||
}
|
||||
ProtocolManager.reconnectNowIfNeeded("auth_handshake_retry_${attempt + 1}")
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -527,17 +527,10 @@ fun SetPasswordScreen(
|
||||
keyPair.privateKey
|
||||
)
|
||||
|
||||
val handshakeState =
|
||||
awaitAuthHandshakeState(
|
||||
keyPair.publicKey,
|
||||
privateKeyHash
|
||||
)
|
||||
if (handshakeState == null) {
|
||||
error =
|
||||
"Failed to connect to server. Please try again."
|
||||
isCreating = false
|
||||
return@launch
|
||||
}
|
||||
startAuthHandshakeFast(
|
||||
keyPair.publicKey,
|
||||
privateKeyHash
|
||||
)
|
||||
|
||||
accountManager.setCurrentAccount(keyPair.publicKey)
|
||||
|
||||
|
||||
@@ -116,12 +116,7 @@ val decryptedPrivateKey = CryptoManager.decryptWithPassword(
|
||||
name = selectedAccount.name
|
||||
)
|
||||
|
||||
val handshakeState = awaitAuthHandshakeState(account.publicKey, privateKeyHash)
|
||||
if (handshakeState == null) {
|
||||
onError("Failed to connect to server")
|
||||
onUnlocking(false)
|
||||
return
|
||||
}
|
||||
startAuthHandshakeFast(account.publicKey, privateKeyHash)
|
||||
|
||||
accountManager.setCurrentAccount(account.publicKey)
|
||||
onSuccess(decryptedAccount)
|
||||
|
||||
Reference in New Issue
Block a user