Skip to content

Commit fc52c8d

Browse files
committed
Merge remote-tracking branch 'origin/main' into hoc/channels-encryption-only-qrcodes
2 parents 4c068e8 + b9ff40c commit fc52c8d

File tree

6 files changed

+110
-15
lines changed

6 files changed

+110
-15
lines changed

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use deltachat::{Event as CoreEvent, EventType as CoreEventType};
2+
use num_traits::ToPrimitive;
23
use serde::Serialize;
34
use typescript_type_def::TypeDef;
45

@@ -303,6 +304,11 @@ pub enum EventType {
303304
/// ID of the contact that wants to join.
304305
contact_id: u32,
305306

307+
/// The type of the joined chat.
308+
/// This can take the same values
309+
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
310+
chat_type: u32,
311+
306312
/// Progress as:
307313
/// 300=vg-/vc-request received, typically shown as "bob@addr joins".
308314
/// 600=vg-/vc-request-with-auth received and verified, typically shown as "bob@addr verified".
@@ -551,9 +557,11 @@ impl From<CoreEventType> for EventType {
551557
},
552558
CoreEventType::SecurejoinInviterProgress {
553559
contact_id,
560+
chat_type,
554561
progress,
555562
} => SecurejoinInviterProgress {
556563
contact_id: contact_id.to_u32(),
564+
chat_type: chat_type.to_u32().unwrap_or(0),
557565
progress,
558566
},
559567
CoreEventType::SecurejoinJoinerProgress {

src/chat.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ impl Chat {
19831983
}
19841984

19851985
/// Adds missing values to the msg object,
1986-
/// writes the record to the database and returns its msg_id.
1986+
/// writes the record to the database.
19871987
///
19881988
/// If `update_msg_id` is set, that record is reused;
19891989
/// if `update_msg_id` is None, a new record is created.
@@ -1992,7 +1992,7 @@ impl Chat {
19921992
context: &Context,
19931993
msg: &mut Message,
19941994
update_msg_id: Option<MsgId>,
1995-
) -> Result<MsgId> {
1995+
) -> Result<()> {
19961996
let mut to_id = 0;
19971997
let mut location_id = 0;
19981998

@@ -2270,7 +2270,7 @@ impl Chat {
22702270
.await?;
22712271
}
22722272
context.scheduler.interrupt_ephemeral_task().await;
2273-
Ok(msg.id)
2273+
Ok(())
22742274
}
22752275

22762276
/// Sends a `SyncAction` synchronising chat contacts to other devices.
@@ -3006,8 +3006,7 @@ async fn prepare_send_msg(
30063006
if !msg.hidden {
30073007
chat_id.unarchive_if_not_muted(context, msg.state).await?;
30083008
}
3009-
msg.id = chat.prepare_msg_raw(context, msg, update_msg_id).await?;
3010-
msg.chat_id = chat_id;
3009+
chat.prepare_msg_raw(context, msg, update_msg_id).await?;
30113010

30123011
let row_ids = create_send_msg_jobs(context, msg)
30133012
.await
@@ -4561,13 +4560,13 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId)
45614560
msg.state = MessageState::OutPending;
45624561
msg.rfc724_mid = create_outgoing_rfc724_mid();
45634562
msg.timestamp_sort = curr_timestamp;
4564-
let new_msg_id = chat.prepare_msg_raw(context, &mut msg, None).await?;
4563+
chat.prepare_msg_raw(context, &mut msg, None).await?;
45654564

45664565
curr_timestamp += 1;
45674566
if !create_send_msg_jobs(context, &mut msg).await?.is_empty() {
45684567
context.scheduler.interrupt_smtp().await;
45694568
}
4570-
created_msgs.push(new_msg_id);
4569+
created_msgs.push(msg.id);
45714570
}
45724571
for msg_id in created_msgs {
45734572
context.emit_msgs_changed(chat_id, msg_id);

src/chat/chat_tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,30 @@ async fn test_chat_get_encryption_info() -> Result<()> {
34593459
Ok(())
34603460
}
34613461

3462+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3463+
async fn test_out_failed_on_all_keys_missing() -> Result<()> {
3464+
let mut tcm = TestContextManager::new();
3465+
let alice = &tcm.alice().await;
3466+
let bob = &tcm.bob().await;
3467+
let fiona = &tcm.fiona().await;
3468+
3469+
let bob_chat_id = bob
3470+
.create_group_with_members(ProtectionStatus::Unprotected, "", &[alice, fiona])
3471+
.await;
3472+
bob.send_text(bob_chat_id, "Gossiping Fiona's key").await;
3473+
alice
3474+
.recv_msg(&bob.send_text(bob_chat_id, "No key gossip").await)
3475+
.await;
3476+
SystemTime::shift(Duration::from_secs(60));
3477+
remove_contact_from_chat(bob, bob_chat_id, ContactId::SELF).await?;
3478+
let alice_chat_id = alice.recv_msg(&bob.pop_sent_msg().await).await.chat_id;
3479+
alice_chat_id.accept(alice).await?;
3480+
let mut msg = Message::new_text("Hi".to_string());
3481+
send_msg(alice, alice_chat_id, &mut msg).await.ok();
3482+
assert_eq!(msg.id.get_state(alice).await?, MessageState::OutFailed);
3483+
Ok(())
3484+
}
3485+
34623486
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
34633487
async fn test_get_chat_media() -> Result<()> {
34643488
let t = TestContext::new_alice().await;

src/events/payload.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::PathBuf;
55

66
use crate::chat::ChatId;
77
use crate::config::Config;
8+
use crate::constants::Chattype;
89
use crate::contact::ContactId;
910
use crate::ephemeral::Timer as EphemeralTimer;
1011
use crate::message::MsgId;
@@ -272,6 +273,9 @@ pub enum EventType {
272273
/// ID of the contact that wants to join.
273274
contact_id: ContactId,
274275

276+
/// The type of the joined chat.
277+
chat_type: Chattype,
278+
275279
/// Progress as:
276280
/// 300=vg-/vc-request received, typically shown as "bob@addr joins".
277281
/// 600=vg-/vc-request-with-auth received and verified, typically shown as "bob@addr verified".

src/securejoin.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,30 @@ use qrinvite::QrInvite;
3232

3333
use crate::token::Namespace;
3434

35-
fn inviter_progress(context: &Context, contact_id: ContactId, progress: usize) {
35+
fn inviter_progress(
36+
context: &Context,
37+
contact_id: ContactId,
38+
step: &str,
39+
progress: usize,
40+
) -> Result<()> {
3641
logged_debug_assert!(
3742
context,
3843
progress <= 1000,
3944
"inviter_progress: contact {contact_id}, progress={progress}, but value in range 0..1000 expected with: 0=error, 1..999=progress, 1000=success."
4045
);
46+
let chat_type = match step.get(..3) {
47+
Some("vc-") => Chattype::Single,
48+
Some("vg-") => Chattype::Group,
49+
Some("vb-") => Chattype::OutBroadcast,
50+
_ => bail!("Unknown securejoin step {step}"),
51+
};
4152
context.emit_event(EventType::SecurejoinInviterProgress {
4253
contact_id,
54+
chat_type,
4355
progress,
4456
});
57+
58+
Ok(())
4559
}
4660

4761
/// Generates a Secure Join QR code.
@@ -346,7 +360,7 @@ pub(crate) async fn handle_securejoin_handshake(
346360
return Ok(HandshakeMessage::Ignore);
347361
}
348362

349-
inviter_progress(context, contact_id, 300);
363+
inviter_progress(context, contact_id, step, 300)?;
350364

351365
let from_addr = ContactAddress::new(&mime_message.from.addr)?;
352366
let autocrypt_fingerprint = mime_message.autocrypt_fingerprint.as_deref().unwrap_or("");
@@ -442,7 +456,7 @@ pub(crate) async fn handle_securejoin_handshake(
442456
ChatId::create_for_contact(context, contact_id).await?;
443457
}
444458
context.emit_event(EventType::ContactsChanged(Some(contact_id)));
445-
inviter_progress(context, contact_id, 600);
459+
inviter_progress(context, contact_id, step, 600)?;
446460
if let Some(group_chat_id) = group_chat_id {
447461
// Join group.
448462
secure_connection_established(
@@ -455,8 +469,8 @@ pub(crate) async fn handle_securejoin_handshake(
455469

456470
chat::add_contact_to_chat_ex(context, Nosync, group_chat_id, contact_id, true)
457471
.await?;
458-
inviter_progress(context, contact_id, 800);
459-
inviter_progress(context, contact_id, 1000);
472+
inviter_progress(context, contact_id, step, 800)?;
473+
inviter_progress(context, contact_id, step, 1000)?;
460474
if step == "vb-request-with-auth" {
461475
// For broadcasts, we don't want to delete the message,
462476
// because the other device should also internally add the member
@@ -480,7 +494,7 @@ pub(crate) async fn handle_securejoin_handshake(
480494
.await
481495
.context("failed sending vc-contact-confirm message")?;
482496

483-
inviter_progress(context, contact_id, 1000);
497+
inviter_progress(context, contact_id, step, 1000)?;
484498
Ok(HandshakeMessage::Ignore) // "Done" would delete the message and break multi-device (the key from Autocrypt-header is needed)
485499
}
486500
}
@@ -609,11 +623,11 @@ pub(crate) async fn observe_securejoin_on_other_device(
609623
ChatId::set_protection_for_contact(context, contact_id, mime_message.timestamp_sent).await?;
610624

611625
if step == "vg-member-added" {
612-
inviter_progress(context, contact_id, 800);
626+
inviter_progress(context, contact_id, step, 800)?;
613627
}
614628
// TODO superflous vb-member-added (we're early-returning above):
615629
if step == "vg-member-added" || step == "vb-member-added" || step == "vc-contact-confirm" {
616-
inviter_progress(context, contact_id, 1000);
630+
inviter_progress(context, contact_id, step, 1000)?;
617631
}
618632

619633
if step == "vg-request-with-auth" || step == "vc-request-with-auth" {

src/securejoin/securejoin_tests.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ async fn test_setup_contact_bob_knows_alice() -> Result<()> {
366366
alice.recv_msg_trash(&sent).await;
367367
assert_eq!(contact_bob.is_verified(alice).await?, true);
368368

369+
// Check Alice signalled success via the SecurejoinInviterProgress event.
370+
let event = alice
371+
.evtracker
372+
.get_matching(|evt| {
373+
matches!(
374+
evt,
375+
EventType::SecurejoinInviterProgress { progress: 1000, .. }
376+
)
377+
})
378+
.await;
379+
match event {
380+
EventType::SecurejoinInviterProgress {
381+
contact_id,
382+
chat_type,
383+
progress,
384+
} => {
385+
assert_eq!(contact_id, contact_bob.id);
386+
assert_eq!(chat_type, Chattype::Single);
387+
assert_eq!(progress, 1000);
388+
}
389+
_ => unreachable!(),
390+
}
391+
369392
let sent = alice.pop_sent_msg().await;
370393
let msg = bob.parse_msg(&sent).await;
371394
assert!(msg.was_encrypted());
@@ -516,6 +539,29 @@ async fn test_secure_join() -> Result<()> {
516539
alice.recv_msg_trash(&sent).await;
517540
assert_eq!(contact_bob.is_verified(&alice).await?, true);
518541

542+
// Check Alice signalled success via the SecurejoinInviterProgress event.
543+
let event = alice
544+
.evtracker
545+
.get_matching(|evt| {
546+
matches!(
547+
evt,
548+
EventType::SecurejoinInviterProgress { progress: 1000, .. }
549+
)
550+
})
551+
.await;
552+
match event {
553+
EventType::SecurejoinInviterProgress {
554+
contact_id,
555+
chat_type,
556+
progress,
557+
} => {
558+
assert_eq!(contact_id, contact_bob.id);
559+
assert_eq!(chat_type, Chattype::Group);
560+
assert_eq!(progress, 1000);
561+
}
562+
_ => unreachable!(),
563+
}
564+
519565
let sent = alice.pop_sent_msg().await;
520566
let msg = bob.parse_msg(&sent).await;
521567
assert!(msg.was_encrypted());

0 commit comments

Comments
 (0)