| 346 | } |
| 347 | |
| 348 | async fn get_stats(context: &Context) -> Result<String> { |
| 349 | // The Id of the last contact that already existed when the user enabled the setting. |
| 350 | // Newer contacts will get the `new` flag set. |
| 351 | let last_old_contact = context |
| 352 | .get_config_u32(Config::StatsLastOldContactId) |
| 353 | .await?; |
| 354 | |
| 355 | let self_public_key = load_self_public_key(context).await?; |
| 356 | // `key_create_timestamps` is a `Vec` for historical reasons, |
| 357 | // support for using multiple keys is being phased out. |
| 358 | let key_create_timestamps: Vec<u32> = vec![self_public_key.created_at().as_secs()]; |
| 359 | let number_of_keys: u32 = context |
| 360 | .sql |
| 361 | .query_get_value("SELECT COUNT(*) FROM keypairs", ()) |
| 362 | .await? |
| 363 | .unwrap_or(0); |
| 364 | |
| 365 | let sending_enabled_timestamps = |
| 366 | get_timestamps(context, "stats_sending_enabled_events").await?; |
| 367 | let sending_disabled_timestamps = |
| 368 | get_timestamps(context, "stats_sending_disabled_events").await?; |
| 369 | |
| 370 | let stats = Statistics { |
| 371 | core_version: DC_VERSION_STR.to_string(), |
| 372 | number_of_transports: context.count_transports().await?, |
| 373 | key_create_timestamps, |
| 374 | number_of_keys, |
| 375 | key_version: self_public_key.primary_key.version().into(), |
| 376 | key_algorithm: format!("{:?}", self_public_key.algorithm()), |
| 377 | pubkey_size: DcKey::to_bytes(&self_public_key).len(), |
| 378 | stats_id: stats_id(context).await?, |
| 379 | is_chatmail: context.is_chatmail().await?, |
| 380 | contact_stats: get_contact_stats(context, last_old_contact).await?, |
| 381 | message_stats: get_message_stats(context).await?, |
| 382 | securejoin_sources: get_securejoin_source_stats(context).await?, |
| 383 | securejoin_uipaths: get_securejoin_uipath_stats(context).await?, |
| 384 | securejoin_invites: get_securejoin_invite_stats(context).await?, |
| 385 | sending_enabled_timestamps, |
| 386 | sending_disabled_timestamps, |
| 387 | }; |
| 388 | |
| 389 | Ok(serde_json::to_string_pretty(&stats)?) |
| 390 | } |
| 391 | |
| 392 | async fn get_timestamps(context: &Context, sql_table: &str) -> Result<Vec<i64>> { |
| 393 | context |