crypto: Add a state for when we confirmed the QR code

This commit is contained in:
Damir Jelić 2021-06-28 09:57:32 +02:00
parent 4473af85b1
commit d21137d910
5 changed files with 32 additions and 28 deletions

View file

@ -174,14 +174,15 @@ internal class QrCodeVerification(
get() { get() {
refreshData() refreshData()
val state = when { val state = when {
this.inner.isDone -> VerificationTxState.Verified this.inner.isDone -> VerificationTxState.Verified
this.inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm
this.inner.otherSideScanned -> VerificationTxState.QrScannedByOther this.inner.otherSideScanned -> VerificationTxState.QrScannedByOther
this.inner.isCancelled -> { this.inner.isCancelled -> {
val cancelCode = safeValueOf(this.inner.cancelCode) val cancelCode = safeValueOf(this.inner.cancelCode)
val byMe = this.inner.cancelledByUs ?: false val byMe = this.inner.cancelledByUs ?: false
VerificationTxState.Cancelled(cancelCode, byMe) VerificationTxState.Cancelled(cancelCode, byMe)
} }
else -> { else -> {
VerificationTxState.None VerificationTxState.None
} }
} }

View file

@ -116,26 +116,25 @@ constructor(
// } // }
} }
suspend fun onEvent(event: Event) { fun onEvent(event: Event) = when (event.getClearType()) {
when (event.getClearType()) { EventType.KEY_VERIFICATION_START -> onStart(event)
EventType.KEY_VERIFICATION_START -> {} EventType.KEY_VERIFICATION_CANCEL -> {}
EventType.KEY_VERIFICATION_CANCEL -> {} EventType.KEY_VERIFICATION_ACCEPT -> {}
EventType.KEY_VERIFICATION_ACCEPT -> {} EventType.KEY_VERIFICATION_KEY -> onKey(event)
EventType.KEY_VERIFICATION_KEY -> { EventType.KEY_VERIFICATION_MAC -> {}
onKeyReceived(event) EventType.KEY_VERIFICATION_READY -> {}
} EventType.KEY_VERIFICATION_DONE -> onDone(event)
EventType.KEY_VERIFICATION_MAC -> {} MessageType.MSGTYPE_VERIFICATION_REQUEST -> onRequest(event)
EventType.KEY_VERIFICATION_READY -> {} else -> {}
EventType.KEY_VERIFICATION_DONE -> { }
onDone(event)
} private fun onStart(event: Event) {
MessageType.MSGTYPE_VERIFICATION_REQUEST -> { val content = event.getClearContent().toModel<KeyVerificationStart>() ?: return
onRequestReceived(event) val flowId = content.transactionId ?: return
} val sender = event.senderId ?: return
else -> {
// ignore val verification = this.getExistingTransaction(sender, flowId) ?: return
} dispatchTxUpdated(verification)
}
} }
private fun onDone(event: Event) { private fun onDone(event: Event) {
@ -146,7 +145,8 @@ constructor(
val verification = this.getExistingTransaction(sender, flowId) ?: return val verification = this.getExistingTransaction(sender, flowId) ?: return
dispatchTxUpdated(verification) dispatchTxUpdated(verification)
} }
private fun onKeyReceived(event: Event) {
private fun onKey(event: Event) {
val content = event.getClearContent().toModel<KeyVerificationKey>() ?: return val content = event.getClearContent().toModel<KeyVerificationKey>() ?: return
val flowId = content.transactionId ?: return val flowId = content.transactionId ?: return
val sender = event.senderId ?: return val sender = event.senderId ?: return
@ -155,7 +155,7 @@ constructor(
dispatchTxUpdated(verification) dispatchTxUpdated(verification)
} }
private fun onRequestReceived(event: Event) { private fun onRequest(event: Event) {
val content = event.getClearContent().toModel<KeyVerificationRequest>() ?: return val content = event.getClearContent().toModel<KeyVerificationRequest>() ?: return
val flowId = content.transactionId val flowId = content.transactionId
val sender = event.senderId ?: return val sender = event.senderId ?: return

View file

@ -25,11 +25,11 @@ features = ["lax_deserialize"]
[dependencies.matrix-sdk-common] [dependencies.matrix-sdk-common]
git = "https://github.com/matrix-org/matrix-rust-sdk/" git = "https://github.com/matrix-org/matrix-rust-sdk/"
rev = "b62f725bead1f44b2038784e5321909f71a4af4a" rev = "3bd43a16086415c17faa969432f18d9ed9e9c272"
[dependencies.matrix-sdk-crypto] [dependencies.matrix-sdk-crypto]
git = "https://github.com/matrix-org/matrix-rust-sdk/" git = "https://github.com/matrix-org/matrix-rust-sdk/"
rev = "b62f725bead1f44b2038784e5321909f71a4af4a" rev = "3bd43a16086415c17faa969432f18d9ed9e9c272"
features = ["sled_cryptostore"] features = ["sled_cryptostore"]
[dependencies.tokio] [dependencies.tokio]

View file

@ -78,6 +78,7 @@ pub struct QrCode {
pub is_done: bool, pub is_done: bool,
pub we_started: bool, pub we_started: bool,
pub other_side_scanned: bool, pub other_side_scanned: bool,
pub has_been_confirmed: bool,
pub cancel_code: Option<String>, pub cancel_code: Option<String>,
pub cancelled_by_us: Option<bool>, pub cancelled_by_us: Option<bool>,
} }
@ -92,7 +93,8 @@ impl From<InnerQr> for QrCode {
cancel_code: qr.cancel_code().map(|c| c.to_string()), cancel_code: qr.cancel_code().map(|c| c.to_string()),
cancelled_by_us: qr.cancelled_by_us(), cancelled_by_us: qr.cancelled_by_us(),
we_started: qr.we_started(), we_started: qr.we_started(),
other_side_scanned: qr.is_scanned(), other_side_scanned: qr.has_been_scanned(),
has_been_confirmed: qr.has_been_confirmed(),
other_device_id: qr.other_device_id().to_string(), other_device_id: qr.other_device_id().to_string(),
room_id: qr.room_id().map(|r| r.to_string()), room_id: qr.room_id().map(|r| r.to_string()),
} }

View file

@ -93,6 +93,7 @@ dictionary QrCode {
string? cancel_code; string? cancel_code;
string? room_id; string? room_id;
boolean we_started; boolean we_started;
boolean has_been_confirmed;
boolean? cancelled_by_us; boolean? cancelled_by_us;
boolean is_done; boolean is_done;
boolean is_cancelled; boolean is_cancelled;