Skip to content

Commit ae759d7

Browse files
committed
refactor: make memberlist update logic easier to follow
1 parent fa016b3 commit ae759d7

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

src/receive_imf.rs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,11 +2328,6 @@ async fn apply_group_changes(
23282328
}
23292329
}
23302330

2331-
// These are for adding info messages about implicit membership changes, so they are only
2332-
// filled when such messages are needed.
2333-
let mut added_ids = HashSet::<ContactId>::new();
2334-
let mut removed_ids = HashSet::<ContactId>::new();
2335-
23362331
if is_from_in_chat {
23372332
if let Some(ref chat_group_member_timestamps) = mime_parser.chat_group_member_timestamps() {
23382333
send_event_chat_modified |= update_chats_contacts_timestamps(
@@ -2344,41 +2339,31 @@ async fn apply_group_changes(
23442339
chat_group_member_timestamps,
23452340
)
23462341
.await?;
2347-
let new_chat_contacts = HashSet::<ContactId>::from_iter(
2348-
chat::get_chat_contacts(context, chat_id)
2349-
.await?
2350-
.iter()
2351-
.copied(),
2352-
);
2353-
added_ids = new_chat_contacts
2354-
.difference(&chat_contacts)
2355-
.copied()
2356-
.collect();
2357-
removed_ids = chat_contacts
2358-
.difference(&new_chat_contacts)
2359-
.copied()
2360-
.collect();
23612342
} else {
2362-
let mut new_members = HashSet::from_iter(to_ids.iter().copied());
2363-
new_members.insert(ContactId::SELF);
2364-
if !from_id.is_special() {
2365-
new_members.insert(from_id);
2366-
}
2367-
2368-
if !self_added {
2369-
if mime_parser.get_header(HeaderDef::ChatVersion).is_none() {
2370-
// Allow non-Delta Chat MUAs to add members.
2371-
added_ids = new_members.difference(&chat_contacts).copied().collect();
2372-
}
2373-
2374-
if let Some(added_id) = added_id {
2375-
added_ids.insert(added_id);
2343+
let mut new_members = HashSet::new();
2344+
if self_added {
2345+
new_members = HashSet::from_iter(to_ids.iter().copied());
2346+
new_members.insert(ContactId::SELF);
2347+
if !from_id.is_special() {
2348+
new_members.insert(from_id);
23762349
}
2350+
} else {
23772351
new_members.clone_from(&chat_contacts);
2352+
}
2353+
2354+
// Allow non-Delta Chat MUAs to add members.
2355+
if mime_parser.get_header(HeaderDef::ChatVersion).is_none() {
23782356
// Don't delete any members locally, but instead add absent ones to provide group
23792357
// membership consistency for all members:
2380-
new_members.extend(added_ids.clone());
2358+
new_members.extend(to_ids.iter());
23812359
}
2360+
2361+
// Apply explicit addition if any.
2362+
if let Some(added_id) = added_id {
2363+
new_members.insert(added_id);
2364+
}
2365+
2366+
// Apply explicit removal if any.
23822367
if let Some(removed_id) = removed_id {
23832368
new_members.remove(&removed_id);
23842369
}
@@ -2391,12 +2376,31 @@ async fn apply_group_changes(
23912376
&new_members,
23922377
)
23932378
.await?;
2394-
chat_contacts = new_members;
23952379
send_event_chat_modified = true;
23962380
}
23972381
}
23982382
}
23992383

2384+
let new_chat_contacts = HashSet::<ContactId>::from_iter(
2385+
chat::get_chat_contacts(context, chat_id)
2386+
.await?
2387+
.iter()
2388+
.copied(),
2389+
);
2390+
2391+
// These are for adding info messages about implicit membership changes, so they are only
2392+
// filled when such messages are needed.
2393+
let mut added_ids: HashSet::<ContactId> = new_chat_contacts
2394+
.difference(&chat_contacts)
2395+
.copied()
2396+
.collect();
2397+
let mut removed_ids: HashSet::<ContactId> = chat_contacts
2398+
.difference(&new_chat_contacts)
2399+
.copied()
2400+
.collect();
2401+
2402+
chat_contacts = new_chat_contacts;
2403+
24002404
if let Some(added_id) = added_id {
24012405
if !added_ids.remove(&added_id) && !self_added {
24022406
// No-op "Member added" message.

0 commit comments

Comments
 (0)