@@ -117,6 +117,9 @@ pub async fn maybe_send_self_report(context: &Context) -> Result<Option<ChatId>>
117
117
118
118
async fn send_self_report ( context : & Context ) -> Result < ChatId > {
119
119
info ! ( context, "Sending self report." ) ;
120
+
121
+ let last_selfreport_time = context. get_config_i64 ( Config :: LastSelfReportSent ) . await ?;
122
+
120
123
// Setting this config at the beginning avoids endless loops when things do not
121
124
// work out for whatever reason.
122
125
context
@@ -135,10 +138,13 @@ This helps us improve the security of Delta Chat. \
135
138
See TODO[blog post] for more information."
136
139
. to_string ( ) ,
137
140
) ;
141
+
142
+ let self_report = get_self_report ( context, last_selfreport_time) . await ?;
143
+
138
144
msg. set_file_from_bytes (
139
145
context,
140
146
"statistics.txt" ,
141
- get_self_report ( context ) . await ? . as_bytes ( ) ,
147
+ self_report . as_bytes ( ) ,
142
148
Some ( "text/plain" ) ,
143
149
) ?;
144
150
@@ -151,7 +157,7 @@ See TODO[blog post] for more information."
151
157
Ok ( chat_id)
152
158
}
153
159
154
- async fn get_self_report ( context : & Context ) -> Result < String > {
160
+ async fn get_self_report ( context : & Context , last_selfreport_time : i64 ) -> Result < String > {
155
161
let num_msgs: u32 = context
156
162
. sql
157
163
. query_get_value (
@@ -257,7 +263,7 @@ async fn get_self_report(context: &Context) -> Result<String> {
257
263
chat_numbers,
258
264
self_reporting_id,
259
265
contact_stats : get_contact_stats ( context) . await ?,
260
- message_stats : get_message_stats ( context) . await ?,
266
+ message_stats : get_message_stats ( context, last_selfreport_time ) . await ?,
261
267
securejoin_source_stats : get_securejoin_source_stats ( context) . await ?,
262
268
} ;
263
269
@@ -394,11 +400,17 @@ async fn get_contact_stats(context: &Context) -> Result<Vec<ContactStat>> {
394
400
Ok ( contacts)
395
401
}
396
402
397
- async fn get_message_stats ( context : & Context ) -> Result < MessageStats > {
403
+ async fn get_message_stats (
404
+ context : & Context ,
405
+ mut last_selfreport_time : i64 ,
406
+ ) -> Result < MessageStats > {
398
407
let enabled_ts: i64 = context
399
408
. get_config_i64 ( Config :: SelfReportingEnabledTimestamp )
400
409
. await ?;
401
- ensure ! ( enabled_ts > 0 , "Enabled Timestamp missing" ) ;
410
+ if last_selfreport_time == 0 {
411
+ last_selfreport_time = enabled_ts;
412
+ }
413
+ ensure ! ( last_selfreport_time > 0 , "Enabled Timestamp missing" ) ;
402
414
403
415
let selfreporting_bot_chat_id = get_selfreporting_bot ( context) . await ?;
404
416
@@ -422,7 +434,7 @@ async fn get_message_stats(context: &Context) -> Result<MessageStats> {
422
434
"SELECT COUNT(*) FROM msgs
423
435
WHERE chat_id IN temp.verified_chats
424
436
AND chat_id<>? AND id>9 AND timestamp_sent>?" ,
425
- ( selfreporting_bot_chat_id, enabled_ts ) ,
437
+ ( selfreporting_bot_chat_id, last_selfreport_time ) ,
426
438
|row| row. get ( 0 ) ,
427
439
) ?;
428
440
@@ -431,7 +443,7 @@ async fn get_message_stats(context: &Context) -> Result<MessageStats> {
431
443
WHERE chat_id not IN temp.verified_chats
432
444
AND (param GLOB '*\n c=1*' OR param GLOB 'c=1*')
433
445
AND chat_id<>? AND id>9 AND timestamp_sent>?" ,
434
- ( selfreporting_bot_chat_id, enabled_ts ) ,
446
+ ( selfreporting_bot_chat_id, last_selfreport_time ) ,
435
447
|row| row. get ( 0 ) ,
436
448
) ?;
437
449
@@ -440,7 +452,7 @@ async fn get_message_stats(context: &Context) -> Result<MessageStats> {
440
452
WHERE chat_id not IN temp.verified_chats
441
453
AND NOT (param GLOB '*\n c=1*' OR param GLOB 'c=1*')
442
454
AND chat_id<>? AND id>9 AND timestamp_sent>=?" ,
443
- ( selfreporting_bot_chat_id, enabled_ts ) ,
455
+ ( selfreporting_bot_chat_id, last_selfreport_time ) ,
444
456
|row| row. get ( 0 ) ,
445
457
) ?;
446
458
0 commit comments