mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
* fix * code-review fixes * check if chat is restored correctly * add changelog-entry * Update src/dc_receive_imf.rs Co-authored-by: Asiel Díaz Benítez <adbenitez@nauta.cu> * Update CHANGELOG.md Co-authored-by: Asiel Díaz Benítez <adbenitez@nauta.cu> Co-authored-by: Asiel Díaz Benítez <adbenitez@nauta.cu>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
- Take `delete_device_after` into account when calculating ephemeral loop timeout #3211
|
- Take `delete_device_after` into account when calculating ephemeral loop timeout #3211
|
||||||
|
- Fix a bug where a blocked contact could send a contact request #3218
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
|||||||
@@ -668,8 +668,13 @@ async fn add_parts(
|
|||||||
// try to create a normal chat
|
// try to create a normal chat
|
||||||
let create_blocked = if from_id == ContactId::SELF {
|
let create_blocked = if from_id == ContactId::SELF {
|
||||||
Blocked::Not
|
Blocked::Not
|
||||||
|
} else {
|
||||||
|
let contact = Contact::load_from_db(context, from_id).await?;
|
||||||
|
if contact.is_blocked() {
|
||||||
|
Blocked::Yes
|
||||||
} else {
|
} else {
|
||||||
Blocked::Request
|
Blocked::Request
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(chat) = test_normal_chat {
|
if let Some(chat) = test_normal_chat {
|
||||||
@@ -5116,4 +5121,70 @@ Reply from different address
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_no_private_reply_to_blocked_account() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new().await;
|
||||||
|
let alice = tcm.alice().await;
|
||||||
|
let bob = tcm.bob().await;
|
||||||
|
|
||||||
|
// =============== Bob creates a group ===============
|
||||||
|
let group_id =
|
||||||
|
chat::create_group_chat(&bob, ProtectionStatus::Unprotected, "Group").await?;
|
||||||
|
chat::add_to_chat_contacts_table(
|
||||||
|
&bob,
|
||||||
|
group_id,
|
||||||
|
bob.add_or_lookup_contact(&alice).await.id,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// =============== Bob sends the first message to the group ===============
|
||||||
|
let sent = bob.send_text(group_id, "Hello all!").await;
|
||||||
|
alice.recv_msg(&sent).await;
|
||||||
|
|
||||||
|
let chats = Chatlist::try_load(&bob, 0, None, None).await?;
|
||||||
|
assert_eq!(chats.len(), 1);
|
||||||
|
|
||||||
|
// =============== Bob blocks Alice ================
|
||||||
|
Contact::block(&bob, bob.add_or_lookup_contact(&alice).await.id).await?;
|
||||||
|
|
||||||
|
// =============== Alice replies private to Bob ==============
|
||||||
|
let received = alice.get_last_msg().await;
|
||||||
|
assert_eq!(received.text, Some("Hello all!".to_string()));
|
||||||
|
|
||||||
|
let received_group = Chat::load_from_db(&alice, received.chat_id).await?;
|
||||||
|
assert_eq!(received_group.typ, Chattype::Group);
|
||||||
|
|
||||||
|
let mut msg_out = Message::new(Viewtype::Text);
|
||||||
|
msg_out.set_text(Some("Private reply".to_string()));
|
||||||
|
msg_out.set_quote(&alice, Some(&received)).await?;
|
||||||
|
|
||||||
|
let alice_bob_chat = alice.create_chat(&bob).await;
|
||||||
|
let sent2 = alice.send_msg(alice_bob_chat.id, &mut msg_out).await;
|
||||||
|
bob.recv_msg(&sent2).await;
|
||||||
|
|
||||||
|
// ========= check that no contact request was created ============
|
||||||
|
let chats = Chatlist::try_load(&bob, 0, None, None).await.unwrap();
|
||||||
|
assert_eq!(chats.len(), 1);
|
||||||
|
let chat_id = chats.get_chat_id(0).unwrap();
|
||||||
|
let chat = Chat::load_from_db(&bob, chat_id).await.unwrap();
|
||||||
|
|
||||||
|
// since only chat is a group, no new open chat has been created
|
||||||
|
assert_eq!(chat.typ, Chattype::Group);
|
||||||
|
let received = bob.get_last_msg().await;
|
||||||
|
assert_eq!(received.text, Some("Hello all!".to_string()));
|
||||||
|
|
||||||
|
// =============== Bob unblocks Alice ================
|
||||||
|
// test if the blocked chat is restored correctly
|
||||||
|
Contact::unblock(&bob, bob.add_or_lookup_contact(&alice).await.id).await?;
|
||||||
|
let chats = Chatlist::try_load(&bob, 0, None, None).await.unwrap();
|
||||||
|
assert_eq!(chats.len(), 2);
|
||||||
|
let chat_id = chats.get_chat_id(0).unwrap();
|
||||||
|
let chat = Chat::load_from_db(&bob, chat_id).await.unwrap();
|
||||||
|
assert_eq!(chat.typ, Chattype::Single);
|
||||||
|
let received = bob.get_last_msg().await;
|
||||||
|
assert_eq!(received.text, Some("Private reply".to_string()));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user