From 838957baddf88c0fad5ada7642ad3e4a5bd04bc3 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 20 Jun 2021 00:00:00 +0000 Subject: [PATCH] Do not hide classic emails from contact requests on setting change Since classical messages are not deleted when show_emails setting is set to "0" and remain in the database, they should be shown somewhere. Otherwise they may reappear later when the setting is enabled again. --- src/chat.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 00e4837eb..4e795c10a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -8,7 +8,6 @@ use anyhow::{bail, ensure, format_err, Context as _, Result}; use async_std::path::{Path, PathBuf}; use deltachat_derive::{FromSql, ToSql}; use itertools::Itertools; -use num_traits::FromPrimitive; use serde::{Deserialize, Serialize}; use crate::aheader::EncryptPreference; @@ -17,7 +16,7 @@ use crate::chatlist::dc_get_archived_cnt; use crate::color::str_to_color; use crate::config::Config; use crate::constants::{ - Blocked, Chattype, ShowEmails, Viewtype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, + Blocked, Chattype, Viewtype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_CHAT_ID_DEADDROP, DC_CHAT_ID_LAST_SPECIAL, DC_CHAT_ID_TRASH, DC_CONTACT_ID_DEVICE, DC_CONTACT_ID_INFO, DC_CONTACT_ID_LAST_SPECIAL, DC_CONTACT_ID_SELF, DC_GCM_ADDDAYMARKER, DC_GCM_INFO_ONLY, DC_RESEND_USER_AVATAR_DAYS, @@ -1941,8 +1940,6 @@ pub async fn get_chat_msgs( }; let items = if chat_id.is_deaddrop() { - let show_emails = ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await?) - .unwrap_or_default(); context .sql .query_map( @@ -1957,13 +1954,8 @@ pub async fn get_chat_msgs( AND m.hidden=0 AND chats.blocked=2 AND contacts.blocked=0 - AND m.msgrmsg>=? ORDER BY m.timestamp,m.id;", - paramsv![if show_emails == ShowEmails::All { - 0i32 - } else { - 1i32 - }], + paramsv![], process_row, process_rows, ) @@ -4065,6 +4057,52 @@ mod tests { Ok(()) } + #[async_std::test] + async fn test_classic_deaddrop_chat() -> Result<()> { + let alice = TestContext::new_alice().await; + + // Alice enables receiving classic emails. + alice + .set_config(Config::ShowEmails, Some("2")) + .await + .unwrap(); + + // Alice receives a classic (non-chat) message from Bob. + dc_receive_imf( + &alice, + b"From: bob@example.org\n\ + To: alice@example.com\n\ + Message-ID: <1@example.org>\n\ + Date: Sun, 22 Mar 2021 19:37:57 +0000\n\ + \n\ + hello\n", + "INBOX", + 1, + false, + ) + .await?; + + // There is one message in the contact requests chat. + assert_eq!(DC_CHAT_ID_DEADDROP.get_fresh_msg_cnt(&alice).await?, 1); + + let msgs = get_chat_msgs(&alice, DC_CHAT_ID_DEADDROP, 0, None).await?; + assert_eq!(msgs.len(), 1); + + // Alice disables receiving classic emails. + alice + .set_config(Config::ShowEmails, Some("0")) + .await + .unwrap(); + + // Already received classic email should still be in the contact requests. + assert_eq!(DC_CHAT_ID_DEADDROP.get_fresh_msg_cnt(&alice).await?, 1); + + let msgs = get_chat_msgs(&alice, DC_CHAT_ID_DEADDROP, 0, None).await?; + assert_eq!(msgs.len(), 1); + + Ok(()) + } + async fn test_sticker(filename: &str, bytes: &[u8], w: i32, h: i32) -> Result<()> { let alice = TestContext::new_alice().await; let bob = TestContext::new_bob().await;