mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Identity: change DB and add sendAttempt
This commit is contained in:
parent
b44f5d3b4a
commit
7e8e1ab9b7
@ -67,6 +67,7 @@ internal class DefaultIdentityRequestTokenForBindingTask @Inject constructor(
|
||||
identityServiceStore.storePendingBinding(
|
||||
params.threePid,
|
||||
clientSecret,
|
||||
1,
|
||||
tokenResponse.sid)
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,22 @@
|
||||
|
||||
package im.vector.matrix.android.internal.session.identity.db
|
||||
|
||||
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||
import im.vector.matrix.android.api.session.identity.toMedium
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
internal open class IdentityPendingBindingEntity(
|
||||
var threePidValue: String = "",
|
||||
var medium: String = "",
|
||||
@PrimaryKey var threePid: String = "",
|
||||
/* Managed by Riot */
|
||||
var clientSecret: String = "",
|
||||
/* Managed by Riot */
|
||||
var sendAttempt: Int = 0,
|
||||
/* Provided by the identity server */
|
||||
var sid: String = ""
|
||||
) : RealmObject() {
|
||||
|
||||
companion object
|
||||
companion object {
|
||||
fun ThreePid.toPrimaryKey() = "${toMedium()}_$value"
|
||||
}
|
||||
}
|
||||
|
@ -17,26 +17,23 @@
|
||||
package im.vector.matrix.android.internal.session.identity.db
|
||||
|
||||
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||
import im.vector.matrix.android.api.session.identity.toMedium
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
|
||||
internal fun IdentityPendingBindingEntity.Companion.get(realm: Realm, threePid: ThreePid): IdentityPendingBindingEntity? {
|
||||
return realm.where<IdentityPendingBindingEntity>()
|
||||
.equalTo(IdentityPendingBindingEntityFields.THREE_PID_VALUE, threePid.value)
|
||||
.equalTo(IdentityPendingBindingEntityFields.MEDIUM, threePid.toMedium())
|
||||
.equalTo(IdentityPendingBindingEntityFields.THREE_PID, threePid.toPrimaryKey())
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
internal fun IdentityPendingBindingEntity.Companion.getOrCreate(realm: Realm, threePid: ThreePid): IdentityPendingBindingEntity {
|
||||
return get(realm, threePid) ?: realm.createObject()
|
||||
return get(realm, threePid) ?: realm.createObject(threePid.toPrimaryKey())
|
||||
}
|
||||
|
||||
internal fun IdentityPendingBindingEntity.Companion.delete(realm: Realm, threePid: ThreePid) {
|
||||
realm.where<IdentityPendingBindingEntity>()
|
||||
.equalTo(IdentityPendingBindingEntityFields.THREE_PID_VALUE, threePid.value)
|
||||
.equalTo(IdentityPendingBindingEntityFields.MEDIUM, threePid.toMedium())
|
||||
.equalTo(IdentityPendingBindingEntityFields.THREE_PID, threePid.toPrimaryKey())
|
||||
.findAll()
|
||||
.deleteAllFromRealm()
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ internal interface IdentityServiceStore {
|
||||
*/
|
||||
fun storePendingBinding(threePid: ThreePid,
|
||||
clientSecret: String,
|
||||
sendAttempt: Int,
|
||||
sid: String)
|
||||
|
||||
fun getPendingBinding(threePid: ThreePid): IdentityPendingBindingEntity?
|
||||
|
@ -61,13 +61,12 @@ internal class RealmIdentityServiceStore @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun storePendingBinding(threePid: ThreePid, clientSecret: String, sid: String) {
|
||||
override fun storePendingBinding(threePid: ThreePid, clientSecret: String, sendAttempt: Int, sid: String) {
|
||||
Realm.getInstance(realmConfiguration).use {
|
||||
it.executeTransaction { realm ->
|
||||
IdentityPendingBindingEntity.getOrCreate(realm, threePid).let { entity ->
|
||||
entity.threePidValue = threePid.value
|
||||
entity.medium = threePid.toMedium()
|
||||
entity.clientSecret = clientSecret
|
||||
entity.sendAttempt = sendAttempt
|
||||
entity.sid = sid
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user