@@ -4,6 +4,7 @@ use pretty_assertions::assert_eq;
44
55use crate :: EventType ;
66use crate :: chat;
7+ use crate :: config:: Config ;
78use crate :: contact;
89use crate :: download:: { DownloadState , PRE_MSG_ATTACHMENT_SIZE_THRESHOLD , PostMsgMetadata } ;
910use crate :: message:: { Message , MessageState , Viewtype , delete_msgs, markseen_msgs} ;
@@ -253,6 +254,64 @@ async fn test_lost_pre_msg() -> Result<()> {
253254 Ok ( ( ) )
254255}
255256
257+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
258+ async fn test_pre_msg_mdn_before_sending_full ( ) -> Result < ( ) > {
259+ pre_msg_mdn_before_sending_full ( "" ) . await
260+ }
261+
262+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
263+ async fn test_pre_msg_mdn_before_sending_full_with_text ( ) -> Result < ( ) > {
264+ pre_msg_mdn_before_sending_full ( "text" ) . await
265+ }
266+
267+ async fn pre_msg_mdn_before_sending_full ( text : & str ) -> Result < ( ) > {
268+ let mut tcm = TestContextManager :: new ( ) ;
269+ let alice = & tcm. alice ( ) . await ;
270+ alice
271+ . set_config_bool ( Config :: PopSentMsgFromHead , true )
272+ . await ?;
273+ let bob = & tcm. bob ( ) . await ;
274+ let alice_chat_id = alice. create_group_with_members ( "" , & [ bob] ) . await ;
275+
276+ let file_bytes = include_bytes ! ( "../../../test-data/image/screenshot.gif" ) ;
277+ let mut msg = Message :: new ( Viewtype :: Image ) ;
278+ msg. set_file_from_bytes ( alice, "a.jpg" , file_bytes, None ) ?;
279+ msg. set_text ( text. to_string ( ) ) ;
280+ let pre_msg = alice. send_msg ( alice_chat_id, & mut msg) . await ;
281+ let alice_msg_id = msg. id ;
282+
283+ let msg = bob. recv_msg ( & pre_msg) . await ;
284+ assert_eq ! ( msg. download_state, DownloadState :: Available ) ;
285+ assert_eq ! ( msg. id. get_state( bob) . await ?, MessageState :: InFresh ) ;
286+ assert_eq ! ( msg. text, text) ;
287+ assert ! ( msg. param. get_bool( Param :: WantsMdn ) . unwrap_or_default( ) ) ;
288+ msg. chat_id . accept ( bob) . await ?;
289+ markseen_msgs ( bob, vec ! [ msg. id] ) . await ?;
290+ assert_eq ! ( msg. id. get_state( bob) . await ?, MessageState :: InSeen ) ;
291+ assert_eq ! (
292+ bob. sql
293+ . count(
294+ "SELECT COUNT(*) FROM smtp_mdns WHERE from_id=?" ,
295+ ( msg. from_id, )
296+ )
297+ . await ?,
298+ 1
299+ ) ;
300+ smtp:: queue_mdn ( bob) . await ?;
301+ alice. recv_msg_trash ( & bob. pop_sent_msg ( ) . await ) . await ;
302+ assert_eq ! (
303+ alice_msg_id. get_state( alice) . await ?,
304+ MessageState :: OutPending
305+ ) ;
306+
307+ let _full_msg = alice. pop_sent_msg ( ) . await ;
308+ assert_eq ! (
309+ alice_msg_id. get_state( alice) . await ?,
310+ MessageState :: OutMdnRcvd
311+ ) ;
312+ Ok ( ( ) )
313+ }
314+
256315#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
257316async fn test_post_msg_bad_sender ( ) -> Result < ( ) > {
258317 let mut tcm = TestContextManager :: new ( ) ;
@@ -539,7 +598,10 @@ async fn test_markseen_pre_msg() -> Result<()> {
539598 assert_eq ! (
540599 alice
541600 . sql
542- . count( "SELECT COUNT(*) FROM smtp_mdns" , ( ) )
601+ . count(
602+ "SELECT COUNT(*) FROM smtp_mdns WHERE from_id=?" ,
603+ ( msg. from_id, )
604+ )
543605 . await ?,
544606 1
545607 ) ;
0 commit comments