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.
This commit is contained in:
iequidoo
2024-03-26 22:06:51 -03:00
committed by iequidoo
parent 6aaed3b524
commit 72bfae9448
2 changed files with 19 additions and 2 deletions

View File

@@ -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(())