crypto: Add a missing dispatchTxUpdated call to the verifications

This commit is contained in:
Damir Jelić 2021-08-11 15:48:09 +02:00
parent c85847df57
commit 3365c10fe3
2 changed files with 16 additions and 39 deletions

View file

@ -42,6 +42,7 @@ internal class QrCodeVerification(
private val dispatcher = UpdateDispatcher(listeners)
private fun dispatchTxUpdated() {
refreshData()
this.dispatcher.dispatchTxUpdated(this)
}
@ -101,9 +102,7 @@ internal class QrCodeVerification(
inner.reciprocated -> VerificationTxState.Started
inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm
inner.otherSideScanned -> VerificationTxState.QrScannedByOther
else -> {
VerificationTxState.None
}
else -> VerificationTxState.None
}
} else {
VerificationTxState.None
@ -182,6 +181,7 @@ internal class QrCodeVerification(
if (request != null) {
this.sender.sendVerificationRequest(request)
dispatchTxUpdated()
}
}
@ -189,23 +189,11 @@ internal class QrCodeVerification(
val request = this.machine.cancelVerification(this.request.otherUser(), this.request.flowId(), code.value)
if (request != null) {
sendRequest(request)
runBlocking { sender.sendVerificationRequest(request) }
dispatchTxUpdated()
}
}
/** Send out a verification request in a blocking manner
*
* This is useful since the public methods to accept/confirm/cancel the verification
* aren't suspendable but sending a request out obviously should be. This bridges the
* gap between our suspendable and non-suspendable methods.
*/
private fun sendRequest(request: OutgoingVerificationRequest) {
runBlocking { sender.sendVerificationRequest(request) }
refreshData()
dispatchTxUpdated()
}
/** Fetch fresh data from the Rust side for our verification flow */
private fun refreshData() {
when (val verification = this.machine.getVerification(this.request.otherUser(), this.request.flowId())) {

View file

@ -29,7 +29,6 @@ import org.matrix.android.sdk.internal.crypto.verification.UpdateDispatcher
import org.matrix.android.sdk.internal.crypto.verification.getEmojiForCode
import uniffi.olm.CryptoStoreErrorException
import uniffi.olm.OlmMachine
import uniffi.olm.OutgoingVerificationRequest
import uniffi.olm.Sas
import uniffi.olm.Verification
@ -44,6 +43,7 @@ internal class SasVerification(
private val dispatcher = UpdateDispatcher(listeners)
private fun dispatchTxUpdated() {
refreshData()
this.dispatcher.dispatchTxUpdated(this)
}
@ -65,16 +65,17 @@ internal class SasVerification(
get() {
refreshData()
val cancelInfo = this.inner.cancelInfo
return when {
cancelInfo != null -> {
cancelInfo != null -> {
val cancelCode = safeValueOf(cancelInfo.cancelCode)
VerificationTxState.Cancelled(cancelCode, cancelInfo.cancelledByUs)
}
this.inner.isDone -> VerificationTxState.Verified
this.inner.haveWeConfirmed -> VerificationTxState.ShortCodeAccepted
this.inner.canBePresented -> VerificationTxState.ShortCodeReady
this.inner.hasBeenAccepted -> VerificationTxState.Accepted
else -> VerificationTxState.OnStarted
inner.isDone -> VerificationTxState.Verified
inner.haveWeConfirmed -> VerificationTxState.ShortCodeAccepted
inner.canBePresented -> VerificationTxState.ShortCodeReady
inner.hasBeenAccepted -> VerificationTxState.Accepted
else -> VerificationTxState.OnStarted
}
}
@Suppress("UNUSED_PARAMETER")
@ -197,7 +198,6 @@ internal class SasVerification(
if (request != null) {
this.sender.sendVerificationRequest(request)
refreshData()
dispatchTxUpdated()
}
}
@ -209,6 +209,7 @@ internal class SasVerification(
}
if (request != null) {
this.sender.sendVerificationRequest(request)
dispatchTxUpdated()
}
}
@ -216,23 +217,11 @@ internal class SasVerification(
val request = this.machine.cancelVerification(this.inner.otherUserId, inner.flowId, code.value)
if (request != null) {
sendRequest(request)
runBlocking { sender.sendVerificationRequest(request) }
dispatchTxUpdated()
}
}
/** Send out a verification request in a blocking manner
*
* This is useful since the public methods to accept/confirm/cancel the verification
* aren't suspendable but sending a request out obviously should be. This bridges the
* gap between our suspendable and non-suspendable methods.
*/
private fun sendRequest(request: OutgoingVerificationRequest) {
runBlocking { sender.sendVerificationRequest(request) }
refreshData()
dispatchTxUpdated()
}
/** Fetch fresh data from the Rust side for our verification flow */
private fun refreshData() {
when (val verification = this.machine.getVerification(this.inner.otherUserId, this.inner.flowId)) {