Generate rfc724_mid when creating Message (#6704)

Set `rfc724_mid` in `Message::new()`, `Message::new_text()`, and
`Message::default()` instead of when sending the message. This way the
rfc724 mid can be read in the draft stage which makes it more consistent
for bots. Tests had to be adjusted to create multiple messages to get
unique mid, otherwise core would not send the messages out.
This commit is contained in:
Sebastian Klähn
2025-05-05 17:06:05 +02:00
committed by GitHub
parent 98a1b9e373
commit 846c8e7f1b
9 changed files with 57 additions and 22 deletions

View File

@@ -2040,20 +2040,28 @@ async fn test_sticker_forward() -> Result<()> {
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_forward() -> Result<()> {
async fn test_forward_basic() -> Result<()> {
let alice = TestContext::new_alice().await;
let bob = TestContext::new_bob().await;
let alice_chat = alice.create_chat(&bob).await;
let bob_chat = bob.create_chat(&alice).await;
let mut msg = Message::new_text("Hi Bob".to_owned());
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await;
let mut alice_msg = Message::new_text("Hi Bob".to_owned());
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut alice_msg).await;
let msg = bob.recv_msg(&sent_msg).await;
assert_eq!(alice_msg.rfc724_mid, msg.rfc724_mid);
forward_msgs(&bob, &[msg.id], bob_chat.get_id()).await?;
let forwarded_msg = bob.pop_sent_msg().await;
assert_eq!(bob_chat.id.get_msg_cnt(&bob).await?, 2);
assert_ne!(
forwarded_msg.load_from_db().await.rfc724_mid,
msg.rfc724_mid,
);
let msg_bob = Message::load_from_db(&bob, forwarded_msg.sender_msg_id).await?;
let msg = alice.recv_msg(&forwarded_msg).await;
assert_eq!(msg.rfc724_mid(), msg_bob.rfc724_mid());
assert_eq!(msg.get_text(), "Hi Bob");
assert!(msg.is_forwarded());
Ok(())