@@ -715,8 +715,9 @@ pub(crate) async fn start_ephemeral_timers(context: &Context) -> Result<()> {
715
715
#[ cfg( test) ]
716
716
mod tests {
717
717
use super :: * ;
718
- use crate :: chat:: marknoticed_chat;
718
+ use crate :: chat:: { marknoticed_chat, set_muted , ChatVisibility , MuteDuration } ;
719
719
use crate :: config:: Config ;
720
+ use crate :: constants:: DC_CHAT_ID_ARCHIVED_LINK ;
720
721
use crate :: download:: DownloadState ;
721
722
use crate :: location;
722
723
use crate :: message:: markseen_msgs;
@@ -1468,4 +1469,52 @@ mod tests {
1468
1469
. is_none( ) ) ;
1469
1470
Ok ( ( ) )
1470
1471
}
1472
+
1473
+ /// Tests that archiving the chat starts ephemeral timer.
1474
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1475
+ async fn test_archived_ephemeral_timer ( ) -> Result < ( ) > {
1476
+ let mut tcm = TestContextManager :: new ( ) ;
1477
+ let alice = & tcm. alice ( ) . await ;
1478
+ let bob = & tcm. bob ( ) . await ;
1479
+
1480
+ let chat = alice. create_chat ( bob) . await ;
1481
+ let duration = 60 ;
1482
+ chat. id
1483
+ . set_ephemeral_timer ( alice, Timer :: Enabled { duration } )
1484
+ . await ?;
1485
+ let bob_received_message = tcm. send_recv ( alice, bob, "Hello!" ) . await ;
1486
+
1487
+ bob_received_message
1488
+ . chat_id
1489
+ . set_visibility ( bob, ChatVisibility :: Archived )
1490
+ . await ?;
1491
+ SystemTime :: shift ( Duration :: from_secs ( 100 ) ) ;
1492
+
1493
+ delete_expired_messages ( bob, time ( ) ) . await ?;
1494
+
1495
+ assert ! ( Message :: load_from_db_optional( bob, bob_received_message. id)
1496
+ . await ?
1497
+ . is_none( ) ) ;
1498
+
1499
+ // Bob mutes the chat so it is not unarchived.
1500
+ set_muted ( bob, bob_received_message. chat_id , MuteDuration :: Forever ) . await ?;
1501
+
1502
+ // Now test that for already archived chat
1503
+ // timer is started if all archived chats are marked as noticed.
1504
+ let bob_received_message_2 = tcm. send_recv ( alice, bob, "Hello again!" ) . await ;
1505
+ assert_eq ! ( bob_received_message_2. state, MessageState :: InFresh ) ;
1506
+
1507
+ marknoticed_chat ( bob, DC_CHAT_ID_ARCHIVED_LINK ) . await ?;
1508
+ SystemTime :: shift ( Duration :: from_secs ( 100 ) ) ;
1509
+
1510
+ delete_expired_messages ( bob, time ( ) ) . await ?;
1511
+
1512
+ assert ! (
1513
+ Message :: load_from_db_optional( bob, bob_received_message_2. id)
1514
+ . await ?
1515
+ . is_none( )
1516
+ ) ;
1517
+
1518
+ Ok ( ( ) )
1519
+ }
1471
1520
}
0 commit comments