Skip to content

Commit 4c6888d

Browse files
committed
Simplify the logic
- Get rid of `Config::DonationRequestMsgCnt` and geometric progression, limit requests to one per 60 days instead. - Don't filter out trashed messages, if a message is sent, the app is used.
1 parent ca2d90a commit 4c6888d

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

src/chat.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,36 +3231,32 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
32313231
}
32323232

32333233
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;
32353236
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 {
32413239
let msg_cnt = context
32423240
.sql
32433241
.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,),
32473244
)
32483245
.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 {
32543250
let mut msg = Message::new_text(stock_str::donation_request(context).await);
32553251
add_device_msg(context, None, Some(&mut msg)).await?;
3252+
now.saturating_add(period_msg)
32563253
}
3257-
true
32583254
} else {
3259-
request_ts > now
3255+
cmp::min(ts, now.saturating_add(period_msg))
32603256
};
3261-
if update_config {
3257+
if ts_new != ts {
32623258
context
3263-
.set_config_internal(Config::DonationRequestTs, Some(&now.to_string()))
3259+
.set_config_internal(Config::DonationRequestTs, Some(&ts_new.to_string()))
32643260
.await?;
32653261
}
32663262
Ok(())

src/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,9 @@ pub enum Config {
369369
#[strum(props(default = "0"))]
370370
DisableIdle,
371371

372-
/// Timestamp of the last check for donation request need.
372+
/// Timestamp of the next check for donation request need.
373373
DonationRequestTs,
374374

375-
/// Number of outgoing encrypted messages at the time of the last donation request.
376-
DonationRequestMsgCnt,
377-
378375
/// Defines the max. size (in bytes) of messages downloaded automatically.
379376
/// 0 = no limit.
380377
#[strum(props(default = "0"))]

src/context.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,6 @@ impl Context {
10381038
.await?
10391039
.to_string(),
10401040
);
1041-
res.insert(
1042-
"donation_request_msg_cnt",
1043-
self.get_config_u64(Config::DonationRequestMsgCnt)
1044-
.await?
1045-
.to_string(),
1046-
);
10471041

10481042
let elapsed = time_elapsed(&self.creation_time);
10491043
res.insert("uptime", duration_to_str(elapsed));

0 commit comments

Comments
 (0)