Skip to content

Commit 187274d

Browse files
committed
fix: create new tombstone in chats_contacts if the row does not exist
Otherwise new members do not see past members even if they receive info about them in every message.
1 parent 5dc8788 commit 187274d

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/chat.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7808,4 +7808,36 @@ mod tests {
78087808

78097809
Ok(())
78107810
}
7811+
7812+
/// Test that tombstones for past members are added to chats_contacts table
7813+
/// even if the row did not exist before.
7814+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7815+
async fn test_past_members() -> Result<()> {
7816+
let mut tcm = TestContextManager::new();
7817+
7818+
let alice = &tcm.alice().await;
7819+
let alice_fiona_contact_id = Contact::create(alice, "Fiona", "fiona@example.net").await?;
7820+
7821+
let alice_chat_id =
7822+
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
7823+
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7824+
alice
7825+
.send_text(alice_chat_id, "Hi! I created a group.")
7826+
.await;
7827+
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7828+
assert_eq!(get_past_chat_contacts(alice, alice_chat_id).await?.len(), 1);
7829+
7830+
let bob = &tcm.bob().await;
7831+
let bob_addr = bob.get_config(Config::Addr).await?.unwrap();
7832+
let alice_bob_contact_id = Contact::create(alice, "Bob", &bob_addr).await?;
7833+
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
7834+
7835+
let add_message = alice.pop_sent_msg().await;
7836+
let bob_add_message = bob.recv_msg(&add_message).await;
7837+
let bob_chat_id = bob_add_message.chat_id;
7838+
assert_eq!(get_chat_contacts(bob, bob_chat_id).await?.len(), 2);
7839+
assert_eq!(get_past_chat_contacts(bob, bob_chat_id).await?.len(), 1);
7840+
7841+
Ok(())
7842+
}
78117843
}

src/receive_imf.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,10 +2161,12 @@ async fn update_chats_contacts_timestamps(
21612161
}
21622162

21632163
let mut remove_statement = transaction.prepare(
2164-
"UPDATE chats_contacts
2165-
SET remove_timestamp=?1
2166-
WHERE chat_id=?2 AND contact_id=?3
2167-
AND ?1>remove_timestamp AND ?1>add_timestamp",
2164+
"INSERT INTO chats_contacts (chat_id, contact_id, remove_timestamp)
2165+
VALUES (?1, ?2, ?3)
2166+
ON CONFLICT (chat_id, contact_id)
2167+
DO
2168+
UPDATE SET remove_timestamp=?3
2169+
WHERE ?3>remove_timestamp AND ?3>add_timestamp",
21682170
)?;
21692171

21702172
for (contact_id, ts) in iter::zip(
@@ -2174,7 +2176,7 @@ async fn update_chats_contacts_timestamps(
21742176
// It could be that member was already removed,
21752177
// but updated removal timestamp
21762178
// is also a modification worth notifying about.
2177-
modified |= remove_statement.execute((ts, chat_id, contact_id))? > 0;
2179+
modified |= remove_statement.execute((chat_id, contact_id, ts))? > 0;
21782180
}
21792181

21802182
Ok(())

0 commit comments

Comments
 (0)