Also cancel pending request on back

This commit is contained in:
Valere 2020-03-24 10:06:15 +01:00
parent 3b62402cfe
commit fcd290410e
3 changed files with 18 additions and 0 deletions

View file

@ -60,6 +60,8 @@ interface VerificationService {
roomId: String,
localId: String? = LocalEcho.createLocalEchoId()): PendingVerificationRequest
fun cancelVerificationRequest(request: PendingVerificationRequest)
/**
* Request a key verification from another user using toDevice events.
*/

View file

@ -1102,6 +1102,18 @@ internal class DefaultVerificationService @Inject constructor(
return verificationRequest
}
override fun cancelVerificationRequest(request: PendingVerificationRequest) {
if (request.roomId != null) {
val transport = verificationTransportRoomMessageFactory.createTransport(request.roomId, null)
transport.cancelTransaction(request.transactionId ?: "", request.otherUserId, null, CancelCode.User)
} else {
val transport = verificationTransportToDeviceFactory.createTransport(null)
request.targetDevices?.forEach { deviceId ->
transport.cancelTransaction(request.transactionId ?: "", request.otherUserId, deviceId, CancelCode.User)
}
}
}
override fun requestKeyVerification(methods: List<VerificationMethod>, otherUserId: String, otherDevices: List<String>?): PendingVerificationRequest {
// TODO refactor this with the DM one
Timber.i("## Requesting verification to user: $otherUserId with device list $otherDevices")

View file

@ -149,6 +149,10 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
}
fun confirmCancel() = withState { state ->
session.cryptoService()
.verificationService().getExistingVerificationRequest(state.otherUserMxItem?.id ?: "", state.transactionId)?.let {
session.cryptoService().verificationService().cancelVerificationRequest(it)
}
session.cryptoService()
.verificationService()
.getExistingTransaction(state.otherUserMxItem?.id ?: "", state.transactionId ?: "")