@@ -2983,6 +2983,9 @@ async fn prepare_send_msg(
29832983    let  row_ids = create_send_msg_jobs ( context,  msg) 
29842984        . await 
29852985        . context ( "Failed to create send jobs" ) ?; 
2986+     if  !row_ids. is_empty ( )  { 
2987+         donation_request_maybe ( context) . await . log_err ( context) . ok ( ) ; 
2988+     } 
29862989    Ok ( row_ids) 
29872990} 
29882991
@@ -3227,6 +3230,43 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
32273230    send_msg ( context,  chat_id,  & mut  msg) . await 
32283231} 
32293232
3233+ async  fn  donation_request_maybe ( context :  & Context )  -> Result < ( ) >  { 
3234+     let  request_ts = context. get_config_i64 ( Config :: DonationRequestTs ) . await ?; 
3235+     let  now = time ( ) ; 
3236+     let  update_config = if  request_ts. saturating_add ( 14  *  24  *  60  *  60 )  <= now { 
3237+         let  msg_cnt_prev = context
3238+             . get_config_parsed ( Config :: DonationRequestMsgCnt ) 
3239+             . await ?
3240+             . unwrap_or ( 0 ) ; 
3241+         let  msg_cnt = context
3242+             . sql 
3243+             . count ( 
3244+                 " 
3245+                 SELECT COUNT(*) FROM msgs 
3246+                 WHERE state>=? AND hidden=0 AND chat_id!=? AND param GLOB \" *c=*\" " , 
3247+                 ( MessageState :: OutDelivered ,  DC_CHAT_ID_TRASH ) , 
3248+             ) 
3249+             . await ?; 
3250+         // 10, 30, 70... 
3251+         if  msg_cnt_prev < msg_cnt. saturating_sub ( 8 )  / 2  { 
3252+             context
3253+                 . set_config_internal ( Config :: DonationRequestMsgCnt ,  Some ( & msg_cnt. to_string ( ) ) ) 
3254+                 . await ?; 
3255+             let  mut  msg = Message :: new_text ( stock_str:: donation_request ( context) . await ) ; 
3256+             add_device_msg ( context,  None ,  Some ( & mut  msg) ) . await ?; 
3257+         } 
3258+         true 
3259+     }  else  { 
3260+         request_ts > now
3261+     } ; 
3262+     if  update_config { 
3263+         context
3264+             . set_config_internal ( Config :: DonationRequestTs ,  Some ( & now. to_string ( ) ) ) 
3265+             . await ?; 
3266+     } 
3267+     Ok ( ( ) ) 
3268+ } 
3269+ 
32303270/// Chat message list request options. 
32313271#[ derive( Debug ) ]  
32323272pub  struct  MessageListOptions  { 
0 commit comments