refactor: replace inviter_progress macro with a function

This commit is contained in:
link2xt
2023-11-08 01:59:49 +00:00
parent 543864f0f5
commit 0a48a2effa

View File

@@ -36,17 +36,15 @@ use crate::token::Namespace;
/// Set of characters to percent-encode in email addresses and names. /// Set of characters to percent-encode in email addresses and names.
pub const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.'); pub const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.');
macro_rules! inviter_progress { fn inviter_progress(context: &Context, contact_id: ContactId, progress: usize) {
($context:tt, $contact_id:expr, $progress:expr) => { debug_assert!(
assert!( progress <= 1000,
$progress >= 0 && $progress <= 1000, "value in range 0..1000 expected with: 0=error, 1..999=progress, 1000=success"
"value in range 0..1000 expected with: 0=error, 1..999=progress, 1000=success" );
); context.emit_event(EventType::SecurejoinInviterProgress {
$context.emit_event($crate::events::EventType::SecurejoinInviterProgress { contact_id,
contact_id: $contact_id, progress,
progress: $progress, });
});
};
} }
/// Generates a Secure Join QR code. /// Generates a Secure Join QR code.
@@ -318,7 +316,7 @@ pub(crate) async fn handle_securejoin_handshake(
} }
info!(context, "Secure-join requested.",); info!(context, "Secure-join requested.",);
inviter_progress!(context, contact_id, 300); inviter_progress(context, contact_id, 300);
// for setup-contact, make Alice's one-to-one chat with Bob visible // for setup-contact, make Alice's one-to-one chat with Bob visible
// (secure-join-information are shown in the group chat) // (secure-join-information are shown in the group chat)
@@ -430,7 +428,7 @@ pub(crate) async fn handle_securejoin_handshake(
Contact::scaleup_origin_by_id(context, contact_id, Origin::SecurejoinInvited).await?; Contact::scaleup_origin_by_id(context, contact_id, Origin::SecurejoinInvited).await?;
info!(context, "Auth verified.",); info!(context, "Auth verified.",);
context.emit_event(EventType::ContactsChanged(Some(contact_id))); context.emit_event(EventType::ContactsChanged(Some(contact_id)));
inviter_progress!(context, contact_id, 600); inviter_progress(context, contact_id, 600);
if join_vg { if join_vg {
// the vg-member-added message is special: // the vg-member-added message is special:
// this is a normal Chat-Group-Member-Added message // this is a normal Chat-Group-Member-Added message
@@ -450,8 +448,8 @@ pub(crate) async fn handle_securejoin_handshake(
} }
None => bail!("Chat {} not found", &field_grpid), None => bail!("Chat {} not found", &field_grpid),
} }
inviter_progress!(context, contact_id, 800); inviter_progress(context, contact_id, 800);
inviter_progress!(context, contact_id, 1000); inviter_progress(context, contact_id, 1000);
} else { } else {
// Alice -> Bob // Alice -> Bob
secure_connection_established( secure_connection_established(
@@ -469,7 +467,7 @@ pub(crate) async fn handle_securejoin_handshake(
.await .await
.context("failed sending vc-contact-confirm message")?; .context("failed sending vc-contact-confirm message")?;
inviter_progress!(context, contact_id, 1000); inviter_progress(context, contact_id, 1000);
} }
Ok(HandshakeMessage::Ignore) // "Done" would delete the message and break multi-device (the key from Autocrypt-header is needed) Ok(HandshakeMessage::Ignore) // "Done" would delete the message and break multi-device (the key from Autocrypt-header is needed)
} }
@@ -651,10 +649,10 @@ pub(crate) async fn observe_securejoin_on_other_device(
return Ok(HandshakeMessage::Ignore); return Ok(HandshakeMessage::Ignore);
} }
if step.as_str() == "vg-member-added" { if step.as_str() == "vg-member-added" {
inviter_progress!(context, contact_id, 800); inviter_progress(context, contact_id, 800);
} }
if step.as_str() == "vg-member-added" || step.as_str() == "vc-contact-confirm" { if step.as_str() == "vg-member-added" || step.as_str() == "vc-contact-confirm" {
inviter_progress!(context, contact_id, 1000); inviter_progress(context, contact_id, 1000);
} }
if step.as_str() == "vg-request-with-auth" || step.as_str() == "vc-request-with-auth" { if step.as_str() == "vg-request-with-auth" || step.as_str() == "vc-request-with-auth" {
// This actually reflects what happens on the first device (which does the secure // This actually reflects what happens on the first device (which does the secure