mirror of
https://github.com/element-hq/element-android
synced 2024-12-19 07:45:17 +03:00
crypto: Add a state for when we confirmed the QR code
This commit is contained in:
parent
4473af85b1
commit
d21137d910
5 changed files with 32 additions and 28 deletions
|
@ -175,6 +175,7 @@ internal class QrCodeVerification(
|
|||
refreshData()
|
||||
val state = when {
|
||||
this.inner.isDone -> VerificationTxState.Verified
|
||||
this.inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm
|
||||
this.inner.otherSideScanned -> VerificationTxState.QrScannedByOther
|
||||
this.inner.isCancelled -> {
|
||||
val cancelCode = safeValueOf(this.inner.cancelCode)
|
||||
|
|
|
@ -116,26 +116,25 @@ constructor(
|
|||
// }
|
||||
}
|
||||
|
||||
suspend fun onEvent(event: Event) {
|
||||
when (event.getClearType()) {
|
||||
EventType.KEY_VERIFICATION_START -> {}
|
||||
fun onEvent(event: Event) = when (event.getClearType()) {
|
||||
EventType.KEY_VERIFICATION_START -> onStart(event)
|
||||
EventType.KEY_VERIFICATION_CANCEL -> {}
|
||||
EventType.KEY_VERIFICATION_ACCEPT -> {}
|
||||
EventType.KEY_VERIFICATION_KEY -> {
|
||||
onKeyReceived(event)
|
||||
}
|
||||
EventType.KEY_VERIFICATION_KEY -> onKey(event)
|
||||
EventType.KEY_VERIFICATION_MAC -> {}
|
||||
EventType.KEY_VERIFICATION_READY -> {}
|
||||
EventType.KEY_VERIFICATION_DONE -> {
|
||||
onDone(event)
|
||||
}
|
||||
MessageType.MSGTYPE_VERIFICATION_REQUEST -> {
|
||||
onRequestReceived(event)
|
||||
}
|
||||
else -> {
|
||||
// ignore
|
||||
}
|
||||
EventType.KEY_VERIFICATION_DONE -> onDone(event)
|
||||
MessageType.MSGTYPE_VERIFICATION_REQUEST -> onRequest(event)
|
||||
else -> {}
|
||||
}
|
||||
|
||||
private fun onStart(event: Event) {
|
||||
val content = event.getClearContent().toModel<KeyVerificationStart>() ?: return
|
||||
val flowId = content.transactionId ?: return
|
||||
val sender = event.senderId ?: return
|
||||
|
||||
val verification = this.getExistingTransaction(sender, flowId) ?: return
|
||||
dispatchTxUpdated(verification)
|
||||
}
|
||||
|
||||
private fun onDone(event: Event) {
|
||||
|
@ -146,7 +145,8 @@ constructor(
|
|||
val verification = this.getExistingTransaction(sender, flowId) ?: return
|
||||
dispatchTxUpdated(verification)
|
||||
}
|
||||
private fun onKeyReceived(event: Event) {
|
||||
|
||||
private fun onKey(event: Event) {
|
||||
val content = event.getClearContent().toModel<KeyVerificationKey>() ?: return
|
||||
val flowId = content.transactionId ?: return
|
||||
val sender = event.senderId ?: return
|
||||
|
@ -155,7 +155,7 @@ constructor(
|
|||
dispatchTxUpdated(verification)
|
||||
}
|
||||
|
||||
private fun onRequestReceived(event: Event) {
|
||||
private fun onRequest(event: Event) {
|
||||
val content = event.getClearContent().toModel<KeyVerificationRequest>() ?: return
|
||||
val flowId = content.transactionId
|
||||
val sender = event.senderId ?: return
|
||||
|
|
|
@ -25,11 +25,11 @@ features = ["lax_deserialize"]
|
|||
|
||||
[dependencies.matrix-sdk-common]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "b62f725bead1f44b2038784e5321909f71a4af4a"
|
||||
rev = "3bd43a16086415c17faa969432f18d9ed9e9c272"
|
||||
|
||||
[dependencies.matrix-sdk-crypto]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "b62f725bead1f44b2038784e5321909f71a4af4a"
|
||||
rev = "3bd43a16086415c17faa969432f18d9ed9e9c272"
|
||||
features = ["sled_cryptostore"]
|
||||
|
||||
[dependencies.tokio]
|
||||
|
|
|
@ -78,6 +78,7 @@ pub struct QrCode {
|
|||
pub is_done: bool,
|
||||
pub we_started: bool,
|
||||
pub other_side_scanned: bool,
|
||||
pub has_been_confirmed: bool,
|
||||
pub cancel_code: Option<String>,
|
||||
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()),
|
||||
cancelled_by_us: qr.cancelled_by_us(),
|
||||
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(),
|
||||
room_id: qr.room_id().map(|r| r.to_string()),
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ dictionary QrCode {
|
|||
string? cancel_code;
|
||||
string? room_id;
|
||||
boolean we_started;
|
||||
boolean has_been_confirmed;
|
||||
boolean? cancelled_by_us;
|
||||
boolean is_done;
|
||||
boolean is_cancelled;
|
||||
|
|
Loading…
Reference in a new issue