mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
api: add chat ID to SecureJoinInviterProgress
This commit is contained in:
@@ -308,6 +308,8 @@ pub enum EventType {
|
|||||||
/// This can take the same values
|
/// This can take the same values
|
||||||
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
|
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
|
||||||
chat_type: u32,
|
chat_type: u32,
|
||||||
|
/// ID of the chat in case of success.
|
||||||
|
chat_id: u32,
|
||||||
|
|
||||||
/// Progress, always 1000.
|
/// Progress, always 1000.
|
||||||
progress: usize,
|
progress: usize,
|
||||||
@@ -556,10 +558,12 @@ impl From<CoreEventType> for EventType {
|
|||||||
CoreEventType::SecurejoinInviterProgress {
|
CoreEventType::SecurejoinInviterProgress {
|
||||||
contact_id,
|
contact_id,
|
||||||
chat_type,
|
chat_type,
|
||||||
|
chat_id,
|
||||||
progress,
|
progress,
|
||||||
} => SecurejoinInviterProgress {
|
} => SecurejoinInviterProgress {
|
||||||
contact_id: contact_id.to_u32(),
|
contact_id: contact_id.to_u32(),
|
||||||
chat_type: chat_type.to_u32().unwrap_or(0),
|
chat_type: chat_type.to_u32().unwrap_or(0),
|
||||||
|
chat_id: chat_id.to_u32(),
|
||||||
progress,
|
progress,
|
||||||
},
|
},
|
||||||
CoreEventType::SecurejoinJoinerProgress {
|
CoreEventType::SecurejoinJoinerProgress {
|
||||||
|
|||||||
@@ -273,6 +273,9 @@ pub enum EventType {
|
|||||||
/// ID of the contact that wants to join.
|
/// ID of the contact that wants to join.
|
||||||
contact_id: ContactId,
|
contact_id: ContactId,
|
||||||
|
|
||||||
|
/// ID of the chat in case of success.
|
||||||
|
chat_id: ChatId,
|
||||||
|
|
||||||
/// The type of the joined chat.
|
/// The type of the joined chat.
|
||||||
chat_type: Chattype,
|
chat_type: Chattype,
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,12 @@ use qrinvite::QrInvite;
|
|||||||
|
|
||||||
use crate::token::Namespace;
|
use crate::token::Namespace;
|
||||||
|
|
||||||
fn inviter_progress(context: &Context, contact_id: ContactId, is_group: bool) -> Result<()> {
|
fn inviter_progress(
|
||||||
|
context: &Context,
|
||||||
|
contact_id: ContactId,
|
||||||
|
chat_id: ChatId,
|
||||||
|
is_group: bool,
|
||||||
|
) -> Result<()> {
|
||||||
let chat_type = if is_group {
|
let chat_type = if is_group {
|
||||||
Chattype::Group
|
Chattype::Group
|
||||||
} else {
|
} else {
|
||||||
@@ -42,6 +47,7 @@ fn inviter_progress(context: &Context, contact_id: ContactId, is_group: bool) ->
|
|||||||
let progress = 1000;
|
let progress = 1000;
|
||||||
context.emit_event(EventType::SecurejoinInviterProgress {
|
context.emit_event(EventType::SecurejoinInviterProgress {
|
||||||
contact_id,
|
contact_id,
|
||||||
|
chat_id,
|
||||||
chat_type,
|
chat_type,
|
||||||
progress,
|
progress,
|
||||||
});
|
});
|
||||||
@@ -418,16 +424,17 @@ pub(crate) async fn handle_securejoin_handshake(
|
|||||||
chat::add_contact_to_chat_ex(context, Nosync, group_chat_id, contact_id, true)
|
chat::add_contact_to_chat_ex(context, Nosync, group_chat_id, contact_id, true)
|
||||||
.await?;
|
.await?;
|
||||||
let is_group = true;
|
let is_group = true;
|
||||||
inviter_progress(context, contact_id, is_group)?;
|
inviter_progress(context, contact_id, group_chat_id, is_group)?;
|
||||||
// IMAP-delete the message to avoid handling it by another device and adding the
|
// IMAP-delete the message to avoid handling it by another device and adding the
|
||||||
// member twice. Another device will know the member's key from Autocrypt-Gossip.
|
// member twice. Another device will know the member's key from Autocrypt-Gossip.
|
||||||
Ok(HandshakeMessage::Done)
|
Ok(HandshakeMessage::Done)
|
||||||
} else {
|
} else {
|
||||||
|
let chat_id = info_chat_id(context, contact_id).await?;
|
||||||
// Setup verified contact.
|
// Setup verified contact.
|
||||||
secure_connection_established(
|
secure_connection_established(
|
||||||
context,
|
context,
|
||||||
contact_id,
|
contact_id,
|
||||||
info_chat_id(context, contact_id).await?,
|
chat_id,
|
||||||
mime_message.timestamp_sent,
|
mime_message.timestamp_sent,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -436,7 +443,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
|||||||
.context("failed sending vc-contact-confirm message")?;
|
.context("failed sending vc-contact-confirm message")?;
|
||||||
|
|
||||||
let is_group = false;
|
let is_group = false;
|
||||||
inviter_progress(context, contact_id, is_group)?;
|
inviter_progress(context, contact_id, chat_id, is_group)?;
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -559,7 +566,16 @@ pub(crate) async fn observe_securejoin_on_other_device(
|
|||||||
let is_group = mime_message
|
let is_group = mime_message
|
||||||
.get_header(HeaderDef::ChatGroupMemberAdded)
|
.get_header(HeaderDef::ChatGroupMemberAdded)
|
||||||
.is_some();
|
.is_some();
|
||||||
inviter_progress(context, contact_id, is_group)?;
|
|
||||||
|
// We don't know the chat ID
|
||||||
|
// as we may not know about the group yet.
|
||||||
|
//
|
||||||
|
// Event is mostly used for bots
|
||||||
|
// which only have a single device
|
||||||
|
// and tests which don't care about the chat ID,
|
||||||
|
// so we pass invalid chat ID here.
|
||||||
|
let chat_id = ChatId::new(0);
|
||||||
|
inviter_progress(context, contact_id, chat_id, is_group)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if step == "vg-request-with-auth" || step == "vc-request-with-auth" {
|
if step == "vg-request-with-auth" || step == "vc-request-with-auth" {
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ async fn test_setup_contact_bob_knows_alice() -> Result<()> {
|
|||||||
contact_id,
|
contact_id,
|
||||||
chat_type,
|
chat_type,
|
||||||
progress,
|
progress,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(contact_id, contact_bob.id);
|
assert_eq!(contact_id, contact_bob.id);
|
||||||
assert_eq!(chat_type, Chattype::Single);
|
assert_eq!(chat_type, Chattype::Single);
|
||||||
@@ -552,10 +553,12 @@ async fn test_secure_join() -> Result<()> {
|
|||||||
EventType::SecurejoinInviterProgress {
|
EventType::SecurejoinInviterProgress {
|
||||||
contact_id,
|
contact_id,
|
||||||
chat_type,
|
chat_type,
|
||||||
|
chat_id,
|
||||||
progress,
|
progress,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(contact_id, contact_bob.id);
|
assert_eq!(contact_id, contact_bob.id);
|
||||||
assert_eq!(chat_type, Chattype::Group);
|
assert_eq!(chat_type, Chattype::Group);
|
||||||
|
assert_eq!(chat_id, alice_chatid);
|
||||||
assert_eq!(progress, 1000);
|
assert_eq!(progress, 1000);
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|||||||
Reference in New Issue
Block a user