Skip to content

Commit 6b9f05f

Browse files
committed
fix: Don't send statistics from a platform other than Android
1 parent bf84ee4 commit 6b9f05f

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ratelimit::Ratelimit;
1414
use tokio::sync::{Mutex, Notify, RwLock};
1515

1616
use crate::chat::{ChatId, get_chat_cnt};
17-
use crate::chatlist_events;
1817
use crate::config::Config;
1918
use crate::constants::{self, DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT, DC_VERSION_STR};
2019
use crate::contact::{Contact, ContactId};
@@ -34,6 +33,7 @@ use crate::sql::Sql;
3433
use crate::stock_str::StockStrings;
3534
use crate::timesmearing::SmearedTimestamp;
3635
use crate::tools::{self, duration_to_str, time, time_elapsed};
36+
use crate::{chatlist_events, statistics};
3737

3838
/// Builder for the [`Context`].
3939
///
@@ -1079,9 +1079,7 @@ impl Context {
10791079
);
10801080
res.insert(
10811081
"send_statistics",
1082-
self.get_config_bool(Config::SendStatistics)
1083-
.await?
1084-
.to_string(),
1082+
statistics::should_send_statistics(self).await?.to_string(),
10851083
);
10861084
res.insert(
10871085
"last_statistics_sent",

src/statistics.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct JoinedInvite {
144144
/// On the other end, a bot will receive the message and make it available
145145
/// to Delta Chat's developers.
146146
pub async fn maybe_send_statistics(context: &Context) -> Result<Option<ChatId>> {
147-
if context.get_config_bool(Config::SendStatistics).await? {
147+
if should_send_statistics(context).await? {
148148
let last_sending_time = context.get_config_i64(Config::LastStatisticsSent).await?;
149149
let next_sending_time = last_sending_time.saturating_add(30); // TODO increase to 1 day or 1 week
150150
if next_sending_time <= time() {
@@ -154,6 +154,21 @@ pub async fn maybe_send_statistics(context: &Context) -> Result<Option<ChatId>>
154154
Ok(None)
155155
}
156156

157+
pub(crate) async fn should_send_statistics(_context: &Context) -> Result<bool> {
158+
#[cfg(any(target_os = "android", test))]
159+
{
160+
_context.get_config_bool(Config::SendStatistics).await
161+
}
162+
163+
// If the user enables statistics-sending on Android,
164+
// and then transfers the account to e.g. Desktop,
165+
// we should not send any statistics:
166+
#[cfg(not(any(target_os = "android", test)))]
167+
{
168+
Ok(false)
169+
}
170+
}
171+
157172
async fn send_statistics(context: &Context) -> Result<ChatId> {
158173
info!(context, "Sending statistics.");
159174

@@ -584,7 +599,7 @@ pub(crate) async fn count_securejoin_ux_info(
584599
source: Option<u32>,
585600
uipath: Option<u32>,
586601
) -> Result<()> {
587-
if !context.get_config_bool(Config::SendStatistics).await? {
602+
if !should_send_statistics(context).await? {
588603
return Ok(());
589604
}
590605

@@ -669,7 +684,7 @@ async fn get_securejoin_uipath_stats(context: &Context) -> Result<SecurejoinUIPa
669684
}
670685

671686
pub(crate) async fn count_securejoin_invite(context: &Context, invite: &QrInvite) -> Result<()> {
672-
if !context.get_config_bool(Config::SendStatistics).await? {
687+
if !should_send_statistics(context).await? {
673688
return Ok(());
674689
}
675690

0 commit comments

Comments
 (0)