mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
feat: Replace Config::SendSyncMsgs with SyncMsgs (#4817)
And execute sync messages only if `Config::SyncMsgs` is enabled. Earlier executing was always enabled, the messages are force-encrypted anyway. But for users it's probably more clear whether a device is synchronised or not.
This commit is contained in:
@@ -270,7 +270,7 @@ describe('Basic offline Tests', function () {
|
|||||||
'quota_exceeding',
|
'quota_exceeding',
|
||||||
'scan_all_folders_debounce_secs',
|
'scan_all_folders_debounce_secs',
|
||||||
'selfavatar',
|
'selfavatar',
|
||||||
'send_sync_msgs',
|
'sync_msgs',
|
||||||
'sentbox_watch',
|
'sentbox_watch',
|
||||||
'show_emails',
|
'show_emails',
|
||||||
'socks5_enabled',
|
'socks5_enabled',
|
||||||
|
|||||||
@@ -297,10 +297,9 @@ pub enum Config {
|
|||||||
#[strum(props(default = "0"))]
|
#[strum(props(default = "0"))]
|
||||||
DownloadLimit,
|
DownloadLimit,
|
||||||
|
|
||||||
/// Send sync messages, requires `BccSelf` to be set as well.
|
/// Enable sending and executing (applying) sync messages. Sending requires `BccSelf` to be set.
|
||||||
/// In a future versions, this switch may be removed.
|
|
||||||
#[strum(props(default = "0"))]
|
#[strum(props(default = "0"))]
|
||||||
SendSyncMsgs,
|
SyncMsgs,
|
||||||
|
|
||||||
/// Space-separated list of all the authserv-ids which we believe
|
/// Space-separated list of all the authserv-ids which we believe
|
||||||
/// may be the one of our email server.
|
/// may be the one of our email server.
|
||||||
@@ -491,7 +490,7 @@ impl Context {
|
|||||||
| Config::Configured
|
| Config::Configured
|
||||||
| Config::Bot
|
| Config::Bot
|
||||||
| Config::NotifyAboutWrongPw
|
| Config::NotifyAboutWrongPw
|
||||||
| Config::SendSyncMsgs
|
| Config::SyncMsgs
|
||||||
| Config::SignUnencrypted
|
| Config::SignUnencrypted
|
||||||
| Config::DisableIdle => {
|
| Config::DisableIdle => {
|
||||||
ensure!(
|
ensure!(
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ impl Context {
|
|||||||
let e2ee_enabled = self.get_config_int(Config::E2eeEnabled).await?;
|
let e2ee_enabled = self.get_config_int(Config::E2eeEnabled).await?;
|
||||||
let mdns_enabled = self.get_config_int(Config::MdnsEnabled).await?;
|
let mdns_enabled = self.get_config_int(Config::MdnsEnabled).await?;
|
||||||
let bcc_self = self.get_config_int(Config::BccSelf).await?;
|
let bcc_self = self.get_config_int(Config::BccSelf).await?;
|
||||||
let send_sync_msgs = self.get_config_int(Config::SendSyncMsgs).await?;
|
let sync_msgs = self.get_config_int(Config::SyncMsgs).await?;
|
||||||
let disable_idle = self.get_config_bool(Config::DisableIdle).await?;
|
let disable_idle = self.get_config_bool(Config::DisableIdle).await?;
|
||||||
|
|
||||||
let prv_key_cnt = self.sql.count("SELECT COUNT(*) FROM keypairs;", ()).await?;
|
let prv_key_cnt = self.sql.count("SELECT COUNT(*) FROM keypairs;", ()).await?;
|
||||||
@@ -697,7 +697,7 @@ impl Context {
|
|||||||
self.get_config_int(Config::KeyGenType).await?.to_string(),
|
self.get_config_int(Config::KeyGenType).await?.to_string(),
|
||||||
);
|
);
|
||||||
res.insert("bcc_self", bcc_self.to_string());
|
res.insert("bcc_self", bcc_self.to_string());
|
||||||
res.insert("send_sync_msgs", send_sync_msgs.to_string());
|
res.insert("sync_msgs", sync_msgs.to_string());
|
||||||
res.insert("disable_idle", disable_idle.to_string());
|
res.insert("disable_idle", disable_idle.to_string());
|
||||||
res.insert("private_key_count", prv_key_cnt.to_string());
|
res.insert("private_key_count", prv_key_cnt.to_string());
|
||||||
res.insert("public_key_count", pub_key_cnt.to_string());
|
res.insert("public_key_count", pub_key_cnt.to_string());
|
||||||
|
|||||||
@@ -1208,6 +1208,9 @@ impl MimeMessage {
|
|||||||
}
|
}
|
||||||
msg_type
|
msg_type
|
||||||
} else if filename == "multi-device-sync.json" {
|
} else if filename == "multi-device-sync.json" {
|
||||||
|
if !context.get_config_bool(Config::SyncMsgs).await? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let serialized = String::from_utf8_lossy(decoded_data)
|
let serialized = String::from_utf8_lossy(decoded_data)
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
30
src/sync.rs
30
src/sync.rs
@@ -43,13 +43,6 @@ pub(crate) struct SyncItems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Checks if sync messages shall be sent.
|
|
||||||
/// Receiving sync messages is currently always enabled;
|
|
||||||
/// the messages are force-encrypted anyway.
|
|
||||||
async fn is_sync_sending_enabled(&self) -> Result<bool> {
|
|
||||||
self.get_config_bool(Config::SendSyncMsgs).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds an item to the list of items that should be synchronized to other devices.
|
/// Adds an item to the list of items that should be synchronized to other devices.
|
||||||
pub(crate) async fn add_sync_item(&self, data: SyncData) -> Result<()> {
|
pub(crate) async fn add_sync_item(&self, data: SyncData) -> Result<()> {
|
||||||
self.add_sync_item_with_timestamp(data, time()).await
|
self.add_sync_item_with_timestamp(data, time()).await
|
||||||
@@ -58,7 +51,7 @@ impl Context {
|
|||||||
/// Adds item and timestamp to the list of items that should be synchronized to other devices.
|
/// Adds item and timestamp to the list of items that should be synchronized to other devices.
|
||||||
/// If device synchronization is disabled, the function does nothing.
|
/// If device synchronization is disabled, the function does nothing.
|
||||||
async fn add_sync_item_with_timestamp(&self, data: SyncData, timestamp: i64) -> Result<()> {
|
async fn add_sync_item_with_timestamp(&self, data: SyncData, timestamp: i64) -> Result<()> {
|
||||||
if !self.is_sync_sending_enabled().await? {
|
if !self.get_config_bool(Config::SyncMsgs).await? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +68,7 @@ impl Context {
|
|||||||
/// If device synchronization is disabled,
|
/// If device synchronization is disabled,
|
||||||
/// no tokens exist or the chat is unpromoted, the function does nothing.
|
/// no tokens exist or the chat is unpromoted, the function does nothing.
|
||||||
pub(crate) async fn sync_qr_code_tokens(&self, chat_id: Option<ChatId>) -> Result<()> {
|
pub(crate) async fn sync_qr_code_tokens(&self, chat_id: Option<ChatId>) -> Result<()> {
|
||||||
if !self.is_sync_sending_enabled().await? {
|
if !self.get_config_bool(Config::SyncMsgs).await? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,20 +260,20 @@ mod tests {
|
|||||||
use crate::token::Namespace;
|
use crate::token::Namespace;
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_is_sync_sending_enabled() -> Result<()> {
|
async fn test_config_sync_msgs() -> Result<()> {
|
||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
assert!(!t.is_sync_sending_enabled().await?);
|
assert!(!t.get_config_bool(Config::SyncMsgs).await?);
|
||||||
t.set_config_bool(Config::SendSyncMsgs, true).await?;
|
t.set_config_bool(Config::SyncMsgs, true).await?;
|
||||||
assert!(t.is_sync_sending_enabled().await?);
|
assert!(t.get_config_bool(Config::SyncMsgs).await?);
|
||||||
t.set_config_bool(Config::SendSyncMsgs, false).await?;
|
t.set_config_bool(Config::SyncMsgs, false).await?;
|
||||||
assert!(!t.is_sync_sending_enabled().await?);
|
assert!(!t.get_config_bool(Config::SyncMsgs).await?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_build_sync_json() -> Result<()> {
|
async fn test_build_sync_json() -> Result<()> {
|
||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
t.set_config_bool(Config::SendSyncMsgs, true).await?;
|
t.set_config_bool(Config::SyncMsgs, true).await?;
|
||||||
|
|
||||||
assert!(t.build_sync_json().await?.is_none());
|
assert!(t.build_sync_json().await?.is_none());
|
||||||
|
|
||||||
@@ -325,7 +318,7 @@ mod tests {
|
|||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_build_sync_json_sync_msgs_off() -> Result<()> {
|
async fn test_build_sync_json_sync_msgs_off() -> Result<()> {
|
||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
t.set_config_bool(Config::SendSyncMsgs, false).await?;
|
t.set_config_bool(Config::SyncMsgs, false).await?;
|
||||||
t.add_sync_item(SyncData::AddQrToken(QrTokenData {
|
t.add_sync_item(SyncData::AddQrToken(QrTokenData {
|
||||||
invitenumber: "testinvite".to_string(),
|
invitenumber: "testinvite".to_string(),
|
||||||
auth: "testauth".to_string(),
|
auth: "testauth".to_string(),
|
||||||
@@ -453,7 +446,7 @@ mod tests {
|
|||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_send_sync_msg() -> Result<()> {
|
async fn test_send_sync_msg() -> Result<()> {
|
||||||
let alice = TestContext::new_alice().await;
|
let alice = TestContext::new_alice().await;
|
||||||
alice.set_config_bool(Config::SendSyncMsgs, true).await?;
|
alice.set_config_bool(Config::SyncMsgs, true).await?;
|
||||||
alice
|
alice
|
||||||
.add_sync_item(SyncData::AddQrToken(QrTokenData {
|
.add_sync_item(SyncData::AddQrToken(QrTokenData {
|
||||||
invitenumber: "in".to_string(),
|
invitenumber: "in".to_string(),
|
||||||
@@ -480,6 +473,7 @@ mod tests {
|
|||||||
// also here, self-talk should stay hidden
|
// also here, self-talk should stay hidden
|
||||||
let sent_msg = alice.pop_sent_msg().await;
|
let sent_msg = alice.pop_sent_msg().await;
|
||||||
let alice2 = TestContext::new_alice().await;
|
let alice2 = TestContext::new_alice().await;
|
||||||
|
alice2.set_config_bool(Config::SyncMsgs, true).await?;
|
||||||
alice2.recv_msg(&sent_msg).await;
|
alice2.recv_msg(&sent_msg).await;
|
||||||
assert!(token::exists(&alice2, token::Namespace::Auth, "testtoken").await);
|
assert!(token::exists(&alice2, token::Namespace::Auth, "testtoken").await);
|
||||||
assert_eq!(Chatlist::try_load(&alice2, 0, None, None).await?.len(), 0);
|
assert_eq!(Chatlist::try_load(&alice2, 0, None, None).await?.len(), 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user