Fix / Verification in DM not working

CheckNumberType crashing on timestamp number
This commit is contained in:
Valere 2020-09-18 18:00:49 +02:00
parent d29d1ead9b
commit 28d37f0106
4 changed files with 38 additions and 14 deletions

View File

@ -8,7 +8,7 @@ Improvements 🙌:
-
Bugfix 🐛:
-
- User Verification in DM not working
Translations 🗣:
-

View File

@ -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<Params>(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(

View File

@ -115,9 +115,15 @@ internal class VerificationTransportRoomMessage(
val observer = object : Observer<List<WorkInfo>> {
override fun onChanged(workInfoList: List<WorkInfo>?) {
workInfoList
?.filter { it.state == WorkInfo.State.SUCCEEDED }
?.firstOrNull { it.id == enqueueInfo.second }
?.let { wInfo ->
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)
@ -130,6 +136,11 @@ internal class VerificationTransportRoomMessage(
}
workLiveData.removeObserver(this)
}
else -> {
// nop
}
}
}
}
}
@ -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
}

View File

@ -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()
}