Merge pull request #3804 from vector-im/feature/ons/fix_deleting_user_device

Fix error when sending encrypted message if someone in the room logs out
This commit is contained in:
Onuray Sahin 2021-08-06 16:13:02 +03:00 committed by GitHub
commit 60a210194d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

1
changelog.d/3792.bugfix Normal file
View file

@ -0,0 +1 @@
Fix error when sending encrypted message if someone in the room logs out.

View file

@ -286,10 +286,13 @@ internal class RealmCryptoStore @Inject constructor(
val userEntity = UserEntity.getOrCreate(realm, userId)
// First delete the removed devices
val deviceIds = devices.keys
userEntity.devices.iterator().forEach { deviceInfoEntity ->
if (deviceInfoEntity.deviceId !in deviceIds) {
Timber.d("Remove device ${deviceInfoEntity.deviceId} of user $userId")
deviceInfoEntity.deleteOnCascade()
userEntity.devices.toTypedArray().iterator().let {
while (it.hasNext()) {
val deviceInfoEntity = it.next()
if (deviceInfoEntity.deviceId !in deviceIds) {
Timber.d("Remove device ${deviceInfoEntity.deviceId} of user $userId")
deviceInfoEntity.deleteOnCascade()
}
}
}
// Then update existing devices or add new one