Skip to content

Commit 2d5212d

Browse files
committed
Fix python/tests/test_1_online.py::test_add_remove_member_remote_events
1 parent 165e283 commit 2d5212d

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/receive_imf.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,26 +2284,43 @@ async fn apply_group_changes(
22842284
chat_group_member_timestamps.iter().take(to_ids.len()),
22852285
) {
22862286
if *contact_id != from_id {
2287-
transaction.execute(
2287+
let modified = transaction.execute(
22882288
"INSERT INTO chats_contacts (chat_id, contact_id, add_timestamp)
22892289
VALUES (?1, ?2, ?3)
22902290
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",
22922294
(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+
}
22942303
}
22952304
}
22962305

22972306
for (contact_id, ts) in std::iter::zip(
22982307
past_ids.iter(),
22992308
chat_group_member_timestamps.iter().skip(to_ids.len()),
23002309
) {
2301-
transaction.execute(
2310+
let modified = transaction.execute(
23022311
"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",
23052315
(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+
}
23072324
}
23082325

23092326
Ok(())

0 commit comments

Comments
 (0)