Use AwaitTransaction (G's review)
This commit is contained in:
parent
4f3734f932
commit
e7c9fb987c
|
@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoMapper
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.model.TrustLevelEntity
|
import org.matrix.android.sdk.internal.crypto.store.db.model.TrustLevelEntity
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity
|
import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields
|
import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields
|
||||||
|
import org.matrix.android.sdk.internal.database.awaitTransaction
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
||||||
|
@ -69,8 +70,10 @@ internal class UpdateTrustWorker(context: Context,
|
||||||
// It breaks the crypto store contract, but we need to batch things :/
|
// It breaks the crypto store contract, but we need to batch things :/
|
||||||
@CryptoDatabase
|
@CryptoDatabase
|
||||||
@Inject lateinit var cryptoRealmConfiguration: RealmConfiguration
|
@Inject lateinit var cryptoRealmConfiguration: RealmConfiguration
|
||||||
|
|
||||||
@SessionDatabase
|
@SessionDatabase
|
||||||
@Inject lateinit var sessionRealmConfiguration: RealmConfiguration
|
@Inject lateinit var sessionRealmConfiguration: RealmConfiguration
|
||||||
|
|
||||||
@UserId
|
@UserId
|
||||||
@Inject lateinit var myUserId: String
|
@Inject lateinit var myUserId: String
|
||||||
@Inject lateinit var crossSigningKeysMapper: CrossSigningKeysMapper
|
@Inject lateinit var crossSigningKeysMapper: CrossSigningKeysMapper
|
||||||
|
@ -96,8 +99,8 @@ internal class UpdateTrustWorker(context: Context,
|
||||||
Timber.d("## CrossSigning - Updating trust for users: ${userList.logLimit()}")
|
Timber.d("## CrossSigning - Updating trust for users: ${userList.logLimit()}")
|
||||||
|
|
||||||
Realm.getInstance(cryptoRealmConfiguration).use { cryptoRealm ->
|
Realm.getInstance(cryptoRealmConfiguration).use { cryptoRealm ->
|
||||||
Realm.getInstance(sessionRealmConfiguration).use { sessionRealm ->
|
Realm.getInstance(sessionRealmConfiguration).use {
|
||||||
updateTrust(userList, cryptoRealm, sessionRealm)
|
updateTrust(userList, cryptoRealm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,14 +109,13 @@ internal class UpdateTrustWorker(context: Context,
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTrust(userListParam: List<String>,
|
private suspend fun updateTrust(userListParam: List<String>,
|
||||||
cRealm: Realm,
|
cRealm: Realm) {
|
||||||
sRealm: Realm) {
|
|
||||||
var userList = userListParam
|
var userList = userListParam
|
||||||
var myCrossSigningInfo: MXCrossSigningInfo? = null
|
var myCrossSigningInfo: MXCrossSigningInfo? = null
|
||||||
// First we check that the users MSK are trusted by mine
|
// First we check that the users MSK are trusted by mine
|
||||||
// After that we check the trust chain for each devices of each users
|
// After that we check the trust chain for each devices of each users
|
||||||
cRealm.executeTransaction { cryptoRealm ->
|
awaitTransaction(cryptoRealmConfiguration) { cryptoRealm ->
|
||||||
// By mapping here to model, this object is not live
|
// By mapping here to model, this object is not live
|
||||||
// I should update it if needed
|
// I should update it if needed
|
||||||
myCrossSigningInfo = getCrossSigningInfo(cryptoRealm, myUserId)
|
myCrossSigningInfo = getCrossSigningInfo(cryptoRealm, myUserId)
|
||||||
|
@ -203,7 +205,7 @@ internal class UpdateTrustWorker(context: Context,
|
||||||
// We can now update room shields? in the session DB?
|
// We can now update room shields? in the session DB?
|
||||||
|
|
||||||
Timber.d("## CrossSigning - Updating shields for impacted rooms...")
|
Timber.d("## CrossSigning - Updating shields for impacted rooms...")
|
||||||
sRealm.executeTransaction { sessionRealm ->
|
awaitTransaction(sessionRealmConfiguration) { sessionRealm ->
|
||||||
sessionRealm.where(RoomMemberSummaryEntity::class.java)
|
sessionRealm.where(RoomMemberSummaryEntity::class.java)
|
||||||
.`in`(RoomMemberSummaryEntityFields.USER_ID, userList.toTypedArray())
|
.`in`(RoomMemberSummaryEntityFields.USER_ID, userList.toTypedArray())
|
||||||
.distinct(RoomMemberSummaryEntityFields.ROOM_ID)
|
.distinct(RoomMemberSummaryEntityFields.ROOM_ID)
|
||||||
|
|
Loading…
Reference in New Issue