From 2669ac4eae5a4e99fb0eca07e5e3d8c13815465f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 23 Sep 2026 11:55:03 +0200 Subject: [PATCH] Change to "produceState" --- .../account/PreferencesAccountPresenter.kt | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/account/PreferencesAccountPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/account/PreferencesAccountPresenter.kt index a51e86647c..f5a46dbf50 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/account/PreferencesAccountPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/account/PreferencesAccountPresenter.kt @@ -9,7 +9,6 @@ package io.element.android.features.preferences.impl.account import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.MutableState import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -28,10 +27,8 @@ import io.element.android.libraries.featureflag.api.FeatureFlags import io.element.android.libraries.indicator.api.IndicatorService import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.matrix.api.verification.SessionVerificationService -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.launch @Inject class PreferencesAccountPresenter( @@ -62,9 +59,6 @@ class PreferencesAccountPresenter( val showSecureBackupIndicator by indicatorService.showSettingChatBackupIndicator() - val accountManagementUrl: MutableState = remember { - mutableStateOf(null) - } var canDeactivateAccount by remember { mutableStateOf(false) } @@ -81,15 +75,19 @@ class PreferencesAccountPresenter( val directLogoutState = directLogoutPresenter.present() - LaunchedEffect(Unit) { - initAccountManagementUrl(accountManagementUrl) + val accountManagementUrl by produceState(initialValue = null) { + value = matrixClient.getAccountManagementUrl(null) + .getOrNull() + ?.let { + sessionEnterpriseService.tweakMasUrl(it) + } } return PreferencesAccountState( myUser = matrixUser.value, showSecureBackup = !canVerifyUserSession, showSecureBackupBadge = showSecureBackupIndicator, - accountManagementUrl = accountManagementUrl.value, + accountManagementUrl = accountManagementUrl, canReportBug = canReportBug, showLinkNewDevice = showLinkNewDevice, canDeactivateAccount = canDeactivateAccount, @@ -98,14 +96,4 @@ class PreferencesAccountPresenter( snackbarMessage = snackbarMessage, ) } - - private fun CoroutineScope.initAccountManagementUrl( - accountManagementUrl: MutableState, - ) = launch { - accountManagementUrl.value = matrixClient.getAccountManagementUrl(null) - .getOrNull() - ?.let { - sessionEnterpriseService.tweakMasUrl(it) - } - } }