Fix test crash

This commit is contained in:
valere 2022-12-13 09:48:15 +01:00
parent c52be1f5b1
commit 9680b044f9
2 changed files with 31 additions and 32 deletions

View file

@ -152,7 +152,7 @@ class Rendezvous(
try {
// explicitly download keys for ourself rather than racing with initial sync which might not complete in time
awaitCallback<MXUsersDevicesMap<CryptoDeviceInfo>> { crypto.downloadKeys(listOf(userId), false, it) }
crypto.downloadKeysIfNeeded(listOf(userId), false)
} catch (e: Throwable) {
// log as warning and continue as initial sync might still complete
Timber.tag(TAG).w(e, "Failed to download keys for self")

View file

@ -146,38 +146,37 @@ internal class RealmCryptoStore @Inject constructor(
.setWriteAsyncExecutor(monarchyWriteAsyncExecutor)
.build()
// init {
// // Ensure CryptoMetadataEntity is inserted in DB
// doRealmTransaction(realmConfiguration) { realm ->
// var currentMetadata = realm.where<CryptoMetadataEntity>().findFirst()
//
// var deleteAll = false
//
// if (currentMetadata != null) {
// // Check credentials
// // The device id may not have been provided in credentials.
// // Check it only if provided, else trust the stored one.
// if (currentMetadata.userId != userId ||
// (deviceId != currentMetadata.deviceId)) {
// Timber.w("## open() : Credentials do not match, close this store and delete data")
// deleteAll = true
// currentMetadata = null
// }
// }
//
// if (currentMetadata == null) {
// if (deleteAll) {
// realm.deleteAll()
// }
//
// // Metadata not found, or database cleaned, create it
// realm.createObject(CryptoMetadataEntity::class.java, userId).apply {
// deviceId = this@RealmCryptoStore.deviceId
// }
// }
// }
// }
init {
// Ensure CryptoMetadataEntity is inserted in DB
doRealmTransaction(realmConfiguration) { realm ->
var currentMetadata = realm.where<CryptoMetadataEntity>().findFirst()
var deleteAll = false
if (currentMetadata != null) {
// Check credentials
// The device id may not have been provided in credentials.
// Check it only if provided, else trust the stored one.
if (currentMetadata.userId != userId ||
(deviceId != null && deviceId != currentMetadata.deviceId)) {
Timber.w("## open() : Credentials do not match, close this store and delete data")
deleteAll = true
currentMetadata = null
}
}
if (currentMetadata == null) {
if (deleteAll) {
realm.deleteAll()
}
// Metadata not found, or database cleaned, create it
realm.createObject(CryptoMetadataEntity::class.java, userId).apply {
deviceId = this@RealmCryptoStore.deviceId
}
}
}
}
/* ==========================================================================================
* Other data
* ========================================================================================== */