Skip to content

Commit

Permalink
test: Deletion request fails in an unencrypted chat and the message r…
Browse files Browse the repository at this point in the history
…emains
  • Loading branch information
iequidoo committed Mar 11, 2025
1 parent 3b3d576 commit fa4de8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
4 changes: 4 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "));
Expand Down
2 changes: 2 additions & 0 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fa4de8f

Please sign in to comment.