@@ -6,7 +6,6 @@ use pretty_assertions::assert_eq;
66
77use crate :: EventType ;
88use crate :: chat;
9- use crate :: chat:: send_msg;
109use crate :: config:: Config ;
1110use crate :: contact;
1211use crate :: download:: { DownloadState , PRE_MSG_ATTACHMENT_SIZE_THRESHOLD , PostMsgMetadata } ;
@@ -265,6 +264,64 @@ async fn test_lost_pre_msg() -> Result<()> {
265264 Ok ( ( ) )
266265}
267266
267+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
268+ async fn test_pre_msg_mdn_before_sending_full ( ) -> Result < ( ) > {
269+ pre_msg_mdn_before_sending_full ( "" ) . await
270+ }
271+
272+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
273+ async fn test_pre_msg_mdn_before_sending_full_with_text ( ) -> Result < ( ) > {
274+ pre_msg_mdn_before_sending_full ( "text" ) . await
275+ }
276+
277+ async fn pre_msg_mdn_before_sending_full ( text : & str ) -> Result < ( ) > {
278+ let mut tcm = TestContextManager :: new ( ) ;
279+ let alice = & tcm. alice ( ) . await ;
280+ alice
281+ . set_config_bool ( Config :: PopSentMsgFromHead , true )
282+ . await ?;
283+ let bob = & tcm. bob ( ) . await ;
284+ let alice_chat_id = alice. create_group_with_members ( "" , & [ bob] ) . await ;
285+
286+ let file_bytes = include_bytes ! ( "../../../test-data/image/screenshot.gif" ) ;
287+ let mut msg = Message :: new ( Viewtype :: Image ) ;
288+ msg. set_file_from_bytes ( alice, "a.jpg" , file_bytes, None ) ?;
289+ msg. set_text ( text. to_string ( ) ) ;
290+ let pre_msg = alice. send_msg ( alice_chat_id, & mut msg) . await ;
291+ let alice_msg_id = msg. id ;
292+
293+ let msg = bob. recv_msg ( & pre_msg) . await ;
294+ assert_eq ! ( msg. download_state, DownloadState :: Available ) ;
295+ assert_eq ! ( msg. id. get_state( bob) . await ?, MessageState :: InFresh ) ;
296+ assert_eq ! ( msg. text, text) ;
297+ assert ! ( msg. param. get_bool( Param :: WantsMdn ) . unwrap_or_default( ) ) ;
298+ msg. chat_id . accept ( bob) . await ?;
299+ markseen_msgs ( bob, vec ! [ msg. id] ) . await ?;
300+ assert_eq ! ( msg. id. get_state( bob) . await ?, MessageState :: InSeen ) ;
301+ assert_eq ! (
302+ bob. sql
303+ . count(
304+ "SELECT COUNT(*) FROM smtp_mdns WHERE from_id=?" ,
305+ ( msg. from_id, )
306+ )
307+ . await ?,
308+ 1
309+ ) ;
310+ smtp:: queue_mdn ( bob) . await ?;
311+ alice. recv_msg_trash ( & bob. pop_sent_msg ( ) . await ) . await ;
312+ assert_eq ! (
313+ alice_msg_id. get_state( alice) . await ?,
314+ MessageState :: OutPending
315+ ) ;
316+
317+ let _full_msg = alice. pop_sent_msg ( ) . await ;
318+ assert_eq ! (
319+ alice_msg_id. get_state( alice) . await ?,
320+ MessageState :: OutMdnRcvd
321+ ) ;
322+ Ok ( ( ) )
323+ }
324+
268325#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
269326async fn test_post_msg_bad_sender ( ) -> Result < ( ) > {
270327 let mut tcm = TestContextManager :: new ( ) ;
@@ -550,7 +607,7 @@ async fn test_webxdc_updates_in_post_message_after_pre_message() -> Result<()> {
550607 . send_webxdc_status_update ( alice_instance. id , r#"{"payload":42, "info":"i"}"# )
551608 . await ?;
552609
553- send_msg ( alice, alice_chat_id, & mut alice_instance) . await ?;
610+ chat :: send_msg ( alice, alice_chat_id, & mut alice_instance) . await ?;
554611 let post_message = alice. pop_sent_msg ( ) . await ;
555612 let pre_message = alice. pop_sent_msg ( ) . await ;
556613
@@ -591,7 +648,7 @@ async fn test_webxdc_updates_in_post_message_without_pre_message() -> Result<()>
591648 . send_webxdc_status_update ( alice_instance. id , r#"{"payload":42, "info":"i"}"# )
592649 . await ?;
593650
594- send_msg ( alice, alice_chat_id, & mut alice_instance) . await ?;
651+ chat :: send_msg ( alice, alice_chat_id, & mut alice_instance) . await ?;
595652 let post_message = alice. pop_sent_msg ( ) . await ;
596653 let pre_message = alice. pop_sent_msg ( ) . await ;
597654
@@ -644,7 +701,10 @@ async fn test_markseen_pre_msg() -> Result<()> {
644701 assert_eq ! (
645702 alice
646703 . sql
647- . count( "SELECT COUNT(*) FROM smtp_mdns" , ( ) )
704+ . count(
705+ "SELECT COUNT(*) FROM smtp_mdns WHERE from_id=?" ,
706+ ( msg. from_id, )
707+ )
648708 . await ?,
649709 1
650710 ) ;
0 commit comments