mirror of
https://github.com/element-hq/element-android
synced 2024-12-21 00:42:04 +03:00
crypto: Allow cancelling of SAS transactions
This commit is contained in:
parent
f854e9cf1c
commit
f95c4ae088
2 changed files with 39 additions and 39 deletions
|
@ -112,7 +112,7 @@ private fun toCryptoDeviceInfo(device: Device): CryptoDeviceInfo {
|
|||
// Kotlin side care about signatures?
|
||||
mapOf(),
|
||||
UnsignedDeviceInfo(device.displayName),
|
||||
DeviceTrustLevel(crossSigningVerified = device.verified, locallyVerified = device.locallyVerified),
|
||||
DeviceTrustLevel(crossSigningVerified = device.crossSigningTrusted, locallyVerified = device.locallyTrusted),
|
||||
device.isBlocked,
|
||||
// TODO
|
||||
null)
|
||||
|
|
|
@ -68,7 +68,7 @@ internal class SasVerification(
|
|||
|
||||
override val isIncoming: Boolean
|
||||
get() {
|
||||
return false
|
||||
return !this.inner.weStarted
|
||||
}
|
||||
|
||||
override var otherDeviceId: String?
|
||||
|
@ -113,19 +113,19 @@ internal class SasVerification(
|
|||
}
|
||||
|
||||
override fun cancel() {
|
||||
TODO()
|
||||
this.cancelHelper(CancelCode.User)
|
||||
}
|
||||
|
||||
override fun cancel(code: CancelCode) {
|
||||
TODO()
|
||||
this.cancelHelper(code)
|
||||
}
|
||||
|
||||
override fun shortCodeDoesNotMatch() {
|
||||
TODO()
|
||||
this.cancelHelper(CancelCode.MismatchedSas)
|
||||
}
|
||||
|
||||
override fun isToDeviceTransport(): Boolean {
|
||||
return false
|
||||
return this.inner.roomId == null
|
||||
}
|
||||
|
||||
override fun supportsDecimal(): Boolean {
|
||||
|
@ -142,41 +142,23 @@ internal class SasVerification(
|
|||
}
|
||||
|
||||
override fun userHasVerifiedShortCode() {
|
||||
runBlocking {
|
||||
when (val request = confirm()) {
|
||||
val request = runBlocking { confirm() } ?: return
|
||||
sendRequest(request)
|
||||
}
|
||||
|
||||
suspend fun accept() {
|
||||
val request = this.machine.acceptSasVerification(this.inner.otherUserId, inner.flowId)
|
||||
|
||||
if (request != null) {
|
||||
when (request) {
|
||||
is OutgoingVerificationRequest.ToDevice -> {
|
||||
sender.sendToDevice(request.eventType, request.body)
|
||||
}
|
||||
is OutgoingVerificationRequest.InRoom -> TODO()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
refreshData()
|
||||
dispatchTxUpdated()
|
||||
}
|
||||
refreshData()
|
||||
dispatchTxUpdated()
|
||||
}
|
||||
|
||||
fun isCanceled(): Boolean {
|
||||
refreshData()
|
||||
return this.inner.isCancelled
|
||||
}
|
||||
|
||||
fun isDone(): Boolean {
|
||||
refreshData()
|
||||
return this.inner.isDone
|
||||
}
|
||||
|
||||
fun timedOut(): Boolean {
|
||||
refreshData()
|
||||
return this.inner.timedOut
|
||||
}
|
||||
|
||||
fun canBePresented(): Boolean {
|
||||
refreshData()
|
||||
return this.inner.canBePresented
|
||||
}
|
||||
|
||||
fun accept(): OutgoingVerificationRequest? {
|
||||
return this.machine.acceptSasVerification(this.inner.otherUserId, inner.flowId)
|
||||
}
|
||||
|
||||
@Throws(CryptoStoreErrorException::class)
|
||||
|
@ -185,8 +167,12 @@ internal class SasVerification(
|
|||
machine.confirmVerification(inner.otherUserId, inner.flowId)
|
||||
}
|
||||
|
||||
fun cancelHelper(): OutgoingVerificationRequest? {
|
||||
return this.machine.cancelVerification(this.inner.otherUserId, inner.flowId)
|
||||
fun cancelHelper(code: CancelCode) {
|
||||
val request = this.machine.cancelVerification(this.inner.otherUserId, inner.flowId, code.value)
|
||||
|
||||
if (request != null) {
|
||||
sendRequest(request)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEmojiCodeRepresentation(): List<EmojiRepresentation> {
|
||||
|
@ -200,4 +186,18 @@ internal class SasVerification(
|
|||
|
||||
return decimals?.joinToString(" ") ?: ""
|
||||
}
|
||||
|
||||
fun sendRequest(request: OutgoingVerificationRequest) {
|
||||
runBlocking {
|
||||
when (request) {
|
||||
is OutgoingVerificationRequest.ToDevice -> {
|
||||
sender.sendToDevice(request.eventType, request.body)
|
||||
}
|
||||
is OutgoingVerificationRequest.InRoom -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
refreshData()
|
||||
dispatchTxUpdated()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue