From 5fa7cff468b9df616036ce74034b91f42ea35043 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sun, 30 Jun 2024 21:45:11 -0300 Subject: [PATCH] feat: Disable sending sync messages for bots (#5705) If currently there are no multi-device bots, let's disable sync messages for bots at all. Another option is to auto-disable sync messages when `Config::Bot` is set, so sync messages can be reenabled if needed. But let's leave this option for the future. --- src/config.rs | 8 ++++---- src/sync.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index a0728f986..ee993df49 100644 --- a/src/config.rs +++ b/src/config.rs @@ -314,7 +314,8 @@ pub enum Config { #[strum(props(default = "0"))] DownloadLimit, - /// Enable sending and executing (applying) sync messages. Sending requires `BccSelf` to be set. + /// Enable sending and executing (applying) sync messages. Sending requires `BccSelf` to be set + /// and `Bot` unset. #[strum(props(default = "1"))] SyncMsgs, @@ -494,11 +495,10 @@ impl Context { } /// Returns true if sync messages should be sent. - /// - /// This requires that both `SyncMsgs` and `BccSelf` settings are enabled. pub(crate) async fn should_send_sync_msgs(&self) -> Result { Ok(self.get_config_bool(Config::SyncMsgs).await? - && self.get_config_bool(Config::BccSelf).await?) + && self.get_config_bool(Config::BccSelf).await? + && !self.get_config_bool(Config::Bot).await?) } /// Gets configured "delete_server_after" value. diff --git a/src/sync.rs b/src/sync.rs index ff3b7f42e..22a888a73 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -322,7 +322,7 @@ mod tests { use super::*; use crate::chatlist::Chatlist; use crate::contact::{Contact, Origin}; - use crate::test_utils::TestContext; + use crate::test_utils::{TestContext, TestContextManager}; use crate::tools::SystemTime; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -595,4 +595,30 @@ mod tests { Ok(()) } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_bot_no_sync_msgs() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + alice.set_config_bool(Config::SyncMsgs, true).await?; + let chat_id = alice.create_chat(bob).await.id; + + chat::send_text_msg(alice, chat_id, "hi".to_string()).await?; + alice + .set_config(Config::Displayname, Some("Alice Human")) + .await?; + alice.pop_sent_msg().await; // Sync message + let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; + assert_eq!(msg.text, "hi"); + + alice.set_config_bool(Config::Bot, true).await?; + chat::send_text_msg(alice, chat_id, "hi".to_string()).await?; + alice + .set_config(Config::Displayname, Some("Alice Bot")) + .await?; + let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; + assert_eq!(msg.text, "hi"); + Ok(()) + } }