From b410cded00f55ccef00772bc9b4576e2538e1081 Mon Sep 17 00:00:00 2001
From: Valeriy Selitskiy <239034+iamwavecut@users.noreply.github.com>
Date: Tue, 10 Nov 2026 15:32:56 +0100
Subject: [PATCH 1/2] Restrict Gradius advertising to private bot chats
---
.env.example | 2 +
crates/openplotva-app/src/gradius_ads.rs | 258 +++++++++++++-----
.../src/gradius_utility_outbox.rs | 164 +++--------
crates/openplotva-app/src/lib.rs | 2 -
crates/openplotva-app/src/telegram_outbox.rs | 12 +
deploy/production/README.md | 40 +--
6 files changed, 258 insertions(+), 220 deletions(-)
diff --git a/.env.example b/.env.example
index 9831085..9bc2656 100644
--- a/.env.example
+++ b/.env.example
@@ -153,6 +153,8 @@
# Retention (days) for the whitecircle_checks audit log; 0 disables the cleanup worker.
# WHITECIRCLE_CHECKS_RETENTION_DAYS=30
# Privacy-preserving ads (server-side only; disabled by default).
+# Advertising is restricted to the initiating user's private chat with the bot.
+# These switches never enable advertising in groups or channels.
# GRADIUS_ENABLED=false
# GRADIUS_UTILITY_IMAGE_ENABLED=false
# GRADIUS_UTILITY_RATES_ENABLED=false
diff --git a/crates/openplotva-app/src/gradius_ads.rs b/crates/openplotva-app/src/gradius_ads.rs
index e91122b..fffe80e 100644
--- a/crates/openplotva-app/src/gradius_ads.rs
+++ b/crates/openplotva-app/src/gradius_ads.rs
@@ -542,6 +542,10 @@ pub struct GradiusUtilityAdRequest {
pub completed_at: OffsetDateTime,
}
+pub(crate) const fn is_private_ad_chat(chat_id: i64, user_id: i64) -> bool {
+ chat_id > 0 && chat_id == user_id
+}
+
pub(crate) fn initialize_placement_service(
config: &openplotva_config::AppConfig,
api_key: &str,
@@ -595,17 +599,13 @@ impl GradiusUtilityAdService {
&self,
request: GradiusUtilityAdRequest,
) -> Result