Checking current session status in the filter use case

This commit is contained in:
Maxime NATUREL 2022-10-13 15:01:31 +02:00
parent f77bceb918
commit 28ce915f18
2 changed files with 8 additions and 3 deletions

View File

@ -57,7 +57,7 @@ class GetDeviceFullInfoListUseCase @Inject constructor(
} else { } else {
emptyList() emptyList()
} }
filterDevicesUseCase.execute(deviceFullInfoList, filterType, excludedDeviceIds) filterDevicesUseCase.execute(currentSessionCrossSigningInfo, deviceFullInfoList, filterType, excludedDeviceIds)
} }
deviceFullInfoFlow.distinctUntilChanged() deviceFullInfoFlow.distinctUntilChanged()

View File

@ -17,22 +17,27 @@
package im.vector.app.features.settings.devices.v2.filter package im.vector.app.features.settings.devices.v2.filter
import im.vector.app.features.settings.devices.v2.DeviceFullInfo import im.vector.app.features.settings.devices.v2.DeviceFullInfo
import im.vector.app.features.settings.devices.v2.verification.CurrentSessionCrossSigningInfo
import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orFalse
import javax.inject.Inject import javax.inject.Inject
class FilterDevicesUseCase @Inject constructor() { class FilterDevicesUseCase @Inject constructor() {
fun execute( fun execute(
currentSessionCrossSigningInfo: CurrentSessionCrossSigningInfo,
devices: List<DeviceFullInfo>, devices: List<DeviceFullInfo>,
filterType: DeviceManagerFilterType, filterType: DeviceManagerFilterType,
excludedDeviceIds: List<String> = emptyList(), excludedDeviceIds: List<String> = emptyList(),
): List<DeviceFullInfo> { ): List<DeviceFullInfo> {
val isCurrentSessionVerified = currentSessionCrossSigningInfo.isCrossSigningVerified.orFalse()
return devices return devices
.filter { .filter {
when (filterType) { when (filterType) {
DeviceManagerFilterType.ALL_SESSIONS -> true DeviceManagerFilterType.ALL_SESSIONS -> true
DeviceManagerFilterType.VERIFIED -> it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse() // when current session is not verified, other session status cannot be trusted
DeviceManagerFilterType.UNVERIFIED -> !it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse() DeviceManagerFilterType.VERIFIED -> isCurrentSessionVerified && it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse()
// when current session is not verified, other session status cannot be trusted
DeviceManagerFilterType.UNVERIFIED -> isCurrentSessionVerified && !it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse()
DeviceManagerFilterType.INACTIVE -> it.isInactive DeviceManagerFilterType.INACTIVE -> it.isInactive
} }
} }