@@ -2264,6 +2264,11 @@ async fn apply_group_changes(
2264
2264
}
2265
2265
}
2266
2266
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
+
2267
2272
if let Some ( ref chat_group_member_timestamps) = mime_parser. chat_group_member_timestamps ( ) {
2268
2273
let expected_timestamps_count = to_ids. len ( ) + past_ids. len ( ) ;
2269
2274
if chat_group_member_timestamps. len ( ) == expected_timestamps_count {
@@ -2325,18 +2330,28 @@ async fn apply_group_changes(
2325
2330
expected_timestamps_count
2326
2331
) ;
2327
2332
}
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 ( ) ;
2328
2348
} else if is_from_in_chat {
2329
2349
let mut new_members = HashSet :: from_iter ( to_ids. iter ( ) . copied ( ) ) ;
2330
2350
new_members. insert ( ContactId :: SELF ) ;
2331
2351
if !from_id. is_special ( ) {
2332
2352
new_members. insert ( from_id) ;
2333
2353
}
2334
2354
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
-
2340
2355
if !self_added {
2341
2356
if mime_parser. get_header ( HeaderDef :: ChatVersion ) . is_none ( ) {
2342
2357
// Allow non-Delta Chat MUAs to add members.
@@ -2355,47 +2370,47 @@ async fn apply_group_changes(
2355
2370
new_members. remove ( & removed_id) ;
2356
2371
}
2357
2372
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
-
2392
2373
if new_members != chat_contacts {
2393
2374
chat:: update_chat_contacts_table ( context, chat_id, & new_members) . await ?;
2394
2375
chat_contacts = new_members;
2395
2376
send_event_chat_modified = true ;
2396
2377
}
2397
2378
}
2398
2379
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
+
2399
2414
if let Some ( avatar_action) = & mime_parser. group_avatar {
2400
2415
if !chat_contacts. contains ( & ContactId :: SELF ) {
2401
2416
warn ! (
0 commit comments