Skip to content

Commit

Permalink
fix: Set Param::Bot for messages on the sender side as well (#5615)
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed May 27, 2024
1 parent d29538b commit adb0dd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
23 changes: 23 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit adb0dd4

Please sign in to comment.