mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
recreate test
This commit is contained in:
39
src/chat.rs
39
src/chat.rs
@@ -3961,6 +3961,45 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_sync_member_list_on_rejoin() -> Result<()> {
|
||||||
|
let alice = TestContext::new_alice().await;
|
||||||
|
|
||||||
|
let bob_id = Contact::create(&alice, "", "bob@example.net").await?;
|
||||||
|
let claire_id = Contact::create(&alice, "", "claire@example.de").await?;
|
||||||
|
|
||||||
|
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "foos").await?;
|
||||||
|
add_contact_to_chat(&alice, alice_chat_id, bob_id).await?;
|
||||||
|
add_contact_to_chat(&alice, alice_chat_id, claire_id).await?;
|
||||||
|
|
||||||
|
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
||||||
|
let add = alice.pop_sent_msg().await;
|
||||||
|
let bob = TestContext::new_bob().await;
|
||||||
|
bob.recv_msg(&add).await;
|
||||||
|
let bob_chat_id = bob.get_last_msg().await.chat_id;
|
||||||
|
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 3);
|
||||||
|
|
||||||
|
// remove bob from chat
|
||||||
|
remove_contact_from_chat(&alice, alice_chat_id, bob_id).await?;
|
||||||
|
let remove_bob = alice.pop_sent_msg().await;
|
||||||
|
bob.recv_msg(&remove_bob).await;
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(1100)).await;
|
||||||
|
|
||||||
|
// remove any other member
|
||||||
|
remove_contact_from_chat(&alice, alice_chat_id, claire_id).await?;
|
||||||
|
alice.pop_sent_msg().await;
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(1100)).await;
|
||||||
|
|
||||||
|
// readd bob
|
||||||
|
add_contact_to_chat(&alice, alice_chat_id, bob_id).await?;
|
||||||
|
let add2 = alice.pop_sent_msg().await;
|
||||||
|
bob.recv_msg(&add2).await;
|
||||||
|
|
||||||
|
// number of memebers in chat should have updated
|
||||||
|
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 2);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_leave_group() -> Result<()> {
|
async fn test_leave_group() -> Result<()> {
|
||||||
let alice = TestContext::new_alice().await;
|
let alice = TestContext::new_alice().await;
|
||||||
|
|||||||
@@ -1613,21 +1613,20 @@ async fn apply_group_changes(
|
|||||||
removed_id = Contact::lookup_id_by_addr(context, &removed_addr, Origin::Unknown).await?;
|
removed_id = Contact::lookup_id_by_addr(context, &removed_addr, Origin::Unknown).await?;
|
||||||
match removed_id {
|
match removed_id {
|
||||||
Some(contact_id) => {
|
Some(contact_id) => {
|
||||||
let mut previous_exists = false;
|
recreate_member_list = match mime_parser.get_header(HeaderDef::InReplyTo) {
|
||||||
if let Some(msgid) = mime_parser.get_header(HeaderDef::InReplyTo) {
|
Some(reply_to) if rfc724_mid_exists(context, reply_to).await?.is_none() => true,
|
||||||
if rfc724_mid_exists(context, msgid).await?.is_some() {
|
Some(_) => false,
|
||||||
previous_exists = true;
|
None => true,
|
||||||
}
|
};
|
||||||
}
|
|
||||||
if mime_parser.get_header(HeaderDef::InReplyTo).is_none() || !previous_exists {
|
if !recreate_member_list {
|
||||||
recreate_member_list = true;
|
|
||||||
} else {
|
|
||||||
chat::remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
|
chat::remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
|
||||||
chat_id
|
chat_id
|
||||||
.update_timestamp(context, Param::MemberListTimestamp, sent_timestamp)
|
.update_timestamp(context, Param::MemberListTimestamp, sent_timestamp)
|
||||||
.await?;
|
.await?;
|
||||||
send_event_chat_modified = true;
|
send_event_chat_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
better_msg = if contact_id == from_id {
|
better_msg = if contact_id == from_id {
|
||||||
Some(stock_str::msg_group_left(context, from_id).await)
|
Some(stock_str::msg_group_left(context, from_id).await)
|
||||||
} else {
|
} else {
|
||||||
@@ -1650,9 +1649,13 @@ async fn apply_group_changes(
|
|||||||
if let Some(contact_id) =
|
if let Some(contact_id) =
|
||||||
Contact::lookup_id_by_addr(context, &added_member, Origin::Unknown).await?
|
Contact::lookup_id_by_addr(context, &added_member, Origin::Unknown).await?
|
||||||
{
|
{
|
||||||
if mime_parser.get_header(HeaderDef::InReplyTo).is_none() {
|
recreate_member_list = match mime_parser.get_header(HeaderDef::InReplyTo) {
|
||||||
recreate_member_list = true;
|
Some(reply_to) if rfc724_mid_exists(context, reply_to).await?.is_none() => true,
|
||||||
} else {
|
Some(_) => false,
|
||||||
|
None => true,
|
||||||
|
};
|
||||||
|
warn!(context, "recreating: {}", recreate_member_list);
|
||||||
|
if !recreate_member_list {
|
||||||
chat::add_to_chat_contacts_table(context, chat_id, &[contact_id]).await?;
|
chat::add_to_chat_contacts_table(context, chat_id, &[contact_id]).await?;
|
||||||
chat_id
|
chat_id
|
||||||
.update_timestamp(context, Param::MemberListTimestamp, sent_timestamp)
|
.update_timestamp(context, Param::MemberListTimestamp, sent_timestamp)
|
||||||
|
|||||||
Reference in New Issue
Block a user