@@ -2237,7 +2237,7 @@ async fn apply_group_changes(
2237
2237
false
2238
2238
} ;
2239
2239
2240
- let mut chat_contacts =
2240
+ let chat_contacts =
2241
2241
HashSet :: < ContactId > :: from_iter ( chat:: get_chat_contacts ( context, chat_id) . await ?) ;
2242
2242
let is_from_in_chat =
2243
2243
!chat_contacts. contains ( & ContactId :: SELF ) || chat_contacts. contains ( & from_id) ;
@@ -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 ( ) ;
2343
+ let mut new_members;
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) ;
2372
2349
}
2350
+ } else {
2351
+ new_members = chat_contacts. clone ( ) ;
2352
+ }
2373
2353
2374
- if let Some ( added_id) = added_id {
2375
- added_ids. insert ( added_id) ;
2376
- }
2377
- new_members. clone_from ( & chat_contacts) ;
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,28 @@ 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.
2392
+ let mut added_ids: HashSet < ContactId > = new_chat_contacts
2393
+ . difference ( & chat_contacts)
2394
+ . copied ( )
2395
+ . collect ( ) ;
2396
+ let mut removed_ids: HashSet < ContactId > = chat_contacts
2397
+ . difference ( & new_chat_contacts)
2398
+ . copied ( )
2399
+ . collect ( ) ;
2400
+
2400
2401
if let Some ( added_id) = added_id {
2401
2402
if !added_ids. remove ( & added_id) && !self_added {
2402
2403
// No-op "Member added" message.
@@ -2437,12 +2438,12 @@ async fn apply_group_changes(
2437
2438
}
2438
2439
2439
2440
if let Some ( avatar_action) = & mime_parser. group_avatar {
2440
- if !chat_contacts . contains ( & ContactId :: SELF ) {
2441
+ if !new_chat_contacts . contains ( & ContactId :: SELF ) {
2441
2442
warn ! (
2442
2443
context,
2443
2444
"Received group avatar update for group chat {chat_id} we are not a member of."
2444
2445
) ;
2445
- } else if !chat_contacts . contains ( & from_id) {
2446
+ } else if !new_chat_contacts . contains ( & from_id) {
2446
2447
warn ! (
2447
2448
context,
2448
2449
"Contact {from_id} attempts to modify group chat {chat_id} avatar without being a member." ,
0 commit comments