Skip to content

Commit fa4de8f

Browse files
committed
test: Deletion request fails in an unencrypted chat and the message remains
1 parent 3b3d576 commit fa4de8f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/chat/chat_tests.rs

+17
Original file line numberDiff line numberDiff line change
@@ -3885,3 +3885,20 @@ async fn test_send_delete_request() -> Result<()> {
38853885

38863886
Ok(())
38873887
}
3888+
3889+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3890+
async fn test_send_delete_request_no_encryption() -> Result<()> {
3891+
let mut tcm = TestContextManager::new();
3892+
let alice = &tcm.alice().await;
3893+
let bob = &tcm.bob().await;
3894+
let alice_chat = alice.create_email_chat(bob).await;
3895+
3896+
// Alice sends a message, then tries to send a deletion request which fails.
3897+
let sent1 = alice.send_text(alice_chat.id, "wtf").await;
3898+
assert!(message::delete_msgs_ex(alice, &[sent1.sender_msg_id], true)
3899+
.await
3900+
.is_err());
3901+
sent1.load_from_db().await;
3902+
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
3903+
Ok(())
3904+
}

src/message.rs

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

src/receive_imf.rs

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

0 commit comments

Comments
 (0)