From 3365c10fe3b7e642f19ecbe517590dcc4ff35925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 11 Aug 2021 15:48:09 +0200 Subject: [PATCH] crypto: Add a missing dispatchTxUpdated call to the verifications --- .../sdk/internal/crypto/QrCodeVerification.kt | 22 +++---------- .../sdk/internal/crypto/SasVerification.kt | 33 +++++++------------ 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt index ea6eba5c6c..de06691f93 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt @@ -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())) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt index ad8322a2ab..4756ac5b1c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt @@ -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)) {