Hide blocked users list when there are no blocked users (#2504)

This commit is contained in:
Jorge Martin Espinosa
2024-03-07 17:14:44 +01:00
committed by GitHub
parent 148e7c2241
commit b07ec3e681
5 changed files with 20 additions and 5 deletions

1
changelog.d/2198.bugfix Normal file
View File

@@ -0,0 +1 @@
Hide blocked users list when there are no blocked users.

View File

@@ -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,
)

View File

@@ -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?,
)

View File

@@ -33,6 +33,7 @@ fun aPreferencesRootState() = PreferencesRootState(
showDeveloperSettings = true,
showNotificationSettings = true,
showLockScreenSettings = true,
showBlockedUsersItem = true,
snackbarMessage = SnackbarMessage(CommonStrings.common_verification_complete),
directLogoutState = aDirectLogoutState(),
)

View File

@@ -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())),