From ee532c8b6754f093f04a720f332bec4661137244 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Thu, 7 Mar 2024 17:14:44 +0100 Subject: [PATCH] Hide blocked users list when there are no blocked users (#2504) --- changelog.d/2198.bugfix | 1 + .../impl/root/PreferencesRootPresenter.kt | 10 ++++++++++ .../preferences/impl/root/PreferencesRootState.kt | 1 + .../impl/root/PreferencesRootStateProvider.kt | 1 + .../preferences/impl/root/PreferencesRootView.kt | 12 +++++++----- 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 changelog.d/2198.bugfix diff --git a/changelog.d/2198.bugfix b/changelog.d/2198.bugfix new file mode 100644 index 0000000000..98a139fd12 --- /dev/null +++ b/changelog.d/2198.bugfix @@ -0,0 +1 @@ +Hide blocked users list when there are no blocked users. diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt index 434985e068..18af3a9b6d 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootPresenter.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import io.element.android.features.logout.api.direct.DirectLogoutPresenter @@ -39,6 +40,8 @@ import io.element.android.libraries.matrix.api.user.getCurrentUser import io.element.android.libraries.matrix.api.verification.SessionVerificationService import io.element.android.services.analytics.api.AnalyticsService import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import javax.inject.Inject @@ -86,6 +89,12 @@ class PreferencesRootPresenter @Inject constructor( mutableStateOf(null) } + val showBlockedUsersItem by produceState(initialValue = false) { + matrixClient.ignoredUsersFlow + .onEach { value = it.isNotEmpty() } + .launchIn(this) + } + val directLogoutState = directLogoutPresenter.present() LaunchedEffect(Unit) { @@ -106,6 +115,7 @@ class PreferencesRootPresenter @Inject constructor( showDeveloperSettings = showDeveloperSettings, showNotificationSettings = showNotificationSettings.value, showLockScreenSettings = showLockScreenSettings.value, + showBlockedUsersItem = showBlockedUsersItem, directLogoutState = directLogoutState, snackbarMessage = snackbarMessage, ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootState.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootState.kt index cda7b3e768..7ac73b10a9 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootState.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootState.kt @@ -33,6 +33,7 @@ data class PreferencesRootState( val showDeveloperSettings: Boolean, val showLockScreenSettings: Boolean, val showNotificationSettings: Boolean, + val showBlockedUsersItem: Boolean, val directLogoutState: DirectLogoutState, val snackbarMessage: SnackbarMessage?, ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootStateProvider.kt index 6f5069f947..0f027d775d 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootStateProvider.kt @@ -33,6 +33,7 @@ fun aPreferencesRootState() = PreferencesRootState( showDeveloperSettings = true, showNotificationSettings = true, showLockScreenSettings = true, + showBlockedUsersItem = true, snackbarMessage = SnackbarMessage(CommonStrings.common_verification_complete), directLogoutState = aDirectLogoutState(), ) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt index be247b8b28..835cd6cc15 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/root/PreferencesRootView.kt @@ -122,11 +122,13 @@ fun PreferencesRootView( onClick = onOpenNotificationSettings, ) } - ListItem( - headlineContent = { Text(stringResource(id = CommonStrings.common_blocked_users)) }, - leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())), - onClick = onOpenBlockedUsers, - ) + if (state.showBlockedUsersItem) { + ListItem( + headlineContent = { Text(stringResource(id = CommonStrings.common_blocked_users)) }, + leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())), + onClick = onOpenBlockedUsers, + ) + } ListItem( headlineContent = { Text(stringResource(id = CommonStrings.common_report_a_problem)) }, leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.ChatProblem())),