mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-09 08:38:43 +01:00
Execute use case from a better place.
This commit is contained in:
parent
22cce30e35
commit
7a667b513e
@ -32,11 +32,13 @@ import im.vector.app.core.platform.EmptyViewEvents
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.core.platform.VectorViewModelAction
|
||||
import im.vector.app.core.time.Clock
|
||||
import im.vector.app.features.settings.devices.v2.DeleteUnusedClientInformationUseCase
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
@ -66,6 +68,7 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(
|
||||
private val setUnverifiedSessionsAlertShownUseCase: SetUnverifiedSessionsAlertShownUseCase,
|
||||
private val isNewLoginAlertShownUseCase: IsNewLoginAlertShownUseCase,
|
||||
private val setNewLoginAlertShownUseCase: SetNewLoginAlertShownUseCase,
|
||||
private val deleteUnusedClientInformationUseCase: DeleteUnusedClientInformationUseCase,
|
||||
) : VectorViewModel<UnknownDevicesState, UnknownDeviceDetectorSharedViewModel.Action, EmptyViewEvents>(initialState) {
|
||||
|
||||
sealed class Action : VectorViewModelAction {
|
||||
@ -102,6 +105,9 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(
|
||||
) { cryptoList, infoList, pInfo ->
|
||||
// Timber.v("## Detector trigger ${cryptoList.map { "${it.deviceId} ${it.trustLevel}" }}")
|
||||
// Timber.v("## Detector trigger canCrossSign ${pInfo.get().selfSigned != null}")
|
||||
|
||||
deleteUnusedClientInformation(infoList)
|
||||
|
||||
infoList
|
||||
.filter { info ->
|
||||
// filter verified session, by checking the crypto device info
|
||||
@ -143,6 +149,12 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(
|
||||
session.cryptoService().fetchDevicesList(NoOpMatrixCallback())
|
||||
}
|
||||
|
||||
private fun deleteUnusedClientInformation(deviceFullInfoList: List<DeviceInfo>) {
|
||||
viewModelScope.launch {
|
||||
deleteUnusedClientInformationUseCase.execute(deviceFullInfoList)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(action: Action) {
|
||||
when (action) {
|
||||
is Action.IgnoreDevice -> {
|
||||
|
@ -18,14 +18,15 @@ package im.vector.app.features.settings.devices.v2
|
||||
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.session.clientinfo.MATRIX_CLIENT_INFO_KEY_PREFIX
|
||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteUnusedClientInformationUseCase @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
) {
|
||||
|
||||
suspend fun execute(deviceFullInfoList: List<DeviceFullInfo>) {
|
||||
val expectedClientInfoKeyList = deviceFullInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceInfo.deviceId }
|
||||
suspend fun execute(deviceInfoList: List<DeviceInfo>) {
|
||||
val expectedClientInfoKeyList = deviceInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceId }
|
||||
activeSessionHolder
|
||||
.getSafeActiveSession()
|
||||
?.accountDataService()
|
||||
|
@ -51,7 +51,6 @@ class DevicesViewModel @AssistedInject constructor(
|
||||
refreshDevicesUseCase: RefreshDevicesUseCase,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase,
|
||||
private val deleteUnusedClientInformationUseCase: DeleteUnusedClientInformationUseCase,
|
||||
) : VectorSessionsListViewModel<DevicesViewState,
|
||||
DevicesAction,
|
||||
DevicesViewEvent>(initialState, activeSessionHolder, refreshDevicesUseCase),
|
||||
@ -114,8 +113,6 @@ class DevicesViewModel @AssistedInject constructor(
|
||||
val unverifiedSessionsCount = deviceFullInfoList.count { !it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse() }
|
||||
val inactiveSessionsCount = deviceFullInfoList.count { it.isInactive }
|
||||
|
||||
deleteUnusedClientInformation(deviceFullInfoList)
|
||||
|
||||
copy(
|
||||
devices = async,
|
||||
unverifiedSessionsCount = unverifiedSessionsCount,
|
||||
@ -129,12 +126,6 @@ class DevicesViewModel @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteUnusedClientInformation(deviceFullInfoList: List<DeviceFullInfo>) {
|
||||
viewModelScope.launch {
|
||||
deleteUnusedClientInformationUseCase.execute(deviceFullInfoList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshDevicesOnCryptoDevicesChange() {
|
||||
viewModelScope.launch {
|
||||
refreshDevicesOnCryptoDevicesChangeUseCase.execute()
|
||||
|
Loading…
x
Reference in New Issue
Block a user