From f77bceb918a81fd7655022ce08b0607fa4b73b5c Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 13 Oct 2022 11:33:32 +0200 Subject: [PATCH] Hide unverified sessions section when current session is not verified --- .../v2/VectorSettingsDevicesFragment.kt | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 47ea96c09d..3cf3b33942 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -44,6 +44,7 @@ import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INAC import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationView import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState +import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import javax.inject.Inject /** @@ -164,12 +165,11 @@ class VectorSettingsDevicesFragment : if (state.devices is Success) { val devices = state.devices() val currentDeviceId = state.currentSessionCrossSigningInfo.deviceId - val currentDeviceInfo = devices?.firstOrNull { - it.deviceInfo.deviceId == currentDeviceId - } + val currentDeviceInfo = devices?.firstOrNull { it.deviceInfo.deviceId == currentDeviceId } + val isCurrentSessionVerified = currentDeviceInfo?.roomEncryptionTrustLevel == RoomEncryptionTrustLevel.Trusted val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId } - renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount) + renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified) renderCurrentDevice(currentDeviceInfo) renderOtherSessionsView(otherDevices) } else { @@ -181,13 +181,18 @@ class VectorSettingsDevicesFragment : handleLoadingStatus(state.isLoading) } - private fun renderSecurityRecommendations(inactiveSessionsCount: Int, unverifiedSessionsCount: Int) { + private fun renderSecurityRecommendations( + inactiveSessionsCount: Int, + unverifiedSessionsCount: Int, + isCurrentSessionVerified: Boolean, + ) { if (unverifiedSessionsCount == 0 && inactiveSessionsCount == 0) { hideSecurityRecommendations() } else { views.deviceListHeaderSectionSecurityRecommendations.isVisible = true views.deviceListSecurityRecommendationsDivider.isVisible = true - views.deviceListUnverifiedSessionsRecommendation.isVisible = unverifiedSessionsCount > 0 + + views.deviceListUnverifiedSessionsRecommendation.isVisible = unverifiedSessionsCount > 0 && isCurrentSessionVerified views.deviceListInactiveSessionsRecommendation.isVisible = inactiveSessionsCount > 0 val unverifiedSessionsViewState = SecurityRecommendationViewState( description = getString(R.string.device_manager_unverified_sessions_description), @@ -206,11 +211,19 @@ class VectorSettingsDevicesFragment : } } + private fun hideUnverifiedSessionsRecommendation() { + views.deviceListUnverifiedSessionsRecommendation.isVisible = false + } + + private fun hideInactiveSessionsRecommendation() { + views.deviceListInactiveSessionsRecommendation.isVisible = false + } + private fun hideSecurityRecommendations() { views.deviceListHeaderSectionSecurityRecommendations.isVisible = false - views.deviceListUnverifiedSessionsRecommendation.isVisible = false - views.deviceListInactiveSessionsRecommendation.isVisible = false views.deviceListSecurityRecommendationsDivider.isVisible = false + hideUnverifiedSessionsRecommendation() + hideInactiveSessionsRecommendation() } private fun renderOtherSessionsView(otherDevices: List?) {