Create use case to detect and delete unnecessary account data of client information.
This commit is contained in:
parent
8206b534f9
commit
22cce30e35
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 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 }
|
||||||
|
activeSessionHolder
|
||||||
|
.getSafeActiveSession()
|
||||||
|
?.accountDataService()
|
||||||
|
?.getUserAccountDataEventsStartWith(MATRIX_CLIENT_INFO_KEY_PREFIX)
|
||||||
|
?.map { it.type }
|
||||||
|
?.subtract(expectedClientInfoKeyList.toSet())
|
||||||
|
?.forEach { userAccountDataKeyToDelete ->
|
||||||
|
activeSessionHolder.getSafeActiveSession()?.accountDataService()?.deleteUserAccountData(userAccountDataKeyToDelete)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
refreshDevicesUseCase: RefreshDevicesUseCase,
|
refreshDevicesUseCase: RefreshDevicesUseCase,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase,
|
private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase,
|
||||||
|
private val deleteUnusedClientInformationUseCase: DeleteUnusedClientInformationUseCase,
|
||||||
) : VectorSessionsListViewModel<DevicesViewState,
|
) : VectorSessionsListViewModel<DevicesViewState,
|
||||||
DevicesAction,
|
DevicesAction,
|
||||||
DevicesViewEvent>(initialState, activeSessionHolder, refreshDevicesUseCase),
|
DevicesViewEvent>(initialState, activeSessionHolder, refreshDevicesUseCase),
|
||||||
|
@ -112,6 +113,9 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
val deviceFullInfoList = async.invoke()
|
val deviceFullInfoList = async.invoke()
|
||||||
val unverifiedSessionsCount = deviceFullInfoList.count { !it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse() }
|
val unverifiedSessionsCount = deviceFullInfoList.count { !it.cryptoDeviceInfo?.trustLevel?.isCrossSigningVerified().orFalse() }
|
||||||
val inactiveSessionsCount = deviceFullInfoList.count { it.isInactive }
|
val inactiveSessionsCount = deviceFullInfoList.count { it.isInactive }
|
||||||
|
|
||||||
|
deleteUnusedClientInformation(deviceFullInfoList)
|
||||||
|
|
||||||
copy(
|
copy(
|
||||||
devices = async,
|
devices = async,
|
||||||
unverifiedSessionsCount = unverifiedSessionsCount,
|
unverifiedSessionsCount = unverifiedSessionsCount,
|
||||||
|
@ -125,6 +129,12 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun deleteUnusedClientInformation(deviceFullInfoList: List<DeviceFullInfo>) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
deleteUnusedClientInformationUseCase.execute(deviceFullInfoList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun refreshDevicesOnCryptoDevicesChange() {
|
private fun refreshDevicesOnCryptoDevicesChange() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
refreshDevicesOnCryptoDevicesChangeUseCase.execute()
|
refreshDevicesOnCryptoDevicesChangeUseCase.execute()
|
||||||
|
|
Loading…
Reference in New Issue