Change to "produceState"

This commit is contained in:
Benoit Marty
2026-09-23 11:55:03 +02:00
parent c8748f4d77
commit 2669ac4eae
@@ -9,7 +9,6 @@ package io.element.android.features.preferences.impl.account
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf 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.indicator.api.IndicatorService
import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.verification.SessionVerificationService import io.element.android.libraries.matrix.api.verification.SessionVerificationService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@Inject @Inject
class PreferencesAccountPresenter( class PreferencesAccountPresenter(
@@ -62,9 +59,6 @@ class PreferencesAccountPresenter(
val showSecureBackupIndicator by indicatorService.showSettingChatBackupIndicator() val showSecureBackupIndicator by indicatorService.showSettingChatBackupIndicator()
val accountManagementUrl: MutableState<String?> = remember {
mutableStateOf(null)
}
var canDeactivateAccount by remember { var canDeactivateAccount by remember {
mutableStateOf(false) mutableStateOf(false)
} }
@@ -81,15 +75,19 @@ class PreferencesAccountPresenter(
val directLogoutState = directLogoutPresenter.present() val directLogoutState = directLogoutPresenter.present()
LaunchedEffect(Unit) { val accountManagementUrl by produceState<String?>(initialValue = null) {
initAccountManagementUrl(accountManagementUrl) value = matrixClient.getAccountManagementUrl(null)
.getOrNull()
?.let {
sessionEnterpriseService.tweakMasUrl(it)
}
} }
return PreferencesAccountState( return PreferencesAccountState(
myUser = matrixUser.value, myUser = matrixUser.value,
showSecureBackup = !canVerifyUserSession, showSecureBackup = !canVerifyUserSession,
showSecureBackupBadge = showSecureBackupIndicator, showSecureBackupBadge = showSecureBackupIndicator,
accountManagementUrl = accountManagementUrl.value, accountManagementUrl = accountManagementUrl,
canReportBug = canReportBug, canReportBug = canReportBug,
showLinkNewDevice = showLinkNewDevice, showLinkNewDevice = showLinkNewDevice,
canDeactivateAccount = canDeactivateAccount, canDeactivateAccount = canDeactivateAccount,
@@ -98,14 +96,4 @@ class PreferencesAccountPresenter(
snackbarMessage = snackbarMessage, snackbarMessage = snackbarMessage,
) )
} }
private fun CoroutineScope.initAccountManagementUrl(
accountManagementUrl: MutableState<String?>,
) = launch {
accountManagementUrl.value = matrixClient.getAccountManagementUrl(null)
.getOrNull()
?.let {
sessionEnterpriseService.tweakMasUrl(it)
}
}
} }