From 704e14c6a45fefa9319c2e6552656403637e0668 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 3 Feb 2023 00:10:05 +0100 Subject: [PATCH] Fix QR code signaling --- .../verification/qrcode/QrCodeVerification.kt | 26 +++++++++++-------- .../verification/user/VerificationEpoxyExt.kt | 25 +++++++++++++++++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/qrcode/QrCodeVerification.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/qrcode/QrCodeVerification.kt index ac79668db9..dcf4c4013d 100644 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/qrcode/QrCodeVerification.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/qrcode/QrCodeVerification.kt @@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.crypto.network.RequestSender import org.matrix.android.sdk.internal.crypto.verification.VerificationListenersHolder import org.matrix.rustcomponents.sdk.crypto.CryptoStoreException import org.matrix.rustcomponents.sdk.crypto.QrCode +import org.matrix.rustcomponents.sdk.crypto.QrCodeState import timber.log.Timber /** Class representing a QR code based verification flow */ @@ -97,18 +98,21 @@ internal class QrCodeVerification @AssistedInject constructor( } override fun state(): QRCodeVerificationState { - Timber.w("VALR state: weStarted ${inner.weStarted()}") - Timber.w("VALR state: reciprocated ${inner.reciprocated()}") - Timber.w("VALR state: isDone ${inner.isDone()}") - Timber.w("VALR state: hasBeenScanned ${inner.hasBeenScanned()}") - - if (inner.hasBeenScanned()) { - return QRCodeVerificationState.WaitingForScanConfirmation + Timber.v("SAS QR state${inner.state()}") + return when (inner.state()) { + // / The QR verification has been started. + QrCodeState.Started -> QRCodeVerificationState.Reciprocated + // / The QR verification has been scanned by the other side. + QrCodeState.Scanned -> QRCodeVerificationState.WaitingForScanConfirmation + // / The scanning of the QR code has been confirmed by us. + QrCodeState.Confirmed -> QRCodeVerificationState.WaitingForOtherDone + // / We have successfully scanned the QR code and are able to send a + // / reciprocation event. + QrCodeState.Reciprocated -> QRCodeVerificationState.WaitingForOtherDone + // / The verification process has been successfully concluded. + QrCodeState.Done -> QRCodeVerificationState.Done + is QrCodeState.Cancelled -> QRCodeVerificationState.Cancelled } - if (inner.isCancelled()) return QRCodeVerificationState.Cancelled - if (inner.isDone()) return QRCodeVerificationState.Done - - return QRCodeVerificationState.Reciprocated } /** Get the unique id of this verification */ diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/user/VerificationEpoxyExt.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/user/VerificationEpoxyExt.kt index 24d193e38d..f841c253cb 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/user/VerificationEpoxyExt.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/user/VerificationEpoxyExt.kt @@ -361,7 +361,30 @@ fun BaseEpoxyVerificationController.renderQrTransaction(transaction: Verificatio listener { host.listener?.onUserConfirmsQrCodeScanned() } } } - QRCodeVerificationState.WaitingForOtherDone, + QRCodeVerificationState.WaitingForOtherDone -> { + bottomSheetVerificationNoticeItem { + id("notice") + apply { + notice(host.stringProvider.getString(R.string.qr_code_scanned_verif_waiting_notice).toEpoxyCharSequence()) + } + } + + bottomSheetVerificationBigImageItem { + id("image") + roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Trusted) + } + + bottomSheetVerificationWaitingItem { + id("waiting") + apply { + if (otherUserItem != null) { + title(host.stringProvider.getString(R.string.qr_code_scanned_verif_waiting, otherUserItem.getBestName())) + } else { + title(host.stringProvider.getString(R.string.qr_code_scanned_verif_waiting, transaction.otherDeviceId.orEmpty())) + } + } + } + } QRCodeVerificationState.Done -> { // Done }