From c1c769ceb03c8feffbe8e875895344f094c5cfd5 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 23 Feb 2020 18:18:38 +0300 Subject: [PATCH] Add MsgId.trash() and use it to delete messages locally In addition to moving the message into trash chat, this function removes message text to make sure the message does not remain in the database. Only the information necessary to delete message from the server and avoid redownloading it should be kept, such as Message-Id and IMAP UID. --- src/message.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/message.rs b/src/message.rs index a06f2a0c2..359e399a3 100644 --- a/src/message.rs +++ b/src/message.rs @@ -85,6 +85,20 @@ impl MsgId { self.0 == DC_MSG_ID_DAYMARKER } + /// Put message into trash chat and delete message text. + /// + /// It means the message is deleted locally, but not on the server + /// yet. + pub fn trash(self, context: &Context) -> crate::sql::Result<()> { + let chat_id = ChatId::new(DC_CHAT_ID_TRASH); + sql::execute( + context, + &context.sql, + "UPDATE msgs SET chat_id=?, txt='', txt_raw='' WHERE id=?", + params![chat_id, self], + ) + } + /// Bad evil escape hatch. /// /// Avoid using this, eventually types should be cleaned up enough @@ -957,7 +971,9 @@ pub fn delete_msgs(context: &Context, msg_ids: &[MsgId]) { delete_poi_location(context, msg.location_id); } } - update_msg_chat_id(context, *msg_id, ChatId::new(DC_CHAT_ID_TRASH)); + if let Err(err) = msg_id.trash(context) { + warn!(context, "Unable to trash message {}: {}", msg_id, err); + } job_add( context, Action::DeleteMsgOnImap, @@ -977,16 +993,6 @@ pub fn delete_msgs(context: &Context, msg_ids: &[MsgId]) { }; } -fn update_msg_chat_id(context: &Context, msg_id: MsgId, chat_id: ChatId) -> bool { - sql::execute( - context, - &context.sql, - "UPDATE msgs SET chat_id=? WHERE id=?;", - params![chat_id, msg_id], - ) - .is_ok() -} - fn delete_poi_location(context: &Context, location_id: u32) -> bool { sql::execute( context,