From 72bfae9448b27d76a74f7213f59f49965ac74ba8 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 26 Mar 2024 22:06:51 -0300 Subject: [PATCH] fix: Keep tombstones for two days before deleting (#3685) This is a way to prevent redownloading locally deleted messages. Otherwise if a message is deleted quickly after sending and `bcc_self` is configured, the BCC copy is downloaded and appears as a new message as it happens for messages sent from another device. --- python/tests/test_0_complex_or_slow.py | 14 ++++++++++++++ src/sql.rs | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/python/tests/test_0_complex_or_slow.py b/python/tests/test_0_complex_or_slow.py index 4ee773912..fbd5738f2 100644 --- a/python/tests/test_0_complex_or_slow.py +++ b/python/tests/test_0_complex_or_slow.py @@ -1,4 +1,5 @@ import sys +import time import pytest import deltachat as dc @@ -675,3 +676,16 @@ def test_verified_group_vs_delete_server_after(acfactory, tmp_path, lp): assert msg_in.chat == chat2_offl assert msg_in.get_sender_contact().addr == ac2.get_config("addr") assert ac2_offl_ac1_contact.is_verified() + + +def test_deleted_msgs_dont_reappear(acfactory): + ac1 = acfactory.new_online_configuring_account() + acfactory.bring_accounts_online() + ac1.set_config("bcc_self", "1") + chat = ac1.get_self_contact().create_chat() + msg = chat.send_text("hello") + ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") + ac1.delete_messages([msg]) + ac1._evtracker.get_matching("DC_EVENT_MSG_DELETED") + time.sleep(5) + assert len(chat.get_messages()) == 0 diff --git a/src/sql.rs b/src/sql.rs index 16409d92e..f85213851 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -990,16 +990,19 @@ async fn maybe_add_from_param( Ok(()) } -/// Removes from the database locally deleted messages that also don't +/// Removes from the database stale locally deleted messages that also don't /// have a server UID. async fn prune_tombstones(sql: &Sql) -> Result<()> { + // Keep tombstones for the last two days to prevent redownloading locally deleted messages. + let timestamp_max = time().saturating_sub(2 * 24 * 3600); sql.execute( "DELETE FROM msgs WHERE chat_id=? + AND timestamp<=? AND NOT EXISTS ( SELECT * FROM imap WHERE msgs.rfc724_mid=rfc724_mid AND target!='' )", - (DC_CHAT_ID_TRASH,), + (DC_CHAT_ID_TRASH, timestamp_max), ) .await?; Ok(())