Realm: fix small identity mistakes

This commit is contained in:
ganfra 2022-07-29 15:19:21 +02:00
parent ed135bc4fc
commit 7e2f821287
3 changed files with 14 additions and 4 deletions

View File

@ -79,7 +79,7 @@ internal abstract class IdentityModule {
.apply {
realmKeysUtils.configureEncryption(this, SessionModule.getKeyAlias(userMd5))
}
.name("matrix-sdk-global.realm")
.name("matrix-sdk-identity.realm")
.schemaVersion(identityStoreMigration.schemaVersion)
.migration(identityStoreMigration)
.build()

View File

@ -43,9 +43,19 @@ internal class RealmIdentityStore @Inject constructor(
}
override suspend fun setUrl(url: String?) {
val identityData = getIdentityDataEntity() ?: return
realmInstance.write {
findLatest(identityData)?.identityServerUrl = url
delete(
query(IdentityDataEntity::class).find()
)
// Delete all pending binding if any
delete(
query(IdentityPendingBindingEntity::class).find()
)
if (url == null) return@write
val newIdentityData = IdentityDataEntity().apply {
identityServerUrl = url
}
copyToRealm(newIdentityData)
}
}

View File

@ -23,7 +23,7 @@ import javax.inject.Inject
internal class RealmIdentityStoreMigration @Inject constructor() : MatrixAutomaticSchemaMigration(
dbName = "Identity",
schemaVersion = 1L,
schemaVersion = 2L,
) {
/**