From 111869dba81aa3271abeb83c08069969a552a3e6 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 16 Jun 2022 16:44:30 +0200 Subject: [PATCH] show option to accept other verif not ready --- .../crypto/verification/VerificationAction.kt | 2 ++ .../VerificationBottomSheetViewModel.kt | 25 +++++++++++++++++++ .../VerificationChooseMethodController.kt | 17 +++++++++++++ .../VerificationChooseMethodFragment.kt | 12 +++++++++ .../VerificationChooseMethodViewModel.kt | 6 +++-- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationAction.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationAction.kt index c4ae2d278b6..1b18117cf3f 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationAction.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationAction.kt @@ -30,6 +30,8 @@ sealed class VerificationAction : VectorViewModelAction { data class GotItConclusion(val verified: Boolean) : VerificationAction() object SkipVerification : VerificationAction() object VerifyFromPassphrase : VerificationAction() + object ReadyPendingVerification : VerificationAction() + object CancelPendingVerification : VerificationAction() data class GotResultFromSsss(val cypherData: String, val alias: String) : VerificationAction() object CancelledFromSsss : VerificationAction() object SecuredStorageHasBeenReset : VerificationAction() diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt index cc5b2d20e4e..f39507a9a4a 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -358,6 +358,31 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( as? SasVerificationTransaction) ?.shortCodeDoesNotMatch() } + is VerificationAction.ReadyPendingVerification -> { + withState { state -> + state.pendingRequest.invoke()?.let { request -> + // will only be there for dm verif + if (state.roomId != null) { + session.cryptoService().verificationService() + .readyPendingVerificationInDMs( + supportedVerificationMethodsProvider.provide(), + state.otherUserId, + state.roomId, + request.transactionId ?: "" + ) + } + } + } + } + is VerificationAction.CancelPendingVerification -> { + withState { state -> + state.pendingRequest.invoke()?.let { + session.cryptoService().verificationService() + .cancelVerificationRequest(it) + } + _viewEvents.post(VerificationBottomSheetViewEvents.Dismiss) + } + } is VerificationAction.GotItConclusion -> { if (state.isVerificationRequired && !action.verified) { // we should go back to first screen diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt index acc8cf61b97..85dbd7d4622 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodController.kt @@ -21,6 +21,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.bottomSheetDividerItem import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider +import im.vector.app.core.ui.list.genericButtonItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationQrCodeItem @@ -108,6 +109,20 @@ class VerificationChooseMethodController @Inject constructor( iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary)) listener { host.listener?.doVerifyBySas() } } + } else if (!state.isReadied) { + // a bit of a special case, if you tapped on the timeline cell but not on a button + genericButtonItem { + id("accept_request") + textColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary)) + text(host.stringProvider.getString(R.string.action_accept)) + buttonClickAction { host.listener?.acceptRequest() } + } + genericButtonItem { + id("decline_request") + textColor(host.colorProvider.getColorFromAttribute(R.attr.colorError)) + text(host.stringProvider.getString(R.string.action_decline)) + buttonClickAction { host.listener?.declineRequest() } + } } if (state.isMe && state.canCrossSign) { @@ -131,5 +146,7 @@ class VerificationChooseMethodController @Inject constructor( fun openCamera() fun doVerifyBySas() fun onClickOnWasNotMe() + fun acceptRequest() + fun declineRequest() } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodFragment.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodFragment.kt index cf6bcc58c06..f8f21454060 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodFragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodFragment.kt @@ -100,6 +100,18 @@ class VerificationChooseMethodFragment @Inject constructor( sharedViewModel.itWasNotMe() } + override fun acceptRequest() { + withState(viewModel) { + sharedViewModel.handle(VerificationAction.ReadyPendingVerification) + } + } + + override fun declineRequest() { + withState(viewModel) { + sharedViewModel.handle(VerificationAction.CancelPendingVerification) + } + } + private fun doOpenQRCodeScanner() { QrCodeScannerActivity.startForResult(requireActivity(), scanActivityResultLauncher) } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodViewModel.kt index a1f902f8f4b..dec0a773dfb 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/choose/VerificationChooseMethodViewModel.kt @@ -44,7 +44,8 @@ data class VerificationChooseMethodViewState( val qrCodeText: String? = null, val sasModeAvailable: Boolean = false, val isMe: Boolean = false, - val canCrossSign: Boolean = false + val canCrossSign: Boolean = false, + val isReadied: Boolean = false ) : MavericksState class VerificationChooseMethodViewModel @AssistedInject constructor( @@ -81,7 +82,8 @@ class VerificationChooseMethodViewModel @AssistedInject constructor( copy( otherCanShowQrCode = pvr?.otherCanShowQrCode().orFalse(), otherCanScanQrCode = pvr?.otherCanScanQrCode().orFalse(), - sasModeAvailable = pvr?.isSasSupported().orFalse() + sasModeAvailable = pvr?.isSasSupported().orFalse(), + isReadied = pvr?.isReady ?: false, ) } }