Hide unverified sessions section when current session is not verified

This commit is contained in:
Maxime NATUREL 2022-10-13 11:33:32 +02:00
parent 7ce56ced4d
commit f77bceb918
1 changed files with 21 additions and 8 deletions

View File

@ -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.SecurityRecommendationView
import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -164,12 +165,11 @@ class VectorSettingsDevicesFragment :
if (state.devices is Success) { if (state.devices is Success) {
val devices = state.devices() val devices = state.devices()
val currentDeviceId = state.currentSessionCrossSigningInfo.deviceId val currentDeviceId = state.currentSessionCrossSigningInfo.deviceId
val currentDeviceInfo = devices?.firstOrNull { val currentDeviceInfo = devices?.firstOrNull { it.deviceInfo.deviceId == currentDeviceId }
it.deviceInfo.deviceId == currentDeviceId val isCurrentSessionVerified = currentDeviceInfo?.roomEncryptionTrustLevel == RoomEncryptionTrustLevel.Trusted
}
val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId } val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId }
renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount) renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified)
renderCurrentDevice(currentDeviceInfo) renderCurrentDevice(currentDeviceInfo)
renderOtherSessionsView(otherDevices) renderOtherSessionsView(otherDevices)
} else { } else {
@ -181,13 +181,18 @@ class VectorSettingsDevicesFragment :
handleLoadingStatus(state.isLoading) handleLoadingStatus(state.isLoading)
} }
private fun renderSecurityRecommendations(inactiveSessionsCount: Int, unverifiedSessionsCount: Int) { private fun renderSecurityRecommendations(
inactiveSessionsCount: Int,
unverifiedSessionsCount: Int,
isCurrentSessionVerified: Boolean,
) {
if (unverifiedSessionsCount == 0 && inactiveSessionsCount == 0) { if (unverifiedSessionsCount == 0 && inactiveSessionsCount == 0) {
hideSecurityRecommendations() hideSecurityRecommendations()
} else { } else {
views.deviceListHeaderSectionSecurityRecommendations.isVisible = true views.deviceListHeaderSectionSecurityRecommendations.isVisible = true
views.deviceListSecurityRecommendationsDivider.isVisible = true views.deviceListSecurityRecommendationsDivider.isVisible = true
views.deviceListUnverifiedSessionsRecommendation.isVisible = unverifiedSessionsCount > 0
views.deviceListUnverifiedSessionsRecommendation.isVisible = unverifiedSessionsCount > 0 && isCurrentSessionVerified
views.deviceListInactiveSessionsRecommendation.isVisible = inactiveSessionsCount > 0 views.deviceListInactiveSessionsRecommendation.isVisible = inactiveSessionsCount > 0
val unverifiedSessionsViewState = SecurityRecommendationViewState( val unverifiedSessionsViewState = SecurityRecommendationViewState(
description = getString(R.string.device_manager_unverified_sessions_description), 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() { private fun hideSecurityRecommendations() {
views.deviceListHeaderSectionSecurityRecommendations.isVisible = false views.deviceListHeaderSectionSecurityRecommendations.isVisible = false
views.deviceListUnverifiedSessionsRecommendation.isVisible = false
views.deviceListInactiveSessionsRecommendation.isVisible = false
views.deviceListSecurityRecommendationsDivider.isVisible = false views.deviceListSecurityRecommendationsDivider.isVisible = false
hideUnverifiedSessionsRecommendation()
hideInactiveSessionsRecommendation()
} }
private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?) { private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?) {