Skip to content

Commit eabf1d1

Browse files
committed
test: Mark not downloaded message as seen (#2970)
Add a test on what happens currently when apps call `markseen_msgs()` for not downloaded encrypted messages. Such messages are marked as seen, but MDNs aren't sent for them. Also currently when such a message is downloaded, it remains `InSeen` despite the full content hasn't yet been seen by the user.
1 parent 3b9e6d6 commit eabf1d1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/message.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,43 @@ mod tests {
25832583
Ok(())
25842584
}
25852585

2586+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2587+
async fn test_markseen_not_downloaded_msg() -> Result<()> {
2588+
let mut tcm = TestContextManager::new();
2589+
let alice = &tcm.alice().await;
2590+
alice.set_config(Config::DownloadLimit, Some("1")).await?;
2591+
let bob = &tcm.bob().await;
2592+
let bob_chat_id = tcm.send_recv_accept(alice, bob, "hi").await.chat_id;
2593+
2594+
let file_bytes = include_bytes!("../test-data/image/screenshot.png");
2595+
let mut msg = Message::new(Viewtype::Image);
2596+
msg.set_file_from_bytes(bob, "a.jpg", file_bytes, None)
2597+
.await?;
2598+
let sent_msg = bob.send_msg(bob_chat_id, &mut msg).await;
2599+
let msg = alice.recv_msg(&sent_msg).await;
2600+
assert_eq!(msg.download_state, DownloadState::Available);
2601+
assert!(!msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
2602+
assert_eq!(msg.state, MessageState::InFresh);
2603+
markseen_msgs(alice, vec![msg.id]).await?;
2604+
let msg = Message::load_from_db(alice, msg.id).await?;
2605+
assert_eq!(msg.state, MessageState::InSeen);
2606+
assert!(
2607+
!alice
2608+
.sql
2609+
.exists("SELECT COUNT(*) FROM smtp_mdns", ())
2610+
.await?
2611+
);
2612+
2613+
alice.set_config(Config::DownloadLimit, None).await?;
2614+
let msg = alice.recv_msg(&sent_msg).await;
2615+
assert_eq!(msg.download_state, DownloadState::Done);
2616+
assert!(msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
2617+
assert!(msg.get_showpadlock());
2618+
assert_eq!(msg.state, MessageState::InSeen);
2619+
2620+
Ok(())
2621+
}
2622+
25862623
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
25872624
async fn test_get_state() -> Result<()> {
25882625
let alice = TestContext::new_alice().await;

0 commit comments

Comments
 (0)