diff --git a/deltachat-jsonrpc/src/api/types/chat_list.rs b/deltachat-jsonrpc/src/api/types/chat_list.rs index b5d31a791..deaeeee20 100644 --- a/deltachat-jsonrpc/src/api/types/chat_list.rs +++ b/deltachat-jsonrpc/src/api/types/chat_list.rs @@ -129,7 +129,9 @@ pub(crate) async fn get_chat_list_item_by_id( let chat_contacts = get_chat_contacts(ctx, chat_id).await?; - let self_in_group = chat_contacts.contains(&ContactId::SELF); + let self_in_group = chat_contacts.contains(&ContactId::SELF) + || chat.get_type() == Chattype::OutBroadcast + || chat.get_type() == Chattype::Mailinglist; let (dm_chat_contact, was_seen_recently) = if chat.get_type() == Chattype::Single { let contact = chat_contacts.first(); diff --git a/src/chat.rs b/src/chat.rs index b63e87fc1..af9c9dcb1 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1737,8 +1737,9 @@ impl Chat { pub(crate) async fn is_self_in_chat(&self, context: &Context) -> Result { match self.typ { Chattype::Single | Chattype::OutBroadcast | Chattype::Mailinglist => Ok(true), - Chattype::Group => is_contact_in_chat(context, self.id, ContactId::SELF).await, - Chattype::InBroadcast => Ok(true), + Chattype::Group | Chattype::InBroadcast => { + is_contact_in_chat(context, self.id, ContactId::SELF).await + } } } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 9363f1cd0..eb74cb0f4 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -3061,9 +3061,7 @@ async fn apply_group_changes( if let Some(added_id) = added_id { if !added_ids.remove(&added_id) && !self_added { - // No-op "Member added" message. - // - // Trash it. + info!(context, "No-op 'Member added' message (TRASH)"); better_msg = Some(String::new()); } } @@ -3315,13 +3313,6 @@ async fn create_or_lookup_mailinglist_or_broadcast( ) })?; - chat::add_to_chat_contacts_table( - context, - mime_parser.timestamp_sent, - chat_id, - &[ContactId::SELF], - ) - .await?; if chattype == Chattype::InBroadcast { chat::add_to_chat_contacts_table( context, @@ -3556,19 +3547,40 @@ async fn apply_in_broadcast_changes( ) .await?; + if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) { + if context.is_self_addr(added_addr).await? { + let msg; + + if chat.is_self_in_chat(context).await? { + // Self is already in the chat. + // Probably Alice has two devices and her second device added us again; + // just hide the message. + info!(context, "No-op broadcast 'Member added' message (TRASH)"); + msg = "".to_string(); + } else { + msg = stock_str::msg_add_member_local(context, ContactId::SELF, from_id).await; + } + + better_msg.get_or_insert(msg); + } + } + if let Some(_removed_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) { - // The only member added/removed message that is ever sent is "I left.", - // so, this is the only case we need to handle here if from_id == ContactId::SELF { + // The only member added/removed message that is ever sent is "I left.", + // so, this is the only case we need to handle here better_msg .get_or_insert(stock_str::msg_group_left_local(context, ContactId::SELF).await); - } - } else if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) { - if context.is_self_addr(added_addr).await? { - better_msg.get_or_insert( - stock_str::msg_add_member_local(context, ContactId::SELF, from_id).await, - ); - } + } // TODO handle removed case + } else if !chat.is_self_in_chat(context).await? { + // Apparently, self is in the chat now, because we're receiving messages + chat::add_to_chat_contacts_table( + context, + mime_parser.timestamp_sent, + chat.id, + &[ContactId::SELF], + ) + .await?; } if let Some(secret) = mime_parser.get_header(HeaderDef::ChatBroadcastSecret) { diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 618a807e7..1919dd0ce 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -881,7 +881,7 @@ async fn test_github_mailing_list() -> Result<()> { Some("reply+elernshsetushoyseshetihseusaferuhsedtisneu@reply.github.com") ); assert_eq!(chat.name, "deltachat/deltachat-core-rust"); - assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await?.len(), 1); + assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await?.len(), 0); receive_imf(&t.ctx, GH_MAILINGLIST2.as_bytes(), false).await?; diff --git a/src/securejoin/bob.rs b/src/securejoin/bob.rs index 8e7099fbe..0c11e54a1 100644 --- a/src/securejoin/bob.rs +++ b/src/securejoin/bob.rs @@ -164,8 +164,10 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul .await?; } - let msg = stock_str::securejoin_wait(context).await; - chat::add_info_msg(context, joining_chat_id, &msg, time()).await?; + if !is_contact_in_chat(context, joining_chat_id, ContactId::SELF).await? { + let msg = stock_str::securejoin_wait(context).await; + chat::add_info_msg(context, joining_chat_id, &msg, time()).await?; + } Ok(joining_chat_id) } QrInvite::Contact { .. } => { diff --git a/test-data/golden/test_broadcast_joining_golden_bob b/test-data/golden/test_broadcast_joining_golden_bob index c03554492..71b6f1bda 100644 --- a/test-data/golden/test_broadcast_joining_golden_bob +++ b/test-data/golden/test_broadcast_joining_golden_bob @@ -1,4 +1,4 @@ -InBroadcast#Chat#11: My Channel [1 member(s)] Icon: e9b6c7a78aa2e4f415644f55a553e73.png +InBroadcast#Chat#11: My Channel [2 member(s)] Icon: e9b6c7a78aa2e4f415644f55a553e73.png -------------------------------------------------------------------------------- Msg#11: info (Contact#Contact#Info): Establishing guaranteed end-to-end encryption, please waitโ€ฆ [NOTICED][INFO] Msg#12๐Ÿ”’: (Contact#Contact#10): Member Me added by Alice. [FRESH][INFO] diff --git a/test-data/golden/test_sync_broadcast_bob b/test-data/golden/test_sync_broadcast_bob index 7aeec5a19..568dd8648 100644 --- a/test-data/golden/test_sync_broadcast_bob +++ b/test-data/golden/test_sync_broadcast_bob @@ -1,6 +1,6 @@ -InBroadcast#Chat#11: Channel [1 member(s)] +InBroadcast#Chat#11: Channel [2 member(s)] -------------------------------------------------------------------------------- Msg#11: info (Contact#Contact#Info): Establishing guaranteed end-to-end encryption, please waitโ€ฆ [NOTICED][INFO] Msg#12๐Ÿ”’: (Contact#Contact#10): Member Me added by alice@example.org. [FRESH][INFO] -Msg#13๐Ÿ”’: (Contact#Contact#10): hi [FRESH] +Msg#14๐Ÿ”’: (Contact#Contact#10): hi [FRESH] --------------------------------------------------------------------------------