Ensure credentials can be stored, even if they already exist

This commit is contained in:
Benoit Marty 2019-12-02 10:57:19 +01:00
parent 3f4f7457c7
commit 1cadbb8eed
1 changed files with 8 additions and 1 deletions

View File

@ -22,6 +22,8 @@ import im.vector.matrix.android.internal.database.awaitTransaction
import im.vector.matrix.android.internal.di.AuthDatabase import im.vector.matrix.android.internal.di.AuthDatabase
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import io.realm.exceptions.RealmPrimaryKeyConstraintException
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper, internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper,
@ -63,7 +65,12 @@ internal class RealmSessionParamsStore @Inject constructor(private val mapper: S
awaitTransaction(realmConfiguration) { awaitTransaction(realmConfiguration) {
val entity = mapper.map(sessionParams) val entity = mapper.map(sessionParams)
if (entity != null) { if (entity != null) {
try {
it.insert(entity) it.insert(entity)
} catch (e: RealmPrimaryKeyConstraintException) {
Timber.e(e, "Something wrong happened during previous session creation. Override with new credentials")
it.insertOrUpdate(entity)
}
} }
} }
} }