mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 04:16:30 +03:00
delete known messaes when deleting chat
This commit is contained in:
16
src/chat.rs
16
src/chat.rs
@@ -35,7 +35,7 @@ use crate::ephemeral::{start_chat_ephemeral_timers, Timer as EphemeralTimer};
|
|||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
use crate::location;
|
use crate::location;
|
||||||
use crate::log::LogExt;
|
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::mimefactory::MimeFactory;
|
||||||
use crate::mimeparser::SystemMessage;
|
use crate::mimeparser::SystemMessage;
|
||||||
use crate::param::{Param, Params};
|
use crate::param::{Param, Params};
|
||||||
@@ -786,7 +786,19 @@ impl ChatId {
|
|||||||
let chat = Chat::load_from_db(context, self).await?;
|
let chat = Chat::load_from_db(context, self).await?;
|
||||||
let sync_id = match sync {
|
let sync_id = match sync {
|
||||||
Nosync => None,
|
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
|
context
|
||||||
|
|||||||
@@ -1738,16 +1738,7 @@ pub async fn delete_msgs_ex(
|
|||||||
modified_chat_ids.insert(msg.chat_id);
|
modified_chat_ids.insert(msg.chat_id);
|
||||||
deleted_rfc724_mid.push(msg.rfc724_mid.clone());
|
deleted_rfc724_mid.push(msg.rfc724_mid.clone());
|
||||||
|
|
||||||
let target = context.get_delete_msgs_target().await?;
|
if let Err(e) = delete_single_msg_from_imap(context, msg).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 {
|
|
||||||
error!(context, "delete_msgs: failed to update db: {e:#}.");
|
error!(context, "delete_msgs: failed to update db: {e:#}.");
|
||||||
res = Err(e);
|
res = Err(e);
|
||||||
continue;
|
continue;
|
||||||
@@ -1788,6 +1779,20 @@ pub async fn delete_msgs_ex(
|
|||||||
Ok(())
|
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.
|
/// Marks requested messages as seen.
|
||||||
pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()> {
|
pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()> {
|
||||||
if msg_ids.is_empty() {
|
if msg_ids.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user