@@ -2284,26 +2284,43 @@ async fn apply_group_changes(
2284
2284
chat_group_member_timestamps. iter ( ) . take ( to_ids. len ( ) ) ,
2285
2285
) {
2286
2286
if * contact_id != from_id {
2287
- transaction. execute (
2287
+ let modified = transaction. execute (
2288
2288
"INSERT INTO chats_contacts (chat_id, contact_id, add_timestamp)
2289
2289
VALUES (?1, ?2, ?3)
2290
2290
ON CONFLICT (chat_id, contact_id)
2291
- DO UPDATE SET add_timestamp=MAX(add_timestamp, ?3)" ,
2291
+ DO
2292
+ UPDATE SET add_timestamp=?3
2293
+ WHERE ?3>add_timestamp AND ?3>=remove_timestamp" ,
2292
2294
( chat_id, contact_id, ts) ,
2293
- ) ?;
2295
+ ) ? > 0 ;
2296
+
2297
+ if modified {
2298
+ // It could be that member was already added,
2299
+ // but updated addition timestamp
2300
+ // is also a modification worth notifying about.
2301
+ send_event_chat_modified = true ;
2302
+ }
2294
2303
}
2295
2304
}
2296
2305
2297
2306
for ( contact_id, ts) in std:: iter:: zip (
2298
2307
past_ids. iter ( ) ,
2299
2308
chat_group_member_timestamps. iter ( ) . skip ( to_ids. len ( ) ) ,
2300
2309
) {
2301
- transaction. execute (
2310
+ let modified = transaction. execute (
2302
2311
"UPDATE chats_contacts
2303
- SET remove_timestamp=MAX(remove_timestamp, ?)
2304
- WHERE chat_id=? AND contact_id=?" ,
2312
+ SET remove_timestamp=?1
2313
+ WHERE chat_id=?2 AND contact_id=?3
2314
+ AND ?1>remove_timestamp AND ?1>add_timestamp" ,
2305
2315
( ts, chat_id, contact_id) ,
2306
- ) ?;
2316
+ ) ? > 0 ;
2317
+
2318
+ if modified {
2319
+ // It could be that member was already removed,
2320
+ // but updated removal timestamp
2321
+ // is also a modification worth notifying about.
2322
+ send_event_chat_modified = true ;
2323
+ }
2307
2324
}
2308
2325
2309
2326
Ok ( ( ) )
0 commit comments