Skip to content

Commit 5b98030

Browse files
committed
small renames
1 parent b1c57ee commit 5b98030

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use tokio::fs;
1414

1515
use crate::blob::BlobObject;
1616
use crate::configure::EnteredLoginParam;
17-
use crate::constants;
1817
use crate::context::Context;
1918
use crate::events::EventType;
2019
use crate::log::{LogExt, info};
@@ -23,6 +22,7 @@ use crate::mimefactory::RECOMMENDED_FILE_SIZE;
2322
use crate::provider::{Provider, get_provider_by_id};
2423
use crate::sync::{self, Sync::*, SyncData};
2524
use crate::tools::get_abs_path;
25+
use crate::{constants, statistics};
2626

2727
/// The available configuration keys.
2828
#[derive(
@@ -846,8 +846,8 @@ impl Context {
846846
}
847847
Config::SendStatistics => {
848848
self.sql.set_raw_config(key.as_ref(), value).await?;
849-
crate::statistics::set_last_excluded_msg_id(self).await?;
850-
crate::statistics::set_last_old_contact_id(self).await?;
849+
statistics::set_last_excluded_msg_id(self).await?;
850+
statistics::set_last_old_contact_id(self).await?;
851851
}
852852
_ => {
853853
self.sql.set_raw_config(key.as_ref(), value).await?;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub mod html;
9898
pub mod net;
9999
pub mod plaintext;
100100
mod push;
101-
pub mod statistics;
101+
pub(crate) mod statistics;
102102
pub mod summary;
103103

104104
mod debug_logging;

src/securejoin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ pub async fn join_securejoin(context: &Context, qr: &str) -> Result<ChatId> {
156156
/// for more details.
157157
///
158158
/// The function returns immediately and the handshake will run in background.
159+
///
160+
/// **source** and **uipath** are for statistics-sending,
161+
/// if the user enabled it in the settings;
162+
/// if you don't have statistics-sending implemented, just pass `None` here.
159163
pub async fn join_securejoin_with_source(
160164
context: &Context,
161165
qr: &str,

src/sql/migrations.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,15 +1264,15 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
12641264
inc_and_check(&mut migration_version, 134)?;
12651265
if dbversion < migration_version {
12661266
sql.execute_migration(
1267-
"CREATE TABLE stats_securejoin_sources(
1267+
"CREATE TABLE statistics_securejoin_sources(
12681268
source INTEGER PRIMARY KEY,
12691269
count INTEGER NOT NULL DEFAULT 0
12701270
) STRICT;
1271-
CREATE TABLE stats_securejoin_uipaths(
1271+
CREATE TABLE statistics_securejoin_uipaths(
12721272
uipath INTEGER PRIMARY KEY,
12731273
count INTEGER NOT NULL DEFAULT 0
12741274
) STRICT;
1275-
CREATE TABLE stats_securejoin_invites(
1275+
CREATE TABLE statistics_securejoin_invites(
12761276
contact_created INTEGER NOT NULL,
12771277
already_verified INTEGER NOT NULL,
12781278
type TEXT NOT NULL

src/statistics.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ struct Statistics {
3333
contact_stats: Vec<ContactStat>,
3434
message_stats_one_one: MessageStats,
3535
message_stats_multi_user: MessageStats,
36-
securejoin_source_stats: SecurejoinSourceStats,
37-
securejoin_uipath_stats: SecurejoinUIPathStats,
38-
securejoin_invites_stats: Vec<JoinedInvite>,
36+
securejoin_sources: SecurejoinSources,
37+
securejoin_uipaths: SecurejoinUIPaths,
38+
securejoin_invites: Vec<JoinedInvite>,
3939
}
4040

4141
#[derive(Serialize, PartialEq)]
@@ -84,7 +84,7 @@ enum SecurejoinSource {
8484
}
8585

8686
#[derive(Serialize)]
87-
struct SecurejoinSourceStats {
87+
struct SecurejoinSources {
8888
unknown: u32,
8989
external_link: u32,
9090
internal_link: u32,
@@ -101,7 +101,7 @@ enum SecurejoinUIPath {
101101
}
102102

103103
#[derive(Serialize)]
104-
struct SecurejoinUIPathStats {
104+
struct SecurejoinUIPaths {
105105
other: u32,
106106
qr_icon: u32,
107107
new_contact: u32,
@@ -155,7 +155,7 @@ See TODO[blog post] for more information."
155155
Some("text/plain"),
156156
)?;
157157

158-
crate::chat::send_msg(context, chat_id, &mut msg)
158+
chat::send_msg(context, chat_id, &mut msg)
159159
.await
160160
.context("Failed to send statistics message")
161161
.log_err(context)
@@ -240,9 +240,9 @@ async fn get_statistics(context: &Context) -> Result<String> {
240240
contact_stats: get_contact_stats(context, last_old_contact).await?,
241241
message_stats_one_one: get_message_stats(context, last_excluded_msg, true).await?,
242242
message_stats_multi_user: get_message_stats(context, last_excluded_msg, false).await?,
243-
securejoin_source_stats: get_securejoin_source_stats(context).await?,
244-
securejoin_uipath_stats: get_securejoin_uipath_stats(context).await?,
245-
securejoin_invites_stats: get_securejoin_invite_stats(context).await?,
243+
securejoin_sources: get_securejoin_source_stats(context).await?,
244+
securejoin_uipaths: get_securejoin_uipath_stats(context).await?,
245+
securejoin_invites: get_securejoin_invite_stats(context).await?,
246246
};
247247

248248
Ok(serde_json::to_string_pretty(&statistics)?)
@@ -556,7 +556,7 @@ pub(crate) async fn count_securejoin_source(
556556
context
557557
.sql
558558
.execute(
559-
"INSERT INTO stats_securejoin_sources VALUES (?, 1)
559+
"INSERT INTO statistics_securejoin_sources VALUES (?, 1)
560560
ON CONFLICT (source) DO UPDATE SET count=count+1;",
561561
(source,),
562562
)
@@ -569,19 +569,19 @@ pub(crate) async fn count_securejoin_source(
569569
context
570570
.sql
571571
.execute(
572-
"INSERT INTO stats_securejoin_uipaths VALUES (?, 1)
572+
"INSERT INTO statistics_securejoin_uipaths VALUES (?, 1)
573573
ON CONFLICT (uipath) DO UPDATE SET count=count+1;",
574574
(uipath,),
575575
)
576576
.await?;
577577
Ok(())
578578
}
579579

580-
async fn get_securejoin_source_stats(context: &Context) -> Result<SecurejoinSourceStats> {
580+
async fn get_securejoin_source_stats(context: &Context) -> Result<SecurejoinSources> {
581581
let map = context
582582
.sql
583583
.query_map(
584-
"SELECT source, count FROM stats_securejoin_sources",
584+
"SELECT source, count FROM statistics_securejoin_sources",
585585
(),
586586
|row| {
587587
let source: SecurejoinSource = row.get(0)?;
@@ -592,7 +592,7 @@ async fn get_securejoin_source_stats(context: &Context) -> Result<SecurejoinSour
592592
)
593593
.await?;
594594

595-
let stats = SecurejoinSourceStats {
595+
let stats = SecurejoinSources {
596596
unknown: *map.get(&SecurejoinSource::Unknown).unwrap_or(&0),
597597
external_link: *map.get(&SecurejoinSource::ExternalLink).unwrap_or(&0),
598598
internal_link: *map.get(&SecurejoinSource::InternalLink).unwrap_or(&0),
@@ -604,11 +604,11 @@ async fn get_securejoin_source_stats(context: &Context) -> Result<SecurejoinSour
604604
Ok(stats)
605605
}
606606

607-
async fn get_securejoin_uipath_stats(context: &Context) -> Result<SecurejoinUIPathStats> {
607+
async fn get_securejoin_uipath_stats(context: &Context) -> Result<SecurejoinUIPaths> {
608608
let map = context
609609
.sql
610610
.query_map(
611-
"SELECT uipath, count FROM stats_securejoin_uipaths",
611+
"SELECT uipath, count FROM statistics_securejoin_uipaths",
612612
(),
613613
|row| {
614614
let uipath: SecurejoinUIPath = row.get(0)?;
@@ -619,7 +619,7 @@ async fn get_securejoin_uipath_stats(context: &Context) -> Result<SecurejoinUIPa
619619
)
620620
.await?;
621621

622-
let stats = SecurejoinUIPathStats {
622+
let stats = SecurejoinUIPaths {
623623
other: *map.get(&SecurejoinUIPath::Unknown).unwrap_or(&0),
624624
qr_icon: *map.get(&SecurejoinUIPath::QrIcon).unwrap_or(&0),
625625
new_contact: *map.get(&SecurejoinUIPath::NewContact).unwrap_or(&0),
@@ -653,7 +653,7 @@ pub(crate) async fn count_securejoin_invite(context: &Context, invite: &QrInvite
653653
context
654654
.sql
655655
.execute(
656-
"INSERT INTO stats_securejoin_invites (contact_created, already_verified, type)
656+
"INSERT INTO statistics_securejoin_invites (contact_created, already_verified, type)
657657
VALUES (?, ?, ?)",
658658
(contact_created, already_verified, typ),
659659
)
@@ -683,7 +683,7 @@ async fn get_securejoin_invite_stats(context: &Context) -> Result<Vec<JoinedInvi
683683
let qr_scans: Vec<JoinedInvite> = context
684684
.sql
685685
.query_map(
686-
"SELECT contact_created, already_verified, type FROM stats_securejoin_invites",
686+
"SELECT contact_created, already_verified, type FROM statistics_securejoin_invites",
687687
(),
688688
|row| {
689689
let contact_created: bool = row.get(0)?;

src/statistics/statistics_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ async fn send_and_read_statistics(context: &TestContext) -> String {
252252
}
253253

254254
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
255-
async fn test_statistics_securejoin_source_stats() -> Result<()> {
256-
async fn check_statistics(context: &TestContext, expected: &SecurejoinSourceStats) {
255+
async fn test_statistics_securejoin_sources() -> Result<()> {
256+
async fn check_statistics(context: &TestContext, expected: &SecurejoinSources) {
257257
let statistics = get_statistics(context).await.unwrap();
258258
let actual: serde_json::Value = serde_json::from_str(&statistics).unwrap();
259-
let actual = &actual["securejoin_source_stats"];
259+
let actual = &actual["securejoin_sources"];
260260

261261
let expected = serde_json::to_string_pretty(&expected).unwrap();
262262
let expected: serde_json::Value = serde_json::from_str(&expected).unwrap();
@@ -269,7 +269,7 @@ async fn test_statistics_securejoin_source_stats() -> Result<()> {
269269
let bob = &tcm.bob().await;
270270
alice.set_config_bool(Config::SendStatistics, true).await?;
271271

272-
let mut expected = SecurejoinSourceStats {
272+
let mut expected = SecurejoinSources {
273273
unknown: 0,
274274
external_link: 0,
275275
internal_link: 0,
@@ -335,11 +335,11 @@ async fn test_statistics_securejoin_source_stats() -> Result<()> {
335335
}
336336

337337
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
338-
async fn test_statistics_securejoin_uipath_stats() -> Result<()> {
339-
async fn check_statistics(context: &TestContext, expected: &SecurejoinUIPathStats) {
338+
async fn test_statistics_securejoin_uipaths() -> Result<()> {
339+
async fn check_statistics(context: &TestContext, expected: &SecurejoinUIPaths) {
340340
let stats = get_statistics(context).await.unwrap();
341341
let actual: serde_json::Value = serde_json::from_str(&stats).unwrap();
342-
let actual = &actual["securejoin_uipath_stats"];
342+
let actual = &actual["securejoin_uipaths"];
343343

344344
let expected = serde_json::to_string_pretty(&expected).unwrap();
345345
let expected: serde_json::Value = serde_json::from_str(&expected).unwrap();
@@ -352,7 +352,7 @@ async fn test_statistics_securejoin_uipath_stats() -> Result<()> {
352352
let bob = &tcm.bob().await;
353353
alice.set_config_bool(Config::SendStatistics, true).await?;
354354

355-
let mut expected = SecurejoinUIPathStats {
355+
let mut expected = SecurejoinUIPaths {
356356
other: 0,
357357
qr_icon: 0,
358358
new_contact: 0,
@@ -402,7 +402,7 @@ async fn test_statistics_securejoin_invites() -> Result<()> {
402402
async fn check_statistics(context: &TestContext, expected: &[JoinedInvite]) {
403403
let stats = get_statistics(context).await.unwrap();
404404
let actual: serde_json::Value = serde_json::from_str(&stats).unwrap();
405-
let actual = &actual["securejoin_invites_stats"];
405+
let actual = &actual["securejoin_invites"];
406406

407407
let expected = serde_json::to_string_pretty(&expected).unwrap();
408408
let expected: serde_json::Value = serde_json::from_str(&expected).unwrap();

0 commit comments

Comments
 (0)