@@ -3464,16 +3464,19 @@ pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec
3464
3464
3465
3465
/// Returns a vector of contact IDs for given chat ID that are no longer part of the group.
3466
3466
pub async fn get_past_chat_contacts ( context : & Context , chat_id : ChatId ) -> Result < Vec < ContactId > > {
3467
+ let now = time ( ) ;
3467
3468
let list = context
3468
3469
. sql
3469
3470
. query_map (
3470
3471
"SELECT cc.contact_id
3471
3472
FROM chats_contacts cc
3472
3473
LEFT JOIN contacts c
3473
3474
ON c.id=cc.contact_id
3474
- WHERE cc.chat_id=? AND cc.add_timestamp < cc.remove_timestamp
3475
+ WHERE cc.chat_id=?
3476
+ AND cc.add_timestamp < cc.remove_timestamp
3477
+ AND ? < cc.remove_timestamp
3475
3478
ORDER BY c.id=1, c.last_seen DESC, c.id DESC" ,
3476
- ( chat_id, ) ,
3479
+ ( chat_id, now . saturating_sub ( 60 * 24 * 3600 ) ) ,
3477
3480
|row| row. get :: < _ , ContactId > ( 0 ) ,
3478
3481
|ids| ids. collect :: < Result < Vec < _ > , _ > > ( ) . map_err ( Into :: into) ,
3479
3482
)
@@ -7896,4 +7899,40 @@ mod tests {
7896
7899
7897
7900
Ok ( ( ) )
7898
7901
}
7902
+
7903
+ /// Test that past members expire after 60 days.
7904
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
7905
+ async fn test_expire_past_members_after_60_days ( ) -> Result < ( ) > {
7906
+ let mut tcm = TestContextManager :: new ( ) ;
7907
+
7908
+ let alice = & tcm. alice ( ) . await ;
7909
+ let fiona_addr =
"[email protected] " ;
7910
+ let alice_fiona_contact_id = Contact :: create ( alice, "Fiona" , fiona_addr) . await ?;
7911
+
7912
+ let alice_chat_id =
7913
+ create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
7914
+ add_contact_to_chat ( alice, alice_chat_id, alice_fiona_contact_id) . await ?;
7915
+ alice
7916
+ . send_text ( alice_chat_id, "Hi! I created a group." )
7917
+ . await ;
7918
+ remove_contact_from_chat ( alice, alice_chat_id, alice_fiona_contact_id) . await ?;
7919
+ assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 1 ) ;
7920
+
7921
+ SystemTime :: shift ( Duration :: from_secs ( 60 * 24 * 60 * 60 + 1 ) ) ;
7922
+ assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 0 ) ;
7923
+
7924
+ let bob = & tcm. bob ( ) . await ;
7925
+ let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
7926
+ let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
7927
+ add_contact_to_chat ( alice, alice_chat_id, alice_bob_contact_id) . await ?;
7928
+
7929
+ let add_message = alice. pop_sent_msg ( ) . await ;
7930
+ assert_eq ! ( add_message. payload. contains( fiona_addr) , false ) ;
7931
+ let bob_add_message = bob. recv_msg ( & add_message) . await ;
7932
+ let bob_chat_id = bob_add_message. chat_id ;
7933
+ assert_eq ! ( get_chat_contacts( bob, bob_chat_id) . await ?. len( ) , 2 ) ;
7934
+ assert_eq ! ( get_past_chat_contacts( bob, bob_chat_id) . await ?. len( ) , 0 ) ;
7935
+
7936
+ Ok ( ( ) )
7937
+ }
7899
7938
}
0 commit comments