From 5cd78c02aacb697f2cfe19fead1b29a4e22d9f95 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 19 Mar 2024 18:23:50 +0100 Subject: [PATCH] Ensure the keys are updated as soon as possible. Else it seems that we had to wait for the next sync response. --- .../crosssigning/CrossSigningSettingsViewModel.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt index 51c7928e1f..3ea66b5dfe 100644 --- a/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/crosssigning/CrossSigningSettingsViewModel.kt @@ -27,6 +27,7 @@ import im.vector.app.core.resources.StringProvider import im.vector.app.features.auth.PendingAuthHandler import im.vector.app.features.login.ReAuthHelper import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -52,6 +53,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor( private val pendingAuthHandler: PendingAuthHandler, ) : VectorViewModel(initialState) { + private var observeCrossSigningJob: Job? = null + init { observeCrossSigning() } @@ -90,6 +93,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor( } } }) + // Force a fast refresh of the data + observeCrossSigning() } catch (failure: Throwable) { handleInitializeXSigningError(failure) } finally { @@ -114,7 +119,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor( // ) { myDevicesInfo, mxCrossSigningInfo -> // myDevicesInfo to mxCrossSigningInfo // } - session.flow().liveCrossSigningInfo(session.myUserId) + observeCrossSigningJob?.cancel() + observeCrossSigningJob = session.flow().liveCrossSigningInfo(session.myUserId) .onEach { data -> val crossSigningKeys = data.getOrNull() val xSigningIsEnableInAccount = crossSigningKeys != null @@ -128,7 +134,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor( xSigningKeyCanSign = xSigningKeyCanSign ) } - }.launchIn(viewModelScope) + } + .launchIn(viewModelScope) } private fun handleInitializeXSigningError(failure: Throwable) {