Fix / Cancel messages was not sent

This commit is contained in:
Valere 2020-01-02 12:51:12 +01:00
parent f541661059
commit b26318f15c
4 changed files with 13 additions and 8 deletions

View file

@ -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)
/**

View file

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

View file

@ -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<Any>()
contentMap.setObject(userId, userDevice, cancelMessage)
contentMap.setObject(otherUserId, otherUserDevice, cancelMessage)
sendToDeviceTask
.configureWith(SendToDeviceTask.Params(EventType.KEY_VERIFICATION_CANCEL, contentMap, transactionId)) {
this.callback = object : MatrixCallback<Unit> {

View file

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