From adb0dd43a7161fa43d49860ae095e12417bf8a1c Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sun, 26 May 2024 15:16:02 -0300 Subject: [PATCH] fix: Set Param::Bot for messages on the sender side as well (#5615) --- src/chat.rs | 4 ++++ src/receive_imf/tests.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 33818350b2..f2ab035828 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1932,6 +1932,10 @@ impl Chat { // reset encrypt error state eg. for forwarding msg.param.remove(Param::ErroneousE2ee); + let is_bot = context.get_config_bool(Config::Bot).await?; + msg.param + .set_optional(Param::Bot, Some("1").filter(|_| is_bot)); + // Set "In-Reply-To:" to identify the message to which the composed message is a reply. // Set "References:" to identify the "thread" of the conversation. // Both according to [RFC 5322 3.6.4, page 25](https://www.rfc-editor.org/rfc/rfc5322#section-3.6.4). diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 38d0d4eff8..a973d34047 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -3213,6 +3213,29 @@ async fn test_auto_accept_group_for_bots() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_send_as_bot() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + alice.set_config(Config::Bot, Some("1")).await.unwrap(); + let bob = &tcm.bob().await; + let bob_addr = bob.get_config(Config::Addr).await?.unwrap(); + let alice_bob_id = Contact::create(alice, "", &bob_addr).await?; + let bob_chat_id = tcm.send_recv_accept(alice, bob, "hi").await.chat_id; + let alice_chat_id = ChatId::lookup_by_contact(alice, alice_bob_id) + .await? + .unwrap(); + let msg = alice.get_last_msg_in(alice_chat_id).await; + assert!(msg.is_bot()); + let msg = bob.get_last_msg_in(bob_chat_id).await; + assert!(msg.is_bot()); + chat::forward_msgs(bob, &[msg.id], bob_chat_id).await?; + let msg = bob.get_last_msg_in(bob_chat_id).await; + assert!(msg.is_forwarded()); + assert!(!msg.is_bot()); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_no_private_reply_to_blocked_account() -> Result<()> { let mut tcm = TestContextManager::new();