fix: Show only one member-added message for Bob

This commit is contained in:
Hocuri
2025-08-07 23:17:39 +02:00
parent 8d89dcc65f
commit 265ac4e30b
7 changed files with 45 additions and 28 deletions

View File

@@ -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();

View File

@@ -1737,8 +1737,9 @@ impl Chat {
pub(crate) async fn is_self_in_chat(&self, context: &Context) -> Result<bool> {
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
}
}
}

View File

@@ -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) {

View File

@@ -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?;

View File

@@ -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 { .. } => {

View File

@@ -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]

View File

@@ -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]
--------------------------------------------------------------------------------