mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +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
|
||||
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
|
||||
chat_type: u32,
|
||||
/// ID of the chat in case of success.
|
||||
chat_id: u32,
|
||||
|
||||
/// Progress, always 1000.
|
||||
progress: usize,
|
||||
@@ -556,10 +558,12 @@ impl From<CoreEventType> for EventType {
|
||||
CoreEventType::SecurejoinInviterProgress {
|
||||
contact_id,
|
||||
chat_type,
|
||||
chat_id,
|
||||
progress,
|
||||
} => SecurejoinInviterProgress {
|
||||
contact_id: contact_id.to_u32(),
|
||||
chat_type: chat_type.to_u32().unwrap_or(0),
|
||||
chat_id: chat_id.to_u32(),
|
||||
progress,
|
||||
},
|
||||
CoreEventType::SecurejoinJoinerProgress {
|
||||
|
||||
@@ -273,6 +273,9 @@ pub enum EventType {
|
||||
/// ID of the contact that wants to join.
|
||||
contact_id: ContactId,
|
||||
|
||||
/// ID of the chat in case of success.
|
||||
chat_id: ChatId,
|
||||
|
||||
/// The type of the joined chat.
|
||||
chat_type: Chattype,
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ use qrinvite::QrInvite;
|
||||
|
||||
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 {
|
||||
Chattype::Group
|
||||
} else {
|
||||
@@ -42,6 +47,7 @@ fn inviter_progress(context: &Context, contact_id: ContactId, is_group: bool) ->
|
||||
let progress = 1000;
|
||||
context.emit_event(EventType::SecurejoinInviterProgress {
|
||||
contact_id,
|
||||
chat_id,
|
||||
chat_type,
|
||||
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)
|
||||
.await?;
|
||||
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
|
||||
// member twice. Another device will know the member's key from Autocrypt-Gossip.
|
||||
Ok(HandshakeMessage::Done)
|
||||
} else {
|
||||
let chat_id = info_chat_id(context, contact_id).await?;
|
||||
// Setup verified contact.
|
||||
secure_connection_established(
|
||||
context,
|
||||
contact_id,
|
||||
info_chat_id(context, contact_id).await?,
|
||||
chat_id,
|
||||
mime_message.timestamp_sent,
|
||||
)
|
||||
.await?;
|
||||
@@ -436,7 +443,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
||||
.context("failed sending vc-contact-confirm message")?;
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -559,7 +566,16 @@ pub(crate) async fn observe_securejoin_on_other_device(
|
||||
let is_group = mime_message
|
||||
.get_header(HeaderDef::ChatGroupMemberAdded)
|
||||
.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" {
|
||||
|
||||
@@ -380,6 +380,7 @@ async fn test_setup_contact_bob_knows_alice() -> Result<()> {
|
||||
contact_id,
|
||||
chat_type,
|
||||
progress,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(contact_id, contact_bob.id);
|
||||
assert_eq!(chat_type, Chattype::Single);
|
||||
@@ -552,10 +553,12 @@ async fn test_secure_join() -> Result<()> {
|
||||
EventType::SecurejoinInviterProgress {
|
||||
contact_id,
|
||||
chat_type,
|
||||
chat_id,
|
||||
progress,
|
||||
} => {
|
||||
assert_eq!(contact_id, contact_bob.id);
|
||||
assert_eq!(chat_type, Chattype::Group);
|
||||
assert_eq!(chat_id, alice_chatid);
|
||||
assert_eq!(progress, 1000);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
||||
Reference in New Issue
Block a user