diff --git a/src/chat.rs b/src/chat.rs index 7583eca15..73d98e475 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3993,6 +3993,48 @@ mod tests { Ok(()) } + #[async_std::test] + async fn test_contact_request_archive() -> Result<()> { + let t = TestContext::new_alice().await; + + dc_receive_imf( + &t, + b"From: bob@example.org\n\ + To: alice@example.com\n\ + Message-ID: <2@example.org>\n\ + Chat-Version: 1.0\n\ + Date: Sun, 22 Mar 2021 19:37:57 +0000\n\ + \n\ + hello\n", + "INBOX", + 1, + false, + ) + .await?; + + let chats = Chatlist::try_load(&t, 0, None, None).await?; + assert_eq!(chats.len(), 1); + let chat_id = chats.get_chat_id(0); + assert!(Chat::load_from_db(&t, chat_id).await?.is_contact_request()); + assert_eq!(dc_get_archived_cnt(&t).await?, 0); + + // archive request without accepting or blocking + chat_id.set_visibility(&t, ChatVisibility::Archived).await?; + + let chats = Chatlist::try_load(&t, 0, None, None).await?; + assert_eq!(chats.len(), 1); + let chat_id = chats.get_chat_id(0); + assert!(chat_id.is_archived_link()); + assert_eq!(dc_get_archived_cnt(&t).await?, 1); + + let chats = Chatlist::try_load(&t, DC_GCL_ARCHIVED_ONLY, None, None).await?; + assert_eq!(chats.len(), 1); + let chat_id = chats.get_chat_id(0); + assert!(Chat::load_from_db(&t, chat_id).await?.is_contact_request()); + + Ok(()) + } + #[async_std::test] async fn test_classic_email_chat() -> Result<()> { let alice = TestContext::new_alice().await; diff --git a/src/chatlist.rs b/src/chatlist.rs index 0fc6f1ffd..55cd3e087 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -4,7 +4,7 @@ use anyhow::{bail, ensure, Result}; use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility}; use crate::constants::{ - Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_CONTACT_ID_DEVICE, + Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_CONTACT_ID_DEVICE, DC_CONTACT_ID_SELF, DC_CONTACT_ID_UNDEFINED, DC_GCL_ADD_ALLDONE_HINT, DC_GCL_ARCHIVED_ONLY, DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS, }; @@ -379,8 +379,8 @@ pub async fn dc_get_archived_cnt(context: &Context) -> Result { let count = context .sql .count( - "SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;", - paramsv![], + "SELECT COUNT(*) FROM chats WHERE blocked!=? AND archived=?;", + paramsv![Blocked::Manually, ChatVisibility::Archived], ) .await?; Ok(count) diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index c14054061..734b8fbc3 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -468,6 +468,13 @@ paramsv![] recode_avatar = true; sql.set_db_version(77).await?; } + if dbversion < 78 { + // move requests to "Archived Chats", + // this way, the app looks familiar after the contact request upgrade. + info!(context, "[migration] v78"); + sql.execute_migration("UPDATE chats SET archived=1 WHERE blocked=2;", 78) + .await?; + } Ok(( recalc_fingerprints,