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 val dispatcher = UpdateDispatcher(listeners)
private fun dispatchTxUpdated() { private fun dispatchTxUpdated() {
refreshData()
this.dispatcher.dispatchTxUpdated(this) this.dispatcher.dispatchTxUpdated(this)
} }
@ -101,9 +102,7 @@ internal class QrCodeVerification(
inner.reciprocated -> VerificationTxState.Started inner.reciprocated -> VerificationTxState.Started
inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm
inner.otherSideScanned -> VerificationTxState.QrScannedByOther inner.otherSideScanned -> VerificationTxState.QrScannedByOther
else -> { else -> VerificationTxState.None
VerificationTxState.None
}
} }
} else { } else {
VerificationTxState.None VerificationTxState.None
@ -182,6 +181,7 @@ internal class QrCodeVerification(
if (request != null) { if (request != null) {
this.sender.sendVerificationRequest(request) this.sender.sendVerificationRequest(request)
dispatchTxUpdated()
} }
} }
@ -189,22 +189,10 @@ internal class QrCodeVerification(
val request = this.machine.cancelVerification(this.request.otherUser(), this.request.flowId(), code.value) val request = this.machine.cancelVerification(this.request.otherUser(), this.request.flowId(), code.value)
if (request != null) { if (request != null) {
sendRequest(request)
}
}
/** 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) } runBlocking { sender.sendVerificationRequest(request) }
refreshData()
dispatchTxUpdated() dispatchTxUpdated()
} }
}
/** Fetch fresh data from the Rust side for our verification flow */ /** Fetch fresh data from the Rust side for our verification flow */
private fun refreshData() { private fun refreshData() {

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 org.matrix.android.sdk.internal.crypto.verification.getEmojiForCode
import uniffi.olm.CryptoStoreErrorException import uniffi.olm.CryptoStoreErrorException
import uniffi.olm.OlmMachine import uniffi.olm.OlmMachine
import uniffi.olm.OutgoingVerificationRequest
import uniffi.olm.Sas import uniffi.olm.Sas
import uniffi.olm.Verification import uniffi.olm.Verification
@ -44,6 +43,7 @@ internal class SasVerification(
private val dispatcher = UpdateDispatcher(listeners) private val dispatcher = UpdateDispatcher(listeners)
private fun dispatchTxUpdated() { private fun dispatchTxUpdated() {
refreshData()
this.dispatcher.dispatchTxUpdated(this) this.dispatcher.dispatchTxUpdated(this)
} }
@ -65,15 +65,16 @@ internal class SasVerification(
get() { get() {
refreshData() refreshData()
val cancelInfo = this.inner.cancelInfo val cancelInfo = this.inner.cancelInfo
return when { return when {
cancelInfo != null -> { cancelInfo != null -> {
val cancelCode = safeValueOf(cancelInfo.cancelCode) val cancelCode = safeValueOf(cancelInfo.cancelCode)
VerificationTxState.Cancelled(cancelCode, cancelInfo.cancelledByUs) VerificationTxState.Cancelled(cancelCode, cancelInfo.cancelledByUs)
} }
this.inner.isDone -> VerificationTxState.Verified inner.isDone -> VerificationTxState.Verified
this.inner.haveWeConfirmed -> VerificationTxState.ShortCodeAccepted inner.haveWeConfirmed -> VerificationTxState.ShortCodeAccepted
this.inner.canBePresented -> VerificationTxState.ShortCodeReady inner.canBePresented -> VerificationTxState.ShortCodeReady
this.inner.hasBeenAccepted -> VerificationTxState.Accepted inner.hasBeenAccepted -> VerificationTxState.Accepted
else -> VerificationTxState.OnStarted else -> VerificationTxState.OnStarted
} }
} }
@ -197,7 +198,6 @@ internal class SasVerification(
if (request != null) { if (request != null) {
this.sender.sendVerificationRequest(request) this.sender.sendVerificationRequest(request)
refreshData()
dispatchTxUpdated() dispatchTxUpdated()
} }
} }
@ -209,6 +209,7 @@ internal class SasVerification(
} }
if (request != null) { if (request != null) {
this.sender.sendVerificationRequest(request) this.sender.sendVerificationRequest(request)
dispatchTxUpdated()
} }
} }
@ -216,22 +217,10 @@ internal class SasVerification(
val request = this.machine.cancelVerification(this.inner.otherUserId, inner.flowId, code.value) val request = this.machine.cancelVerification(this.inner.otherUserId, inner.flowId, code.value)
if (request != null) { if (request != null) {
sendRequest(request)
}
}
/** 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) } runBlocking { sender.sendVerificationRequest(request) }
refreshData()
dispatchTxUpdated() dispatchTxUpdated()
} }
}
/** Fetch fresh data from the Rust side for our verification flow */ /** Fetch fresh data from the Rust side for our verification flow */
private fun refreshData() { private fun refreshData() {