From b916937a7a50f442e135dd0ada678574b989787f Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 22 Feb 2025 16:58:32 +0000 Subject: [PATCH] feat: enable bcc-self automatically when doing Autocrypt Setup Message --- src/imex.rs | 16 +--------------- src/imex/key_transfer.rs | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/imex.rs b/src/imex.rs index aacc920795..04f908d822 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -15,14 +15,13 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio_tar::Archive; use crate::blob::BlobDirContents; -use crate::chat::{self, delete_and_reset_all_device_msgs}; +use crate::chat::delete_and_reset_all_device_msgs; use crate::config::Config; use crate::context::Context; use crate::e2ee; use crate::events::EventType; use crate::key::{self, DcKey, DcSecretKey, SignedPublicKey, SignedSecretKey}; use crate::log::LogExt; -use crate::message::{Message, Viewtype}; use crate::pgp; use crate::sql; use crate::tools::{ @@ -139,19 +138,6 @@ pub async fn has_backup(_context: &Context, dir_name: &Path) -> Result { } } -async fn maybe_add_bcc_self_device_msg(context: &Context) -> Result<()> { - if !context.sql.get_raw_config_bool("bcc_self").await? { - let mut msg = Message::new(Viewtype::Text); - // TODO: define this as a stockstring once the wording is settled. - msg.text = "It seems you are using multiple devices with Delta Chat. Great!\n\n\ - If you also want to synchronize outgoing messages across all devices, \ - go to \"Settings → Advanced\" and enable \"Send Copy to Self\"." - .to_string(); - chat::add_device_msg(context, Some("bcc-self-hint"), Some(&mut msg)).await?; - } - Ok(()) -} - async fn set_self_key(context: &Context, armored: &str, set_default: bool) -> Result<()> { // try hard to only modify key-state let (private_key, header) = SignedSecretKey::from_asc(armored)?; diff --git a/src/imex/key_transfer.rs b/src/imex/key_transfer.rs index dbe63f9673..ce5d4da4e8 100644 --- a/src/imex/key_transfer.rs +++ b/src/imex/key_transfer.rs @@ -8,7 +8,6 @@ use crate::chat::{self, ChatId}; use crate::config::Config; use crate::contact::ContactId; use crate::context::Context; -use crate::imex::maybe_add_bcc_self_device_msg; use crate::imex::set_self_key; use crate::key::{load_self_secret_key, DcKey}; use crate::message::{Message, MsgId, Viewtype}; @@ -48,11 +47,10 @@ pub async fn initiate_key_transfer(context: &Context) -> Result { msg.param.set_int(Param::SkipAutocrypt, 1); chat::send_msg(context, chat_id, &mut msg).await?; - // no maybe_add_bcc_self_device_msg() here. - // the ui shows the dialog with the setup code on this device, - // it would be too much noise to have two things popping up at the same time. - // maybe_add_bcc_self_device_msg() is called on the other device - // once the transfer is completed. + + // Enable BCC-self, because transferring a key + // means we have a multi-device setup. + context.set_config_bool(Config::BccSelf, true).await?; Ok(setup_code) } @@ -78,7 +76,7 @@ pub async fn continue_key_transfer( let sc = normalize_setup_code(setup_code); let armored_key = decrypt_setup_file(&sc, file).await?; set_self_key(context, &armored_key, true).await?; - maybe_add_bcc_self_device_msg(context).await?; + context.set_config_bool(Config::BccSelf, true).await?; Ok(()) } else { @@ -301,8 +299,12 @@ mod tests { async fn test_key_transfer() -> Result<()> { let alice = TestContext::new_alice().await; + alice.set_config(Config::BccSelf, Some("0")).await?; let setup_code = initiate_key_transfer(&alice).await?; + // Test that sending Autocrypt Setup Message enables `bcc_self`. + assert_eq!(alice.get_config_bool(Config::BccSelf).await?, true); + // Get Autocrypt Setup Message. let sent = alice.pop_sent_msg().await; @@ -322,12 +324,14 @@ mod tests { assert_ne!(alice.get_last_msg().await.get_text(), "Test"); // Transfer the key. + alice2.set_config(Config::BccSelf, Some("0")).await?; continue_key_transfer(&alice2, msg.id, &setup_code).await?; + assert_eq!(alice2.get_config_bool(Config::BccSelf).await?, true); // Alice sends a message to self from the new device. let sent = alice2.send_text(msg.chat_id, "Test").await; - alice.recv_msg(&sent).await; - assert_eq!(alice.get_last_msg().await.get_text(), "Test"); + let rcvd_msg = alice.recv_msg(&sent).await; + assert_eq!(rcvd_msg.get_text(), "Test"); Ok(()) }