Fix issue with SessionId for the worker

Also rename some variables
This commit is contained in:
Benoit Marty 2020-01-14 13:51:55 +01:00 committed by Valere
parent a95410c118
commit 689fd1ea90
6 changed files with 49 additions and 45 deletions

View File

@ -288,31 +288,27 @@ internal class DefaultSasVerificationService @Inject constructor(
if (startReq?.isValid()?.not() == true) {
Timber.e("## received invalid verification request")
if (startReq.transactionID != null) {
sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", event.roomId
?: "", null).cancelTransaction(
startReq.transactionID ?: "",
otherUserId!!,
startReq.fromDevice ?: event.getSenderKey()!!,
CancelCode.UnknownMethod
)
sasTransportRoomMessageFactory.createTransport(event.roomId ?: "", null)
.cancelTransaction(
startReq.transactionID ?: "",
otherUserId!!,
startReq.fromDevice ?: event.getSenderKey()!!,
CancelCode.UnknownMethod
)
}
return
}
handleStart(otherUserId, startReq as VerificationInfoStart) {
it.transport = sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", event.roomId
?: "", it)
it.transport = sasTransportRoomMessageFactory.createTransport(event.roomId ?: "", it)
}?.let {
sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", event.roomId
?: "", null).cancelTransaction(
startReq.transactionID ?: "",
otherUserId!!,
startReq.fromDevice ?: event.getSenderKey()!!,
it
)
sasTransportRoomMessageFactory.createTransport(event.roomId ?: "", null)
.cancelTransaction(
startReq.transactionID ?: "",
otherUserId!!,
startReq.fromDevice ?: event.getSenderKey()!!,
it
)
}
}
@ -729,8 +725,7 @@ internal class DefaultSasVerificationService @Inject constructor(
pendingRequests[userId] = it
}
val transport = sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", roomId, null)
val transport = sasTransportRoomMessageFactory.createTransport(roomId, null)
// Cancel existing pending requests?
requestsForUser.forEach { existingRequest ->
@ -767,8 +762,8 @@ internal class DefaultSasVerificationService @Inject constructor(
}
override fun declineVerificationRequestInDMs(otherUserId: String, otherDeviceId: String, transactionId: String, roomId: String) {
sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", roomId, null).cancelTransaction(transactionId, otherUserId, otherDeviceId, CancelCode.User)
sasTransportRoomMessageFactory.createTransport(roomId, null)
.cancelTransaction(transactionId, otherUserId, otherDeviceId, CancelCode.User)
getExistingVerificationRequest(otherUserId, transactionId)?.let {
updatePendingRequest(it.copy(
@ -805,8 +800,7 @@ internal class DefaultSasVerificationService @Inject constructor(
transactionId,
otherUserId,
otherDeviceId)
tx.transport = sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", roomId, tx)
tx.transport = sasTransportRoomMessageFactory.createTransport(roomId, tx)
addTransaction(tx)
tx.start()
@ -822,8 +816,7 @@ internal class DefaultSasVerificationService @Inject constructor(
val existingRequest = getExistingVerificationRequest(otherUserId, transactionId)
if (existingRequest != null) {
// we need to send a ready event, with matching methods
val transport = sasTransportRoomMessageFactory.createTransport(credentials.userId, credentials.deviceId
?: "", roomId, null)
val transport = sasTransportRoomMessageFactory.createTransport(roomId, null)
val methods = existingRequest.requestInfo?.methods?.intersect(listOf(KeyVerificationStart.VERIF_METHOD_SAS))?.toList()
if (methods.isNullOrEmpty()) {
Timber.i("Cannot ready this request, no common methods found txId:$transactionId")

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, otherUserId: String, otherUserDevice: String, code: CancelCode)
fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDeviceId: String, code: CancelCode)
fun done(transactionId: String)
/**

View File

@ -26,6 +26,9 @@ import im.vector.matrix.android.api.session.events.model.*
import im.vector.matrix.android.api.session.room.model.message.*
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationStart
import im.vector.matrix.android.internal.di.DeviceId
import im.vector.matrix.android.internal.di.SessionId
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
import im.vector.matrix.android.internal.worker.WorkManagerUtil
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
@ -39,8 +42,9 @@ import javax.inject.Inject
internal class SasTransportRoomMessage(
private val context: Context,
private val sessionId: String,
private val userId: String,
private val userDevice: String,
private val userDeviceId: String?,
private val roomId: String,
private val monarchy: Monarchy,
private val localEchoEventFactory: LocalEchoEventFactory,
@ -61,7 +65,7 @@ internal class SasTransportRoomMessage(
)
val workerParams = WorkerParamsFactory.toData(SendVerificationMessageWorker.Params(
userId = userId,
sessionId = sessionId,
event = event
))
val enqueueInfo = enqueueSendWork(workerParams)
@ -113,11 +117,13 @@ internal class SasTransportRoomMessage(
}
}
override fun sendVerificationRequest(localID: String, otherUserId: String, roomId: String,
override fun sendVerificationRequest(localID: String,
otherUserId: String,
roomId: String,
callback: (String?, MessageVerificationRequestContent?) -> Unit) {
val info = MessageVerificationRequestContent(
body = context.getString(R.string.key_verification_request_fallback_message, userId),
fromDevice = userDevice,
fromDevice = userDeviceId ?: "",
toUserId = otherUserId,
methods = listOf(KeyVerificationStart.VERIF_METHOD_SAS)
)
@ -131,7 +137,7 @@ internal class SasTransportRoomMessage(
)
val workerParams = WorkerParamsFactory.toData(SendVerificationMessageWorker.Params(
userId = userId,
sessionId = sessionId,
event = event
))
@ -174,7 +180,7 @@ internal class SasTransportRoomMessage(
}
}
override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDevice: String, code: CancelCode) {
override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDeviceId: String, code: CancelCode) {
Timber.d("## SAS canceling transaction $transactionId for reason $code")
val event = createEventAndLocalEcho(
type = EventType.KEY_VERIFICATION_CANCEL,
@ -182,7 +188,7 @@ internal class SasTransportRoomMessage(
content = MessageVerificationCancelContent.create(transactionId, code).toContent()
)
val workerParams = WorkerParamsFactory.toData(SendVerificationMessageWorker.Params(
userId = this.userId,
sessionId = sessionId,
event = event
))
enqueueSendWork(workerParams)
@ -200,7 +206,7 @@ internal class SasTransportRoomMessage(
).toContent()
)
val workerParams = WorkerParamsFactory.toData(SendVerificationMessageWorker.Params(
userId = userId,
sessionId = sessionId,
event = event
))
enqueueSendWork(workerParams)
@ -286,10 +292,15 @@ internal class SasTransportRoomMessage(
internal class SasTransportRoomMessageFactory @Inject constructor(
private val context: Context,
private val monarchy: Monarchy,
@SessionId
private val sessionId: String,
@UserId
private val userId: String,
@DeviceId
private val deviceId: String?,
private val localEchoEventFactory: LocalEchoEventFactory) {
fun createTransport(userId: String, userDevice: String, roomId: String, tx: SASVerificationTransaction?
): SasTransportRoomMessage {
return SasTransportRoomMessage(context, userId, userDevice, roomId, monarchy, localEchoEventFactory, tx)
fun createTransport(roomId: String, tx: SASVerificationTransaction?): SasTransportRoomMessage {
return SasTransportRoomMessage(context, sessionId, userId, deviceId, roomId, monarchy, localEchoEventFactory, tx)
}
}

View File

@ -78,11 +78,11 @@ internal class SasTransportToDevice(
// To device do not do anything here
}
override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDevice: String, code: CancelCode) {
override fun cancelTransaction(transactionId: String, otherUserId: String, otherUserDeviceId: String, code: CancelCode) {
Timber.d("## SAS canceling transaction $transactionId for reason $code")
val cancelMessage = KeyVerificationCancel.create(transactionId, code)
val contentMap = MXUsersDevicesMap<Any>()
contentMap.setObject(otherUserId, otherUserDevice, cancelMessage)
contentMap.setObject(otherUserId, otherUserDeviceId, cancelMessage)
sendToDeviceTask
.configureWith(SendToDeviceTask.Params(EventType.KEY_VERIFICATION_CANCEL, contentMap, transactionId)) {
this.callback = object : MatrixCallback<Unit> {

View File

@ -34,7 +34,7 @@ internal class SendVerificationMessageWorker constructor(context: Context, param
@JsonClass(generateAdapter = true)
internal data class Params(
val userId: String,
val sessionId: String,
val event: Event
)
@ -49,10 +49,10 @@ internal class SendVerificationMessageWorker constructor(context: Context, param
val params = WorkerParamsFactory.fromData<Params>(inputData)
?: return Result.success(errorOutputData)
val sessionComponent = getSessionComponent(params.userId)
val sessionComponent = getSessionComponent(params.sessionId)
?: return Result.success(errorOutputData).also {
// TODO, can this happen? should I update local echo?
Timber.e("Unknown Session, cannot send message, userId:${params.userId}")
Timber.e("Unknown Session, cannot send message, sessionId: ${params.sessionId}")
}
sessionComponent.inject(this)
val localId = params.event.eventId ?: ""

View File

@ -26,7 +26,7 @@ import javax.inject.Qualifier
internal annotation class UserId
/**
* Used to inject the userId
* Used to inject the deviceId
*/
@Qualifier
@Retention(AnnotationRetention.RUNTIME)