diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/verification/SASTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/verification/SASTest.kt index 75c7ad4d53..a81f503e77 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/verification/SASTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/verification/SASTest.kt @@ -555,7 +555,7 @@ class SASTest : InstrumentedTest { mTestHelper.waitWithLatch { mTestHelper.retryPeriodicallyWithLatch(it) { - val prAlicePOV = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId)?.firstOrNull() + val prAlicePOV = aliceVerificationService.getExistingVerificationRequests(bobSession.myUserId).firstOrNull() requestID = prAlicePOV?.transactionId Log.v("TEST", "== alicePOV is $prAlicePOV") prAlicePOV?.transactionId != null && prAlicePOV.localId == req.localId @@ -566,7 +566,7 @@ class SASTest : InstrumentedTest { mTestHelper.waitWithLatch { mTestHelper.retryPeriodicallyWithLatch(it) { - val prBobPOV = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId)?.firstOrNull() + val prBobPOV = bobVerificationService.getExistingVerificationRequests(aliceSession.myUserId).firstOrNull() Log.v("TEST", "== prBobPOV is $prBobPOV") prBobPOV?.transactionId == requestID } @@ -581,7 +581,7 @@ class SASTest : InstrumentedTest { // wait for alice to get the ready mTestHelper.waitWithLatch { mTestHelper.retryPeriodicallyWithLatch(it) { - val prAlicePOV = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId)?.firstOrNull() + val prAlicePOV = aliceVerificationService.getExistingVerificationRequests(bobSession.myUserId).firstOrNull() Log.v("TEST", "== prAlicePOV is $prAlicePOV") prAlicePOV?.transactionId == requestID && prAlicePOV?.isReady != null } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationService.kt index 65c6a1f1f7..2413786ea9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/verification/VerificationService.kt @@ -41,7 +41,7 @@ interface VerificationService { fun getExistingTransaction(otherUserId: String, tid: String): VerificationTransaction? - fun getExistingVerificationRequest(otherUserId: String): List? + fun getExistingVerificationRequests(otherUserId: String): List fun getExistingVerificationRequest(otherUserId: String, tid: String?): PendingVerificationRequest? diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/DefaultVerificationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/DefaultVerificationService.kt index 7f02750359..29ddd92213 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/DefaultVerificationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/DefaultVerificationService.kt @@ -537,11 +537,10 @@ internal class DefaultVerificationService @Inject constructor( // If there is a corresponding request, we can auto accept // as we are the one requesting in first place (or we accepted the request) // I need to check if the pending request was related to this device also - val autoAccept = getExistingVerificationRequest(otherUserId)?.any { + val autoAccept = getExistingVerificationRequests(otherUserId).any { it.transactionId == startReq.transactionId && (it.requestInfo?.fromDevice == this.deviceId || it.readyInfo?.fromDevice == this.deviceId) } - ?: false val tx = DefaultIncomingSASDefaultVerificationTransaction( // this, setDeviceVerificationAction, @@ -837,8 +836,8 @@ internal class DefaultVerificationService @Inject constructor( // SAS do not care for now? } - // Now transactions are udated, let's also update Requests - val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneReq.transactionId } + // Now transactions are updated, let's also update Requests + val existingRequest = getExistingVerificationRequests(senderId).find { it.transactionId == doneReq.transactionId } if (existingRequest == null) { Timber.e("## SAS Received Done for unknown request txId:${doneReq.transactionId}") return @@ -892,7 +891,7 @@ internal class DefaultVerificationService @Inject constructor( private fun handleReadyReceived(senderId: String, readyReq: ValidVerificationInfoReady, transportCreator: (DefaultVerificationTransaction) -> VerificationTransport) { - val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == readyReq.transactionId } + val existingRequest = getExistingVerificationRequests(senderId).find { it.transactionId == readyReq.transactionId } if (existingRequest == null) { Timber.e("## SAS Received Ready for unknown request txId:${readyReq.transactionId} fromDevice ${readyReq.fromDevice}") return @@ -1041,9 +1040,9 @@ internal class DefaultVerificationService @Inject constructor( } } - override fun getExistingVerificationRequest(otherUserId: String): List? { + override fun getExistingVerificationRequests(otherUserId: String): List { synchronized(lock = pendingRequests) { - return pendingRequests[otherUserId] + return pendingRequests[otherUserId].orEmpty() } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt index 862b2de85a..c7533cd3df 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModel.kt @@ -143,7 +143,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor( // as we are going to reset, we'd better cancel all outgoing requests // if not they could be accepted in the middle of the reset process // and cause strange use cases - session.cryptoService().verificationService().getExistingVerificationRequest(session.myUserId)?.forEach { + session.cryptoService().verificationService().getExistingVerificationRequests(session.myUserId).forEach { session.cryptoService().verificationService().cancelVerificationRequest(it) } _viewEvents.post(SharedSecureStorageViewEvent.ShowResetBottomSheet) 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 2d09974687..aa20a9a992 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 @@ -99,8 +99,8 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( val pr = if (selfVerificationMode) { // See if active tx for this user and take it - session.cryptoService().verificationService().getExistingVerificationRequest(args.otherUserId) - ?.lastOrNull { !it.isFinished } + session.cryptoService().verificationService().getExistingVerificationRequests(args.otherUserId) + .lastOrNull { !it.isFinished } ?.also { verificationRequest -> if (verificationRequest.isIncoming && !verificationRequest.isReady) { // auto ready in this case, as we are waiting