mirror of
https://github.com/element-hq/element-android
synced 2024-12-21 08:54:12 +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?
|
// Kotlin side care about signatures?
|
||||||
mapOf(),
|
mapOf(),
|
||||||
UnsignedDeviceInfo(device.displayName),
|
UnsignedDeviceInfo(device.displayName),
|
||||||
DeviceTrustLevel(crossSigningVerified = device.verified, locallyVerified = device.locallyVerified),
|
DeviceTrustLevel(crossSigningVerified = device.crossSigningTrusted, locallyVerified = device.locallyTrusted),
|
||||||
device.isBlocked,
|
device.isBlocked,
|
||||||
// TODO
|
// TODO
|
||||||
null)
|
null)
|
||||||
|
|
|
@ -68,7 +68,7 @@ internal class SasVerification(
|
||||||
|
|
||||||
override val isIncoming: Boolean
|
override val isIncoming: Boolean
|
||||||
get() {
|
get() {
|
||||||
return false
|
return !this.inner.weStarted
|
||||||
}
|
}
|
||||||
|
|
||||||
override var otherDeviceId: String?
|
override var otherDeviceId: String?
|
||||||
|
@ -113,19 +113,19 @@ internal class SasVerification(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
TODO()
|
this.cancelHelper(CancelCode.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancel(code: CancelCode) {
|
override fun cancel(code: CancelCode) {
|
||||||
TODO()
|
this.cancelHelper(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shortCodeDoesNotMatch() {
|
override fun shortCodeDoesNotMatch() {
|
||||||
TODO()
|
this.cancelHelper(CancelCode.MismatchedSas)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isToDeviceTransport(): Boolean {
|
override fun isToDeviceTransport(): Boolean {
|
||||||
return false
|
return this.inner.roomId == null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun supportsDecimal(): Boolean {
|
override fun supportsDecimal(): Boolean {
|
||||||
|
@ -142,41 +142,23 @@ internal class SasVerification(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun userHasVerifiedShortCode() {
|
override fun userHasVerifiedShortCode() {
|
||||||
runBlocking {
|
val request = runBlocking { confirm() } ?: return
|
||||||
when (val request = confirm()) {
|
sendRequest(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun accept() {
|
||||||
|
val request = this.machine.acceptSasVerification(this.inner.otherUserId, inner.flowId)
|
||||||
|
|
||||||
|
if (request != null) {
|
||||||
|
when (request) {
|
||||||
is OutgoingVerificationRequest.ToDevice -> {
|
is OutgoingVerificationRequest.ToDevice -> {
|
||||||
sender.sendToDevice(request.eventType, request.body)
|
sender.sendToDevice(request.eventType, request.body)
|
||||||
}
|
}
|
||||||
|
is OutgoingVerificationRequest.InRoom -> TODO()
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
refreshData()
|
refreshData()
|
||||||
dispatchTxUpdated()
|
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)
|
@Throws(CryptoStoreErrorException::class)
|
||||||
|
@ -185,8 +167,12 @@ internal class SasVerification(
|
||||||
machine.confirmVerification(inner.otherUserId, inner.flowId)
|
machine.confirmVerification(inner.otherUserId, inner.flowId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelHelper(): OutgoingVerificationRequest? {
|
fun cancelHelper(code: CancelCode) {
|
||||||
return this.machine.cancelVerification(this.inner.otherUserId, inner.flowId)
|
val request = this.machine.cancelVerification(this.inner.otherUserId, inner.flowId, code.value)
|
||||||
|
|
||||||
|
if (request != null) {
|
||||||
|
sendRequest(request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEmojiCodeRepresentation(): List<EmojiRepresentation> {
|
override fun getEmojiCodeRepresentation(): List<EmojiRepresentation> {
|
||||||
|
@ -200,4 +186,18 @@ internal class SasVerification(
|
||||||
|
|
||||||
return decimals?.joinToString(" ") ?: ""
|
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