This commit is contained in:
Alfonso Grillo
2022-12-13 15:35:18 +01:00
parent a423199aa4
commit 4201c0060e
2 changed files with 71 additions and 7 deletions

View File

@@ -76,18 +76,25 @@ class UserSessionsDataProvider: UserSessionsDataProviderProtocol {
}
}
private extension UserSessionsDataProvider {
func deleteAccountDataIfNeeded(deviceList: [MXDevice]) {
extension UserSessionsDataProvider {
// internal just to facilitate tests
func obsoletedDeviceAccountData(deviceList: [MXDevice], accountDataEvents: [String: Any]) -> Set<String> {
let deviceAccountDataKeys = Set(
session
.accountData
.allAccountDataEvents()
accountDataEvents
.map(\.key)
.filter { $0.hasPrefix(kMXAccountDataTypeClientInformation) }
)
let expectedDeviceAccountDataKeys = Set(deviceList.map { "\(kMXAccountDataTypeClientInformation).\($0.deviceId)" })
let obsoletedDeviceAccountDataKeys = deviceAccountDataKeys.subtracting(expectedDeviceAccountDataKeys)
let expectedDeviceAccountDataKeys = Set(deviceList.map {
"\(kMXAccountDataTypeClientInformation).\($0.deviceId)"
})
return deviceAccountDataKeys.subtracting(expectedDeviceAccountDataKeys)
}
private func deleteAccountDataIfNeeded(deviceList: [MXDevice]) {
let obsoletedDeviceAccountDataKeys = obsoletedDeviceAccountData(deviceList: deviceList,
accountDataEvents: session.accountData.allAccountDataEvents())
for accountDataKey in obsoletedDeviceAccountDataKeys {
session.deleteAccountData(withType: accountDataKey, success: {}, failure: { _ in })