From 885a663380a040abaa1c048b024323857b3a7465 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 6 Aug 2021 15:23:24 +0300 Subject: [PATCH] Fix error when sending encrypted message if someone in the room logs out. --- changelog.d/3792.bugfix | 1 + .../sdk/internal/crypto/store/db/RealmCryptoStore.kt | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelog.d/3792.bugfix diff --git a/changelog.d/3792.bugfix b/changelog.d/3792.bugfix new file mode 100644 index 0000000000..d0f28980b7 --- /dev/null +++ b/changelog.d/3792.bugfix @@ -0,0 +1 @@ +Fix error when sending encrypted message if someone in the room logs out. \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index 80d00c3dde..d997998836 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -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