mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Identity: store sendAttempt in DB
This commit is contained in:
parent
7e8e1ab9b7
commit
69759b7415
2 changed files with 11 additions and 8 deletions
|
@ -20,7 +20,7 @@ import im.vector.matrix.android.api.session.identity.ThreePid
|
|||
import im.vector.matrix.android.api.session.identity.getCountryCode
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.identity.db.RealmIdentityServiceStore
|
||||
import im.vector.matrix.android.internal.session.identity.db.IdentityServiceStore
|
||||
import im.vector.matrix.android.internal.session.identity.model.IdentityRequestTokenForEmailBody
|
||||
import im.vector.matrix.android.internal.session.identity.model.IdentityRequestTokenForMsisdnBody
|
||||
import im.vector.matrix.android.internal.session.identity.model.IdentityRequestTokenResponse
|
||||
|
@ -36,26 +36,29 @@ internal interface IdentityRequestTokenForBindingTask : Task<IdentityRequestToke
|
|||
|
||||
internal class DefaultIdentityRequestTokenForBindingTask @Inject constructor(
|
||||
private val identityApiProvider: IdentityApiProvider,
|
||||
private val identityServiceStore: RealmIdentityServiceStore,
|
||||
private val identityServiceStore: IdentityServiceStore,
|
||||
@UserId private val userId: String
|
||||
) : IdentityRequestTokenForBindingTask {
|
||||
|
||||
override suspend fun execute(params: IdentityRequestTokenForBindingTask.Params) {
|
||||
val identityAPI = getIdentityApiAndEnsureTerms(identityApiProvider, userId)
|
||||
|
||||
val clientSecret = UUID.randomUUID().toString()
|
||||
val pendingBindingEntity = identityServiceStore.getPendingBinding(params.threePid)
|
||||
|
||||
val clientSecret = pendingBindingEntity?.clientSecret ?: UUID.randomUUID().toString()
|
||||
val sendAttempt = pendingBindingEntity?.sendAttempt?.inc() ?: 1
|
||||
|
||||
val tokenResponse = executeRequest<IdentityRequestTokenResponse>(null) {
|
||||
apiCall = when (params.threePid) {
|
||||
is ThreePid.Email -> identityAPI.requestTokenToBindEmail(IdentityRequestTokenForEmailBody(
|
||||
clientSecret = clientSecret,
|
||||
sendAttempt = 1,
|
||||
sendAttempt = sendAttempt,
|
||||
email = params.threePid.email
|
||||
))
|
||||
is ThreePid.Msisdn -> {
|
||||
identityAPI.requestTokenToBindMsisdn(IdentityRequestTokenForMsisdnBody(
|
||||
clientSecret = clientSecret,
|
||||
sendAttempt = 1,
|
||||
sendAttempt = sendAttempt,
|
||||
phoneNumber = params.threePid.msisdn,
|
||||
countryCode = params.threePid.getCountryCode()
|
||||
))
|
||||
|
@ -67,7 +70,7 @@ internal class DefaultIdentityRequestTokenForBindingTask @Inject constructor(
|
|||
identityServiceStore.storePendingBinding(
|
||||
params.threePid,
|
||||
clientSecret,
|
||||
1,
|
||||
sendAttempt,
|
||||
tokenResponse.sid)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import im.vector.matrix.android.api.session.identity.toMedium
|
|||
import im.vector.matrix.android.internal.auth.registration.SuccessResult
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.identity.db.RealmIdentityServiceStore
|
||||
import im.vector.matrix.android.internal.session.identity.db.IdentityServiceStore
|
||||
import im.vector.matrix.android.internal.session.identity.model.IdentityRequestOwnershipParams
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
@ -36,7 +36,7 @@ internal interface IdentitySubmitTokenForBindingTask : Task<IdentitySubmitTokenF
|
|||
|
||||
internal class DefaultIdentitySubmitTokenForBindingTask @Inject constructor(
|
||||
private val identityApiProvider: IdentityApiProvider,
|
||||
private val identityServiceStore: RealmIdentityServiceStore,
|
||||
private val identityServiceStore: IdentityServiceStore,
|
||||
@UserId private val userId: String
|
||||
) : IdentitySubmitTokenForBindingTask {
|
||||
|
||||
|
|
Loading…
Reference in a new issue