Skip to content

Commit b916937

Browse files
committed
feat: enable bcc-self automatically when doing Autocrypt Setup Message
1 parent 3d7ac9d commit b916937

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/imex.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1515
use tokio_tar::Archive;
1616

1717
use crate::blob::BlobDirContents;
18-
use crate::chat::{self, delete_and_reset_all_device_msgs};
18+
use crate::chat::delete_and_reset_all_device_msgs;
1919
use crate::config::Config;
2020
use crate::context::Context;
2121
use crate::e2ee;
2222
use crate::events::EventType;
2323
use crate::key::{self, DcKey, DcSecretKey, SignedPublicKey, SignedSecretKey};
2424
use crate::log::LogExt;
25-
use crate::message::{Message, Viewtype};
2625
use crate::pgp;
2726
use crate::sql;
2827
use crate::tools::{
@@ -139,19 +138,6 @@ pub async fn has_backup(_context: &Context, dir_name: &Path) -> Result<String> {
139138
}
140139
}
141140

142-
async fn maybe_add_bcc_self_device_msg(context: &Context) -> Result<()> {
143-
if !context.sql.get_raw_config_bool("bcc_self").await? {
144-
let mut msg = Message::new(Viewtype::Text);
145-
// TODO: define this as a stockstring once the wording is settled.
146-
msg.text = "It seems you are using multiple devices with Delta Chat. Great!\n\n\
147-
If you also want to synchronize outgoing messages across all devices, \
148-
go to \"Settings → Advanced\" and enable \"Send Copy to Self\"."
149-
.to_string();
150-
chat::add_device_msg(context, Some("bcc-self-hint"), Some(&mut msg)).await?;
151-
}
152-
Ok(())
153-
}
154-
155141
async fn set_self_key(context: &Context, armored: &str, set_default: bool) -> Result<()> {
156142
// try hard to only modify key-state
157143
let (private_key, header) = SignedSecretKey::from_asc(armored)?;

src/imex/key_transfer.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::chat::{self, ChatId};
88
use crate::config::Config;
99
use crate::contact::ContactId;
1010
use crate::context::Context;
11-
use crate::imex::maybe_add_bcc_self_device_msg;
1211
use crate::imex::set_self_key;
1312
use crate::key::{load_self_secret_key, DcKey};
1413
use crate::message::{Message, MsgId, Viewtype};
@@ -48,11 +47,10 @@ pub async fn initiate_key_transfer(context: &Context) -> Result<String> {
4847
msg.param.set_int(Param::SkipAutocrypt, 1);
4948

5049
chat::send_msg(context, chat_id, &mut msg).await?;
51-
// no maybe_add_bcc_self_device_msg() here.
52-
// the ui shows the dialog with the setup code on this device,
53-
// it would be too much noise to have two things popping up at the same time.
54-
// maybe_add_bcc_self_device_msg() is called on the other device
55-
// once the transfer is completed.
50+
51+
// Enable BCC-self, because transferring a key
52+
// means we have a multi-device setup.
53+
context.set_config_bool(Config::BccSelf, true).await?;
5654
Ok(setup_code)
5755
}
5856

@@ -78,7 +76,7 @@ pub async fn continue_key_transfer(
7876
let sc = normalize_setup_code(setup_code);
7977
let armored_key = decrypt_setup_file(&sc, file).await?;
8078
set_self_key(context, &armored_key, true).await?;
81-
maybe_add_bcc_self_device_msg(context).await?;
79+
context.set_config_bool(Config::BccSelf, true).await?;
8280

8381
Ok(())
8482
} else {
@@ -301,8 +299,12 @@ mod tests {
301299
async fn test_key_transfer() -> Result<()> {
302300
let alice = TestContext::new_alice().await;
303301

302+
alice.set_config(Config::BccSelf, Some("0")).await?;
304303
let setup_code = initiate_key_transfer(&alice).await?;
305304

305+
// Test that sending Autocrypt Setup Message enables `bcc_self`.
306+
assert_eq!(alice.get_config_bool(Config::BccSelf).await?, true);
307+
306308
// Get Autocrypt Setup Message.
307309
let sent = alice.pop_sent_msg().await;
308310

@@ -322,12 +324,14 @@ mod tests {
322324
assert_ne!(alice.get_last_msg().await.get_text(), "Test");
323325

324326
// Transfer the key.
327+
alice2.set_config(Config::BccSelf, Some("0")).await?;
325328
continue_key_transfer(&alice2, msg.id, &setup_code).await?;
329+
assert_eq!(alice2.get_config_bool(Config::BccSelf).await?, true);
326330

327331
// Alice sends a message to self from the new device.
328332
let sent = alice2.send_text(msg.chat_id, "Test").await;
329-
alice.recv_msg(&sent).await;
330-
assert_eq!(alice.get_last_msg().await.get_text(), "Test");
333+
let rcvd_msg = alice.recv_msg(&sent).await;
334+
assert_eq!(rcvd_msg.get_text(), "Test");
331335

332336
Ok(())
333337
}

0 commit comments

Comments
 (0)