From b26318f15c6f87e6b2dddbe8b7edd982dd58529d Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 2 Jan 2020 12:51:12 +0100 Subject: [PATCH] Fix / Cancel messages was not sent --- .../internal/crypto/verification/SasTransport.kt | 2 +- .../crypto/verification/SasTransportRoomMessage.kt | 4 ++-- .../crypto/verification/SasTransportToDevice.kt | 4 ++-- .../verification/SendVerificationMessageWorker.kt | 11 ++++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransport.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransport.kt index 43c1762a89..60e0204800 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransport.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransport.kt @@ -36,7 +36,7 @@ internal interface SasTransport { fun sendVerificationRequest(localID: String, otherUserId: String, roomId: String, callback: (String?, MessageVerificationRequestContent?) -> Unit) - fun cancelTransaction(transactionId: String, userId: String, userDevice: String, code: CancelCode) + fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDevice: String, code: CancelCode) fun done(transactionId: String) /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportRoomMessage.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportRoomMessage.kt index e3b5afd8e1..9beee96e93 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportRoomMessage.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportRoomMessage.kt @@ -177,7 +177,7 @@ internal class SasTransportRoomMessage( } } - override fun cancelTransaction(transactionId: String, userId: String, userDevice: String, code: CancelCode) { + override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDevice: String, code: CancelCode) { Timber.d("## SAS canceling transaction $transactionId for reason $code") val event = createEventAndLocalEcho( type = EventType.KEY_VERIFICATION_CANCEL, @@ -185,7 +185,7 @@ internal class SasTransportRoomMessage( content = MessageVerificationCancelContent.create(transactionId, code).toContent() ) val workerParams = WorkerParamsFactory.toData(SendVerificationMessageWorker.Params( - userId = userId, + userId = this.userId, event = event )) enqueueSendWork(workerParams) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt index 8e945e6cab..20cd603679 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt @@ -77,11 +77,11 @@ internal class SasTransportToDevice( // To device do not do anything here } - override fun cancelTransaction(transactionId: String, userId: String, userDevice: String, code: CancelCode) { + override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDevice: String, code: CancelCode) { Timber.d("## SAS canceling transaction $transactionId for reason $code") val cancelMessage = KeyVerificationCancel.create(transactionId, code) val contentMap = MXUsersDevicesMap() - contentMap.setObject(userId, userDevice, cancelMessage) + contentMap.setObject(otherUserId, otherUserDevice, cancelMessage) sendToDeviceTask .configureWith(SendToDeviceTask.Params(EventType.KEY_VERIFICATION_CANCEL, contentMap, transactionId)) { this.callback = object : MatrixCallback { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt index 656641706a..c0eaace7ca 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt @@ -12,6 +12,7 @@ import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.internal.crypto.tasks.SendVerificationMessageTask import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.getSessionComponent +import timber.log.Timber import javax.inject.Inject internal class SendVerificationMessageWorker constructor(context: Context, params: WorkerParameters) @@ -30,10 +31,14 @@ internal class SendVerificationMessageWorker constructor(context: Context, param lateinit var cryptoService: CryptoService override suspend fun doWork(): Result { + val errorOutputData = Data.Builder().putBoolean("failed", true).build() val params = WorkerParamsFactory.fromData(inputData) - ?: return Result.success(Data.Builder().putBoolean("failed", true).build()) + ?: return Result.success(errorOutputData) - val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success(errorOutputData).also { + // TODO, can this happen? should I update local echo? + Timber.e("Unknown Session, cannot send message, userId:${params.userId}") + } sessionComponent.inject(this) val localId = params.event.eventId ?: "" return try { @@ -49,7 +54,7 @@ internal class SendVerificationMessageWorker constructor(context: Context, param if (exception.shouldBeRetried()) { Result.retry() } else { - Result.success(Data.Builder().putBoolean("failed", true).build()) + Result.success(errorOutputData) } } }