mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
feat: enable bcc-self automatically when doing Autocrypt Setup Message
This commit is contained in:
16
src/imex.rs
16
src/imex.rs
@@ -15,14 +15,13 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
|||||||
use tokio_tar::Archive;
|
use tokio_tar::Archive;
|
||||||
|
|
||||||
use crate::blob::BlobDirContents;
|
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::config::Config;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::e2ee;
|
use crate::e2ee;
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
use crate::key::{self, DcKey, DcSecretKey, SignedPublicKey, SignedSecretKey};
|
use crate::key::{self, DcKey, DcSecretKey, SignedPublicKey, SignedSecretKey};
|
||||||
use crate::log::LogExt;
|
use crate::log::LogExt;
|
||||||
use crate::message::{Message, Viewtype};
|
|
||||||
use crate::pgp;
|
use crate::pgp;
|
||||||
use crate::sql;
|
use crate::sql;
|
||||||
use crate::tools::{
|
use crate::tools::{
|
||||||
@@ -139,19 +138,6 @@ pub async fn has_backup(_context: &Context, dir_name: &Path) -> Result<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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<()> {
|
async fn set_self_key(context: &Context, armored: &str, set_default: bool) -> Result<()> {
|
||||||
// try hard to only modify key-state
|
// try hard to only modify key-state
|
||||||
let (private_key, header) = SignedSecretKey::from_asc(armored)?;
|
let (private_key, header) = SignedSecretKey::from_asc(armored)?;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use crate::chat::{self, ChatId};
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::imex::maybe_add_bcc_self_device_msg;
|
|
||||||
use crate::imex::set_self_key;
|
use crate::imex::set_self_key;
|
||||||
use crate::key::{load_self_secret_key, DcKey};
|
use crate::key::{load_self_secret_key, DcKey};
|
||||||
use crate::message::{Message, MsgId, Viewtype};
|
use crate::message::{Message, MsgId, Viewtype};
|
||||||
@@ -48,11 +47,10 @@ pub async fn initiate_key_transfer(context: &Context) -> Result<String> {
|
|||||||
msg.param.set_int(Param::SkipAutocrypt, 1);
|
msg.param.set_int(Param::SkipAutocrypt, 1);
|
||||||
|
|
||||||
chat::send_msg(context, chat_id, &mut msg).await?;
|
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,
|
// Enable BCC-self, because transferring a key
|
||||||
// it would be too much noise to have two things popping up at the same time.
|
// means we have a multi-device setup.
|
||||||
// maybe_add_bcc_self_device_msg() is called on the other device
|
context.set_config_bool(Config::BccSelf, true).await?;
|
||||||
// once the transfer is completed.
|
|
||||||
Ok(setup_code)
|
Ok(setup_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +76,7 @@ pub async fn continue_key_transfer(
|
|||||||
let sc = normalize_setup_code(setup_code);
|
let sc = normalize_setup_code(setup_code);
|
||||||
let armored_key = decrypt_setup_file(&sc, file).await?;
|
let armored_key = decrypt_setup_file(&sc, file).await?;
|
||||||
set_self_key(context, &armored_key, true).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(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@@ -301,8 +299,12 @@ mod tests {
|
|||||||
async fn test_key_transfer() -> Result<()> {
|
async fn test_key_transfer() -> Result<()> {
|
||||||
let alice = TestContext::new_alice().await;
|
let alice = TestContext::new_alice().await;
|
||||||
|
|
||||||
|
alice.set_config(Config::BccSelf, Some("0")).await?;
|
||||||
let setup_code = initiate_key_transfer(&alice).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.
|
// Get Autocrypt Setup Message.
|
||||||
let sent = alice.pop_sent_msg().await;
|
let sent = alice.pop_sent_msg().await;
|
||||||
|
|
||||||
@@ -322,12 +324,14 @@ mod tests {
|
|||||||
assert_ne!(alice.get_last_msg().await.get_text(), "Test");
|
assert_ne!(alice.get_last_msg().await.get_text(), "Test");
|
||||||
|
|
||||||
// Transfer the key.
|
// Transfer the key.
|
||||||
|
alice2.set_config(Config::BccSelf, Some("0")).await?;
|
||||||
continue_key_transfer(&alice2, msg.id, &setup_code).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.
|
// Alice sends a message to self from the new device.
|
||||||
let sent = alice2.send_text(msg.chat_id, "Test").await;
|
let sent = alice2.send_text(msg.chat_id, "Test").await;
|
||||||
alice.recv_msg(&sent).await;
|
let rcvd_msg = alice.recv_msg(&sent).await;
|
||||||
assert_eq!(alice.get_last_msg().await.get_text(), "Test");
|
assert_eq!(rcvd_msg.get_text(), "Test");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user