@@ -2328,11 +2328,6 @@ async fn apply_group_changes(
2328
2328
}
2329
2329
}
2330
2330
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
-
2336
2331
if is_from_in_chat {
2337
2332
if let Some ( ref chat_group_member_timestamps) = mime_parser. chat_group_member_timestamps ( ) {
2338
2333
send_event_chat_modified |= update_chats_contacts_timestamps (
@@ -2344,41 +2339,31 @@ async fn apply_group_changes(
2344
2339
chat_group_member_timestamps,
2345
2340
)
2346
2341
. 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 ( ) ;
2361
2342
} 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) ;
2376
2349
}
2350
+ } else {
2377
2351
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 ( ) {
2378
2356
// Don't delete any members locally, but instead add absent ones to provide group
2379
2357
// membership consistency for all members:
2380
- new_members. extend ( added_ids . clone ( ) ) ;
2358
+ new_members. extend ( to_ids . iter ( ) ) ;
2381
2359
}
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.
2382
2367
if let Some ( removed_id) = removed_id {
2383
2368
new_members. remove ( & removed_id) ;
2384
2369
}
@@ -2391,12 +2376,31 @@ async fn apply_group_changes(
2391
2376
& new_members,
2392
2377
)
2393
2378
. await ?;
2394
- chat_contacts = new_members;
2395
2379
send_event_chat_modified = true ;
2396
2380
}
2397
2381
}
2398
2382
}
2399
2383
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
+
2400
2404
if let Some ( added_id) = added_id {
2401
2405
if !added_ids. remove ( & added_id) && !self_added {
2402
2406
// No-op "Member added" message.
0 commit comments