From fcd290410e99c62a3b9a05891b462a6f9b22d164 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 24 Mar 2020 10:06:15 +0100 Subject: [PATCH] Also cancel pending request on back --- .../crypto/verification/VerificationService.kt | 2 ++ .../verification/DefaultVerificationService.kt | 12 ++++++++++++ .../verification/VerificationBottomSheetViewModel.kt | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/verification/VerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/verification/VerificationService.kt index 75033082d6..4482101434 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/verification/VerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/verification/VerificationService.kt @@ -60,6 +60,8 @@ interface VerificationService { roomId: String, localId: String? = LocalEcho.createLocalEchoId()): PendingVerificationRequest + fun cancelVerificationRequest(request: PendingVerificationRequest) + /** * Request a key verification from another user using toDevice events. */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt index 846fc80930..1a7549d696 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt @@ -1102,6 +1102,18 @@ internal class DefaultVerificationService @Inject constructor( return verificationRequest } + override fun cancelVerificationRequest(request: PendingVerificationRequest) { + if (request.roomId != null) { + val transport = verificationTransportRoomMessageFactory.createTransport(request.roomId, null) + transport.cancelTransaction(request.transactionId ?: "", request.otherUserId, null, CancelCode.User) + } else { + val transport = verificationTransportToDeviceFactory.createTransport(null) + request.targetDevices?.forEach { deviceId -> + transport.cancelTransaction(request.transactionId ?: "", request.otherUserId, deviceId, CancelCode.User) + } + } + } + override fun requestKeyVerification(methods: List, otherUserId: String, otherDevices: List?): PendingVerificationRequest { // TODO refactor this with the DM one Timber.i("## Requesting verification to user: $otherUserId with device list $otherDevices") diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt index fab59fe5af..515657eb13 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -149,6 +149,10 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( } fun confirmCancel() = withState { state -> + session.cryptoService() + .verificationService().getExistingVerificationRequest(state.otherUserMxItem?.id ?: "", state.transactionId)?.let { + session.cryptoService().verificationService().cancelVerificationRequest(it) + } session.cryptoService() .verificationService() .getExistingTransaction(state.otherUserMxItem?.id ?: "", state.transactionId ?: "")