@@ -3231,36 +3231,32 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
3231
3231
}
3232
3232
3233
3233
async fn donation_request_maybe ( context : & Context ) -> Result < ( ) > {
3234
- let request_ts = context. get_config_i64 ( Config :: DonationRequestTs ) . await ?;
3234
+ let period_check = 14 * 24 * 60 * 60 ;
3235
+ let period_msg = 60 * 24 * 60 * 60 ;
3235
3236
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 ) ;
3237
+ let ts = context. get_config_i64 ( Config :: DonationRequestTs ) . await ?;
3238
+ let ts_new = if ts <= now {
3241
3239
let msg_cnt = context
3242
3240
. sql
3243
3241
. count (
3244
- "SELECT COUNT(*) FROM msgs
3245
- WHERE state>=? AND hidden=0 AND chat_id!=? AND param GLOB \" *c=*\" " ,
3246
- ( MessageState :: OutDelivered , DC_CHAT_ID_TRASH ) ,
3242
+ "SELECT COUNT(*) FROM msgs WHERE state>=? AND hidden=0 AND param GLOB \" *c=*\" " ,
3243
+ ( MessageState :: OutDelivered , ) ,
3247
3244
)
3248
3245
. await ?;
3249
- // 10, 30, 70...
3250
- if msg_cnt_prev < msg_cnt. saturating_sub ( 8 ) / 2 {
3251
- context
3252
- . set_config_internal ( Config :: DonationRequestMsgCnt , Some ( & msg_cnt. to_string ( ) ) )
3253
- . await ?;
3246
+ if msg_cnt < 10 {
3247
+ // New users go here, so they won't get the message immediately.
3248
+ now. saturating_add ( period_check)
3249
+ } else {
3254
3250
let mut msg = Message :: new_text ( stock_str:: donation_request ( context) . await ) ;
3255
3251
add_device_msg ( context, None , Some ( & mut msg) ) . await ?;
3252
+ now. saturating_add ( period_msg)
3256
3253
}
3257
- true
3258
3254
} else {
3259
- request_ts > now
3255
+ cmp :: min ( ts , now. saturating_add ( period_msg ) )
3260
3256
} ;
3261
- if update_config {
3257
+ if ts_new != ts {
3262
3258
context
3263
- . set_config_internal ( Config :: DonationRequestTs , Some ( & now . to_string ( ) ) )
3259
+ . set_config_internal ( Config :: DonationRequestTs , Some ( & ts_new . to_string ( ) ) )
3264
3260
. await ?;
3265
3261
}
3266
3262
Ok ( ( ) )
0 commit comments