Compare commits

...

1 Commits

Author SHA1 Message Date
B. Petersen
26997958c3 delete known messaes when deleting chat 2025-03-04 18:20:52 +01:00
2 changed files with 29 additions and 12 deletions

View File

@@ -35,7 +35,7 @@ use crate::ephemeral::{start_chat_ephemeral_timers, Timer as EphemeralTimer};
use crate::events::EventType;
use crate::location;
use crate::log::LogExt;
use crate::message::{self, Message, MessageState, MsgId, Viewtype};
use crate::message::{self, delete_single_msg_from_imap, Message, MessageState, MsgId, Viewtype};
use crate::mimefactory::MimeFactory;
use crate::mimeparser::SystemMessage;
use crate::param::{Param, Params};
@@ -786,7 +786,19 @@ impl ChatId {
let chat = Chat::load_from_db(context, self).await?;
let sync_id = match sync {
Nosync => None,
Sync => chat.get_sync_id(context).await?,
Sync => {
let chat_items = get_chat_msgs(context, self).await?;
for item in chat_items {
match item {
ChatItem::Message { msg_id } => {
let msg = Message::load_from_db(context, msg_id).await?;
delete_single_msg_from_imap(context, msg).await?;
}
ChatItem::DayMarker { .. } => {}
}
}
chat.get_sync_id(context).await?
}
};
context

View File

@@ -1738,16 +1738,7 @@ pub async fn delete_msgs_ex(
modified_chat_ids.insert(msg.chat_id);
deleted_rfc724_mid.push(msg.rfc724_mid.clone());
let target = context.get_delete_msgs_target().await?;
let update_db = |trans: &mut rusqlite::Transaction| {
trans.execute(
"UPDATE imap SET target=? WHERE rfc724_mid=?",
(target, msg.rfc724_mid),
)?;
trans.execute("DELETE FROM smtp WHERE msg_id=?", (msg_id,))?;
Ok(())
};
if let Err(e) = context.sql.transaction(update_db).await {
if let Err(e) = delete_single_msg_from_imap(context, msg).await {
error!(context, "delete_msgs: failed to update db: {e:#}.");
res = Err(e);
continue;
@@ -1788,6 +1779,20 @@ pub async fn delete_msgs_ex(
Ok(())
}
pub(crate) async fn delete_single_msg_from_imap(context: &Context, msg: Message) -> Result<()> {
let target = context.get_delete_msgs_target().await?;
let update_db = |trans: &mut rusqlite::Transaction| {
trans.execute(
"UPDATE imap SET target=? WHERE rfc724_mid=?",
(target, msg.rfc724_mid),
)?;
trans.execute("DELETE FROM smtp WHERE msg_id=?", (msg.id,))?;
Ok(())
};
context.sql.transaction(update_db).await?;
Ok(())
}
/// Marks requested messages as seen.
pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()> {
if msg_ids.is_empty() {