Skip to content

Commit a7b9bec

Browse files
committed
Bring back implict member addition/removal messages
1 parent cb57b33 commit a7b9bec

File tree

3 files changed

+67
-39
lines changed

3 files changed

+67
-39
lines changed

src/receive_imf.rs

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,11 @@ async fn apply_group_changes(
22642264
}
22652265
}
22662266

2267+
// These are for adding info messages about implicit membership changes, so they are only
2268+
// filled when such messages are needed.
2269+
let mut added_ids = HashSet::<ContactId>::new();
2270+
let mut removed_ids = HashSet::<ContactId>::new();
2271+
22672272
if let Some(ref chat_group_member_timestamps) = mime_parser.chat_group_member_timestamps() {
22682273
let expected_timestamps_count = to_ids.len() + past_ids.len();
22692274
if chat_group_member_timestamps.len() == expected_timestamps_count {
@@ -2325,18 +2330,28 @@ async fn apply_group_changes(
23252330
expected_timestamps_count
23262331
);
23272332
}
2333+
2334+
let new_chat_contacts = HashSet::<ContactId>::from_iter(
2335+
chat::get_chat_contacts(context, chat_id)
2336+
.await?
2337+
.iter()
2338+
.copied(),
2339+
);
2340+
added_ids = new_chat_contacts
2341+
.difference(&chat_contacts)
2342+
.copied()
2343+
.collect();
2344+
removed_ids = chat_contacts
2345+
.difference(&new_chat_contacts)
2346+
.copied()
2347+
.collect();
23282348
} else if is_from_in_chat {
23292349
let mut new_members = HashSet::from_iter(to_ids.iter().copied());
23302350
new_members.insert(ContactId::SELF);
23312351
if !from_id.is_special() {
23322352
new_members.insert(from_id);
23332353
}
23342354

2335-
// These are for adding info messages about implicit membership changes, so they are only
2336-
// filled when such messages are needed.
2337-
let mut added_ids = HashSet::<ContactId>::new();
2338-
let mut removed_ids = HashSet::<ContactId>::new();
2339-
23402355
if !self_added {
23412356
if mime_parser.get_header(HeaderDef::ChatVersion).is_none() {
23422357
// Allow non-Delta Chat MUAs to add members.
@@ -2355,47 +2370,47 @@ async fn apply_group_changes(
23552370
new_members.remove(&removed_id);
23562371
}
23572372

2358-
if let Some(added_id) = added_id {
2359-
added_ids.remove(&added_id);
2360-
}
2361-
if let Some(removed_id) = removed_id {
2362-
removed_ids.remove(&removed_id);
2363-
}
2364-
if !added_ids.is_empty() {
2365-
warn!(
2366-
context,
2367-
"Implicit addition of {added_ids:?} to chat {chat_id}."
2368-
);
2369-
}
2370-
if !removed_ids.is_empty() {
2371-
warn!(
2372-
context,
2373-
"Implicit removal of {removed_ids:?} from chat {chat_id}."
2374-
);
2375-
}
2376-
group_changes_msgs.reserve(added_ids.len() + removed_ids.len());
2377-
for contact_id in added_ids {
2378-
let contact = Contact::get_by_id(context, contact_id).await?;
2379-
group_changes_msgs.push(
2380-
stock_str::msg_add_member_local(context, contact.get_addr(), ContactId::UNDEFINED)
2381-
.await,
2382-
);
2383-
}
2384-
for contact_id in removed_ids {
2385-
let contact = Contact::get_by_id(context, contact_id).await?;
2386-
group_changes_msgs.push(
2387-
stock_str::msg_del_member_local(context, contact.get_addr(), ContactId::UNDEFINED)
2388-
.await,
2389-
);
2390-
}
2391-
23922373
if new_members != chat_contacts {
23932374
chat::update_chat_contacts_table(context, chat_id, &new_members).await?;
23942375
chat_contacts = new_members;
23952376
send_event_chat_modified = true;
23962377
}
23972378
}
23982379

2380+
if let Some(added_id) = added_id {
2381+
added_ids.remove(&added_id);
2382+
}
2383+
if let Some(removed_id) = removed_id {
2384+
removed_ids.remove(&removed_id);
2385+
}
2386+
if !added_ids.is_empty() {
2387+
warn!(
2388+
context,
2389+
"Implicit addition of {added_ids:?} to chat {chat_id}."
2390+
);
2391+
}
2392+
if !removed_ids.is_empty() {
2393+
warn!(
2394+
context,
2395+
"Implicit removal of {removed_ids:?} from chat {chat_id}."
2396+
);
2397+
}
2398+
group_changes_msgs.reserve(added_ids.len() + removed_ids.len());
2399+
for contact_id in added_ids {
2400+
let contact = Contact::get_by_id(context, contact_id).await?;
2401+
group_changes_msgs.push(
2402+
stock_str::msg_add_member_local(context, contact.get_addr(), ContactId::UNDEFINED)
2403+
.await,
2404+
);
2405+
}
2406+
for contact_id in removed_ids {
2407+
let contact = Contact::get_by_id(context, contact_id).await?;
2408+
group_changes_msgs.push(
2409+
stock_str::msg_del_member_local(context, contact.get_addr(), ContactId::UNDEFINED)
2410+
.await,
2411+
);
2412+
}
2413+
23992414
if let Some(avatar_action) = &mime_parser.group_avatar {
24002415
if !chat_contacts.contains(&ContactId::SELF) {
24012416
warn!(

src/receive_imf/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4268,6 +4268,10 @@ async fn test_delayed_removal_is_ignored() -> Result<()> {
42684268
alice.recv_msg(&remove_msg).await;
42694269
assert_eq!(get_chat_contacts(&alice, chat_id).await?.len(), 5);
42704270

4271+
alice
4272+
.golden_test_chat(chat_id, "receive_imf_delayed_removal_is_ignored")
4273+
.await;
4274+
42714275
Ok(())
42724276
}
42734277

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Group#Chat#10: Group [5 member(s)]
2+
--------------------------------------------------------------------------------
3+
Msg#10: Me (Contact#Contact#Self): populate √
4+
Msg#11: info (Contact#Contact#Info): Member blue@example.net added. [NOTICED][INFO]
5+
Msg#12: info (Contact#Contact#Info): Member fiona (fiona@example.net) removed. [NOTICED][INFO]
6+
Msg#13: bob (Contact#Contact#11): Member orange@example.net added by bob (bob@example.net). [FRESH][INFO]
7+
Msg#14: Me (Contact#Contact#Self): You added member fiona (fiona@example.net). [INFO] o
8+
Msg#15: bob (Contact#Contact#11): Member fiona (fiona@example.net) removed by bob (bob@example.net). [FRESH][INFO]
9+
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)