Ensure the keys are updated as soon as possible. Else it seems that we had to wait for the next sync response.

This commit is contained in:
Benoit Marty 2024-03-19 18:23:50 +01:00 committed by Benoit Marty
parent c0da558c96
commit 5cd78c02aa
1 changed files with 9 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.features.auth.PendingAuthHandler import im.vector.app.features.auth.PendingAuthHandler
import im.vector.app.features.login.ReAuthHelper import im.vector.app.features.login.ReAuthHelper
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -52,6 +53,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(
private val pendingAuthHandler: PendingAuthHandler, private val pendingAuthHandler: PendingAuthHandler,
) : VectorViewModel<CrossSigningSettingsViewState, CrossSigningSettingsAction, CrossSigningSettingsViewEvents>(initialState) { ) : VectorViewModel<CrossSigningSettingsViewState, CrossSigningSettingsAction, CrossSigningSettingsViewEvents>(initialState) {
private var observeCrossSigningJob: Job? = null
init { init {
observeCrossSigning() observeCrossSigning()
} }
@ -90,6 +93,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(
} }
} }
}) })
// Force a fast refresh of the data
observeCrossSigning()
} catch (failure: Throwable) { } catch (failure: Throwable) {
handleInitializeXSigningError(failure) handleInitializeXSigningError(failure)
} finally { } finally {
@ -114,7 +119,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(
// ) { myDevicesInfo, mxCrossSigningInfo -> // ) { myDevicesInfo, mxCrossSigningInfo ->
// myDevicesInfo to mxCrossSigningInfo // myDevicesInfo to mxCrossSigningInfo
// } // }
session.flow().liveCrossSigningInfo(session.myUserId) observeCrossSigningJob?.cancel()
observeCrossSigningJob = session.flow().liveCrossSigningInfo(session.myUserId)
.onEach { data -> .onEach { data ->
val crossSigningKeys = data.getOrNull() val crossSigningKeys = data.getOrNull()
val xSigningIsEnableInAccount = crossSigningKeys != null val xSigningIsEnableInAccount = crossSigningKeys != null
@ -128,7 +134,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(
xSigningKeyCanSign = xSigningKeyCanSign xSigningKeyCanSign = xSigningKeyCanSign
) )
} }
}.launchIn(viewModelScope) }
.launchIn(viewModelScope)
} }
private fun handleInitializeXSigningError(failure: Throwable) { private fun handleInitializeXSigningError(failure: Throwable) {