@@ -10,35 +10,30 @@ use std::time::Duration;
10
10
11
11
use anyhow:: { Context as _, Result , bail, ensure} ;
12
12
use async_channel:: { self as channel, Receiver , Sender } ;
13
- use pgp:: types:: PublicKeyTrait ;
14
13
use ratelimit:: Ratelimit ;
15
14
use tokio:: sync:: { Mutex , Notify , RwLock } ;
16
15
17
- use crate :: chat:: { ChatId , ProtectionStatus , get_chat_cnt} ;
16
+ use crate :: chat:: { ChatId , get_chat_cnt} ;
18
17
use crate :: chatlist_events;
19
18
use crate :: config:: Config ;
20
- use crate :: constants:: {
21
- self , DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT , DC_CHAT_ID_TRASH , DC_VERSION_STR ,
22
- } ;
23
- use crate :: contact:: { Contact , ContactId , import_vcard, mark_contact_id_as_verified} ;
19
+ use crate :: constants:: { self , DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT , DC_VERSION_STR } ;
20
+ use crate :: contact:: { Contact , ContactId } ;
24
21
use crate :: debug_logging:: DebugLogging ;
25
- use crate :: download:: DownloadState ;
26
22
use crate :: events:: { Event , EventEmitter , EventType , Events } ;
27
23
use crate :: imap:: { FolderMeaning , Imap , ServerMetadata } ;
28
- use crate :: key:: { load_self_secret_key , self_fingerprint} ;
24
+ use crate :: key:: self_fingerprint;
29
25
use crate :: log:: { info, warn} ;
30
26
use crate :: logged_debug_assert;
31
27
use crate :: login_param:: { ConfiguredLoginParam , EnteredLoginParam } ;
32
- use crate :: message:: { self , Message , MessageState , MsgId } ;
33
- use crate :: param:: { Param , Params } ;
28
+ use crate :: message:: { self , MessageState , MsgId } ;
34
29
use crate :: peer_channels:: Iroh ;
35
30
use crate :: push:: PushSubscriber ;
36
31
use crate :: quota:: QuotaInfo ;
37
32
use crate :: scheduler:: { SchedulerState , convert_folder_meaning} ;
38
33
use crate :: sql:: Sql ;
39
34
use crate :: stock_str:: StockStrings ;
40
35
use crate :: timesmearing:: SmearedTimestamp ;
41
- use crate :: tools:: { self , create_id , duration_to_str, time, time_elapsed} ;
36
+ use crate :: tools:: { self , duration_to_str, time, time_elapsed} ;
42
37
43
38
/// Builder for the [`Context`].
44
39
///
@@ -1076,154 +1071,31 @@ impl Context {
1076
1071
. await ?
1077
1072
. unwrap_or_default ( ) ,
1078
1073
) ;
1074
+ res. insert (
1075
+ "statistics_id" ,
1076
+ self . get_config_bool ( Config :: StatisticsId )
1077
+ . await ?
1078
+ . to_string ( ) ,
1079
+ ) ;
1080
+ res. insert (
1081
+ "send_statistics" ,
1082
+ self . get_config_bool ( Config :: SendStatistics )
1083
+ . await ?
1084
+ . to_string ( ) ,
1085
+ ) ;
1086
+ res. insert (
1087
+ "last_statistics_sent" ,
1088
+ self . get_config_i64 ( Config :: LastStatisticsSent )
1089
+ . await ?
1090
+ . to_string ( ) ,
1091
+ ) ;
1079
1092
1080
1093
let elapsed = time_elapsed ( & self . creation_time ) ;
1081
1094
res. insert ( "uptime" , duration_to_str ( elapsed) ) ;
1082
1095
1083
1096
Ok ( res)
1084
1097
}
1085
1098
1086
- async fn get_self_report ( & self ) -> Result < String > {
1087
- #[ derive( Default ) ]
1088
- struct ChatNumbers {
1089
- protected : u32 ,
1090
- opportunistic_dc : u32 ,
1091
- opportunistic_mua : u32 ,
1092
- unencrypted_dc : u32 ,
1093
- unencrypted_mua : u32 ,
1094
- }
1095
-
1096
- let mut res = String :: new ( ) ;
1097
- res += & format ! ( "core_version {}\n " , get_version_str( ) ) ;
1098
-
1099
- let num_msgs: u32 = self
1100
- . sql
1101
- . query_get_value (
1102
- "SELECT COUNT(*) FROM msgs WHERE hidden=0 AND chat_id!=?" ,
1103
- ( DC_CHAT_ID_TRASH , ) ,
1104
- )
1105
- . await ?
1106
- . unwrap_or_default ( ) ;
1107
- res += & format ! ( "num_msgs {num_msgs}\n " ) ;
1108
-
1109
- let num_chats: u32 = self
1110
- . sql
1111
- . query_get_value ( "SELECT COUNT(*) FROM chats WHERE id>9 AND blocked!=1" , ( ) )
1112
- . await ?
1113
- . unwrap_or_default ( ) ;
1114
- res += & format ! ( "num_chats {num_chats}\n " ) ;
1115
-
1116
- let db_size = tokio:: fs:: metadata ( & self . sql . dbfile ) . await ?. len ( ) ;
1117
- res += & format ! ( "db_size_bytes {db_size}\n " ) ;
1118
-
1119
- let secret_key = & load_self_secret_key ( self ) . await ?. primary_key ;
1120
- let key_created = secret_key. public_key ( ) . created_at ( ) . timestamp ( ) ;
1121
- res += & format ! ( "key_created {key_created}\n " ) ;
1122
-
1123
- // how many of the chats active in the last months are:
1124
- // - protected
1125
- // - opportunistic-encrypted and the contact uses Delta Chat
1126
- // - opportunistic-encrypted and the contact uses a classical MUA
1127
- // - unencrypted and the contact uses Delta Chat
1128
- // - unencrypted and the contact uses a classical MUA
1129
- let three_months_ago = time ( ) . saturating_sub ( 3600 * 24 * 30 * 3 ) ;
1130
- let chats = self
1131
- . sql
1132
- . query_map (
1133
- "SELECT c.protected, m.param, m.msgrmsg
1134
- FROM chats c
1135
- JOIN msgs m
1136
- ON c.id=m.chat_id
1137
- AND m.id=(
1138
- SELECT id
1139
- FROM msgs
1140
- WHERE chat_id=c.id
1141
- AND hidden=0
1142
- AND download_state=?
1143
- AND to_id!=?
1144
- ORDER BY timestamp DESC, id DESC LIMIT 1)
1145
- WHERE c.id>9
1146
- AND (c.blocked=0 OR c.blocked=2)
1147
- AND IFNULL(m.timestamp,c.created_timestamp) > ?
1148
- GROUP BY c.id" ,
1149
- ( DownloadState :: Done , ContactId :: INFO , three_months_ago) ,
1150
- |row| {
1151
- let protected: ProtectionStatus = row. get ( 0 ) ?;
1152
- let message_param: Params =
1153
- row. get :: < _ , String > ( 1 ) ?. parse ( ) . unwrap_or_default ( ) ;
1154
- let is_dc_message: bool = row. get ( 2 ) ?;
1155
- Ok ( ( protected, message_param, is_dc_message) )
1156
- } ,
1157
- |rows| {
1158
- let mut chats = ChatNumbers :: default ( ) ;
1159
- for row in rows {
1160
- let ( protected, message_param, is_dc_message) = row?;
1161
- let encrypted = message_param
1162
- . get_bool ( Param :: GuaranteeE2ee )
1163
- . unwrap_or ( false ) ;
1164
-
1165
- if protected == ProtectionStatus :: Protected {
1166
- chats. protected += 1 ;
1167
- } else if encrypted {
1168
- if is_dc_message {
1169
- chats. opportunistic_dc += 1 ;
1170
- } else {
1171
- chats. opportunistic_mua += 1 ;
1172
- }
1173
- } else if is_dc_message {
1174
- chats. unencrypted_dc += 1 ;
1175
- } else {
1176
- chats. unencrypted_mua += 1 ;
1177
- }
1178
- }
1179
- Ok ( chats)
1180
- } ,
1181
- )
1182
- . await ?;
1183
- res += & format ! ( "chats_protected {}\n " , chats. protected) ;
1184
- res += & format ! ( "chats_opportunistic_dc {}\n " , chats. opportunistic_dc) ;
1185
- res += & format ! ( "chats_opportunistic_mua {}\n " , chats. opportunistic_mua) ;
1186
- res += & format ! ( "chats_unencrypted_dc {}\n " , chats. unencrypted_dc) ;
1187
- res += & format ! ( "chats_unencrypted_mua {}\n " , chats. unencrypted_mua) ;
1188
-
1189
- let self_reporting_id = match self . get_config ( Config :: SelfReportingId ) . await ? {
1190
- Some ( id) => id,
1191
- None => {
1192
- let id = create_id ( ) ;
1193
- self . set_config ( Config :: SelfReportingId , Some ( & id) ) . await ?;
1194
- id
1195
- }
1196
- } ;
1197
- res += & format ! ( "self_reporting_id {self_reporting_id}" ) ;
1198
-
1199
- Ok ( res)
1200
- }
1201
-
1202
- /// Drafts a message with statistics about the usage of Delta Chat.
1203
- /// The user can inspect the message if they want, and then hit "Send".
1204
- ///
1205
- /// On the other end, a bot will receive the message and make it available
1206
- /// to Delta Chat's developers.
1207
- pub async fn draft_self_report ( & self ) -> Result < ChatId > {
1208
- const SELF_REPORTING_BOT_VCARD : & str = include_str ! ( "../assets/self-reporting-bot.vcf" ) ;
1209
- let contact_id: ContactId = * import_vcard ( self , SELF_REPORTING_BOT_VCARD )
1210
- . await ?
1211
- . first ( )
1212
- . context ( "Self reporting bot vCard does not contain a contact" ) ?;
1213
- mark_contact_id_as_verified ( self , contact_id, ContactId :: SELF ) . await ?;
1214
-
1215
- let chat_id = ChatId :: create_for_contact ( self , contact_id) . await ?;
1216
- chat_id
1217
- . set_protection ( self , ProtectionStatus :: Protected , time ( ) , Some ( contact_id) )
1218
- . await ?;
1219
-
1220
- let mut msg = Message :: new_text ( self . get_self_report ( ) . await ?) ;
1221
-
1222
- chat_id. set_draft ( self , Some ( & mut msg) ) . await ?;
1223
-
1224
- Ok ( chat_id)
1225
- }
1226
-
1227
1099
/// Get a list of fresh, unmuted messages in unblocked chats.
1228
1100
///
1229
1101
/// The list starts with the most recent message
0 commit comments