From c690a644627a957c323570fe7a8875ba7c996935 Mon Sep 17 00:00:00 2001 From: Nico de Haen Date: Sat, 16 Nov 2019 11:04:56 +0100 Subject: [PATCH 1/3] Update msg related location when message is deleted resolves #843 --- src/message.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/message.rs b/src/message.rs index bf4cdfecd..ea5d9a74c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -841,6 +841,12 @@ pub fn get_mime_headers(context: &Context, msg_id: MsgId) -> Option { pub fn delete_msgs(context: &Context, msg_ids: &[MsgId]) { for msg_id in msg_ids.iter() { + if let Ok(msg) = Message::load_from_db(context, *msg_id) { + if msg.location_id > 0 { + update_location_chat_id(context, msg.location_id, DC_CHAT_ID_TRASH); + } + } else { + } update_msg_chat_id(context, *msg_id, DC_CHAT_ID_TRASH); job_add( context, @@ -871,6 +877,16 @@ fn update_msg_chat_id(context: &Context, msg_id: MsgId, chat_id: u32) -> bool { .is_ok() } +fn update_location_chat_id(context: &Context, location_id: u32, chat_id: u32) -> bool { + sql::execute( + context, + &context.sql, + "UPDATE locations SET chat_id=? WHERE id=?;", + params![chat_id as i32, location_id as i32], + ) + .is_ok() +} + pub fn markseen_msgs(context: &Context, msg_ids: &[MsgId]) -> bool { if msg_ids.is_empty() { return false; From 13ff2bd8c403e17816cb2833507cacb85619e238 Mon Sep 17 00:00:00 2001 From: Nico de Haen Date: Sat, 16 Nov 2019 11:28:43 +0100 Subject: [PATCH 2/3] Fix wrong indents --- src/message.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/message.rs b/src/message.rs index ea5d9a74c..49f9e6678 100644 --- a/src/message.rs +++ b/src/message.rs @@ -842,10 +842,9 @@ pub fn get_mime_headers(context: &Context, msg_id: MsgId) -> Option { pub fn delete_msgs(context: &Context, msg_ids: &[MsgId]) { for msg_id in msg_ids.iter() { if let Ok(msg) = Message::load_from_db(context, *msg_id) { - if msg.location_id > 0 { - update_location_chat_id(context, msg.location_id, DC_CHAT_ID_TRASH); - } - } else { + if msg.location_id > 0 { + update_location_chat_id(context, msg.location_id, DC_CHAT_ID_TRASH); + } } update_msg_chat_id(context, *msg_id, DC_CHAT_ID_TRASH); job_add( From e2673894b46be28bbb9dd08522fa0a0b0fe3c646 Mon Sep 17 00:00:00 2001 From: Nico de Haen Date: Sat, 16 Nov 2019 16:55:13 +0100 Subject: [PATCH 3/3] Delete message only if its a POI --- src/message.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/message.rs b/src/message.rs index 49f9e6678..5d362722c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -843,7 +843,7 @@ pub fn delete_msgs(context: &Context, msg_ids: &[MsgId]) { for msg_id in msg_ids.iter() { if let Ok(msg) = Message::load_from_db(context, *msg_id) { if msg.location_id > 0 { - update_location_chat_id(context, msg.location_id, DC_CHAT_ID_TRASH); + delete_poi_location(context, msg.location_id); } } update_msg_chat_id(context, *msg_id, DC_CHAT_ID_TRASH); @@ -876,12 +876,12 @@ fn update_msg_chat_id(context: &Context, msg_id: MsgId, chat_id: u32) -> bool { .is_ok() } -fn update_location_chat_id(context: &Context, location_id: u32, chat_id: u32) -> bool { +fn delete_poi_location(context: &Context, location_id: u32) -> bool { sql::execute( context, &context.sql, - "UPDATE locations SET chat_id=? WHERE id=?;", - params![chat_id as i32, location_id as i32], + "DELETE FROM locations WHERE independent = 1 AND id=?;", + params![location_id as i32], ) .is_ok() }