test: Deletion request fails in an unencrypted chat and the message remains

This commit is contained in:
iequidoo
2025-03-10 23:18:20 -03:00
committed by iequidoo
parent 3b3d5767b0
commit fa4de8f72e
3 changed files with 23 additions and 0 deletions

View File

@@ -3885,3 +3885,20 @@ async fn test_send_delete_request() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_send_delete_request_no_encryption() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_chat = alice.create_email_chat(bob).await;
// Alice sends a message, then tries to send a deletion request which fails.
let sent1 = alice.send_text(alice_chat.id, "wtf").await;
assert!(message::delete_msgs_ex(alice, &[sent1.sender_msg_id], true)
.await
.is_err());
sent1.load_from_db().await;
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
Ok(())
}

View File

@@ -1760,6 +1760,10 @@ pub async fn delete_msgs_ex(
);
if let Some(chat_id) = modified_chat_ids.iter().next() {
let mut msg = Message::new_text("🚮".to_owned());
// We don't want to send deletion requests in chats w/o encryption:
// - These are usually chats with non-DC clients who won't respect deletion requests
// anyway and display a weird trash bin message instead.
// - Deletion of world-visible unencrypted messages seems not very useful.
msg.param.set_int(Param::GuaranteeE2ee, 1);
msg.param
.set(Param::DeleteRequestFor, deleted_rfc724_mid.join(" "));

View File

@@ -1531,6 +1531,8 @@ async fn add_parts(
} else if let Some(rfc724_mid_list) = mime_parser.get_header(HeaderDef::ChatDelete) {
chat_id = DC_CHAT_ID_TRASH;
if let Some(part) = mime_parser.parts.first() {
// See `message::delete_msgs_ex()`, unlike edit requests, DC doesn't send unencrypted
// deletion requests, so there's no need to support them.
if part.param.get_bool(Param::GuaranteeE2ee).unwrap_or(false) {
let mut modified_chat_ids = HashSet::new();
let mut msg_ids = Vec::new();