diff --git a/CHANGES.md b/CHANGES.md index fae13abeed..543af54bf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Improvements 🙌: - Bugfix 🐛: - - + - User Verification in DM not working Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/SendVerificationMessageWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/SendVerificationMessageWorker.kt index 2b7d26e76b..494ef842fd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/SendVerificationMessageWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/SendVerificationMessageWorker.kt @@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.session.crypto.CryptoService import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.internal.crypto.tasks.SendVerificationMessageTask +import org.matrix.android.sdk.internal.session.room.send.CancelSendTracker import org.matrix.android.sdk.internal.worker.SessionWorkerParams import org.matrix.android.sdk.internal.worker.WorkerParamsFactory import org.matrix.android.sdk.internal.worker.getSessionComponent @@ -52,6 +53,8 @@ internal class SendVerificationMessageWorker(context: Context, @Inject lateinit var cryptoService: CryptoService + @Inject lateinit var cancelSendTracker: CancelSendTracker + override suspend fun doWork(): Result { val errorOutputData = Data.Builder().putBoolean(OUTPUT_KEY_FAILED, true).build() val params = WorkerParamsFactory.fromData(inputData) @@ -63,7 +66,17 @@ internal class SendVerificationMessageWorker(context: Context, Timber.e("Unknown Session, cannot send message, sessionId: ${params.sessionId}") } sessionComponent.inject(this) + val localId = params.event.eventId ?: "" + + if (cancelSendTracker.isCancelRequestedFor(localId, params.event.roomId)) { + return Result.success() + .also { + cancelSendTracker.markCancelled(localId, params.event.roomId ?: "") + Timber.e("## SendEvent: Event sending has been cancelled $localId") + } + } + return try { val eventId = sendVerificationMessageTask.execute( SendVerificationMessageTask.Params( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportRoomMessage.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportRoomMessage.kt index 69f00ce359..25c0b07a3c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportRoomMessage.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportRoomMessage.kt @@ -115,20 +115,31 @@ internal class VerificationTransportRoomMessage( val observer = object : Observer> { override fun onChanged(workInfoList: List?) { workInfoList - ?.filter { it.state == WorkInfo.State.SUCCEEDED } ?.firstOrNull { it.id == enqueueInfo.second } ?.let { wInfo -> - if (SendVerificationMessageWorker.hasFailed(wInfo.outputData)) { - Timber.e("## SAS verification [${tx?.transactionId}] failed to send verification message in state : ${tx?.state}") - tx?.cancel(onErrorReason) - } else { - if (onDone != null) { - onDone() - } else { - tx?.state = nextState + + when (wInfo.state) { + WorkInfo.State.FAILED -> { + tx?.cancel(onErrorReason) + workLiveData.removeObserver(this) + } + WorkInfo.State.SUCCEEDED -> { + if (SendVerificationMessageWorker.hasFailed(wInfo.outputData)) { + Timber.e("## SAS verification [${tx?.transactionId}] failed to send verification message in state : ${tx?.state}") + tx?.cancel(onErrorReason) + } else { + if (onDone != null) { + onDone() + } else { + tx?.state = nextState + } + } + workLiveData.removeObserver(this) + } + else -> { + // nop } } - workLiveData.removeObserver(this) } } } @@ -184,7 +195,7 @@ internal class VerificationTransportRoomMessage( .build() workManagerProvider.workManager - .beginUniqueWork("${roomId}_VerificationWork", ExistingWorkPolicy.APPEND, workRequest) + .beginUniqueWork("${roomId}_VerificationWork", ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest) .enqueue() // I cannot just listen to the given work request, because when used in a uniqueWork, @@ -280,7 +291,7 @@ internal class VerificationTransportRoomMessage( .setBackoffCriteria(BackoffPolicy.LINEAR, 2_000L, TimeUnit.MILLISECONDS) .build() return workManagerProvider.workManager - .beginUniqueWork(uniqueQueueName(), ExistingWorkPolicy.APPEND, workRequest) + .beginUniqueWork(uniqueQueueName(), ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest) .enqueue() to workRequest.id } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/parsing/CheckNumberType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/parsing/CheckNumberType.kt index d4ceca2006..40ba02ef6d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/parsing/CheckNumberType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/parsing/CheckNumberType.kt @@ -49,7 +49,7 @@ interface CheckNumberType { val numberAsString = reader.nextString() val decimal = BigDecimal(numberAsString) if (decimal.scale() <= 0) { - decimal.intValueExact() + decimal.longValueExact() } else { decimal.toDouble() }