diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index 1564e8c8..f35ef1d6 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -619,7 +619,7 @@ impl Overlord { Ok(()) } - async fn post_textnote(&mut self, content: String, tags: Vec) -> Result<(), Error> { + async fn post_textnote(&mut self, content: String, mut tags: Vec) -> Result<(), Error> { let event = { let public_key = match GLOBALS.signer.read().await.public_key() { Some(pk) => pk, @@ -629,6 +629,13 @@ impl Overlord { } }; + if GLOBALS.settings.read().await.set_client_tag { + tags.push(Tag::Other { + tag: "client".to_owned(), + data: vec!["gossip".to_owned()], + }); + } + let pre_event = PreEvent { pubkey: public_key, created_at: Unixtime::now().unwrap(), @@ -725,6 +732,13 @@ impl Overlord { // FIXME deduplicate 'p' tags + if GLOBALS.settings.read().await.set_client_tag { + tags.push(Tag::Other { + tag: "client".to_owned(), + data: vec!["gossip".to_owned()], + }); + } + let pre_event = PreEvent { pubkey: public_key, created_at: Unixtime::now().unwrap(), @@ -778,22 +792,31 @@ impl Overlord { } }; + let mut tags: Vec = vec![ + Tag::Event { + id, + recommended_relay_url: DbRelay::recommended_relay_for_reply(id).await?, + marker: None, + }, + Tag::Pubkey { + pubkey, + recommended_relay_url: None, + petname: None, + }, + ]; + + if GLOBALS.settings.read().await.set_client_tag { + tags.push(Tag::Other { + tag: "client".to_owned(), + data: vec!["gossip".to_owned()], + }); + } + let pre_event = PreEvent { pubkey: public_key, created_at: Unixtime::now().unwrap(), kind: EventKind::Reaction, - tags: vec![ - Tag::Event { - id, - recommended_relay_url: DbRelay::recommended_relay_for_reply(id).await?, - marker: None, - }, - Tag::Pubkey { - pubkey, - recommended_relay_url: None, - petname: None, - }, - ], + tags, content: "+".to_owned(), ots: None, }; diff --git a/src/settings.rs b/src/settings.rs index 4051f1e6..5f238f99 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -14,6 +14,7 @@ pub const DEFAULT_FEED_RECOMPUTE_INTERVAL_MS: u32 = 2000; pub const DEFAULT_POW: u8 = 0; pub const DEFAULT_OFFLINE: bool = false; pub const DEFAULT_LIGHT_MODE: bool = true; // true = light false = dark +pub const DEFAULT_SET_CLIENT_TAG: bool = false; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Settings { @@ -30,6 +31,7 @@ pub struct Settings { pub pow: u8, pub offline: bool, pub light_mode: bool, + pub set_client_tag: bool, } impl Default for Settings { @@ -48,6 +50,7 @@ impl Default for Settings { pow: DEFAULT_POW, offline: DEFAULT_OFFLINE, light_mode: DEFAULT_LIGHT_MODE, + set_client_tag: DEFAULT_SET_CLIENT_TAG, } } } @@ -105,6 +108,7 @@ impl Settings { "pow" => settings.pow = row.1.parse::().unwrap_or(DEFAULT_POW), "offline" => settings.offline = numstr_to_bool(row.1), "light_mode" => settings.light_mode = numstr_to_bool(row.1), + "set_client_tag" => settings.set_client_tag = numstr_to_bool(row.1), _ => {} } } @@ -135,8 +139,9 @@ impl Settings { ('max_fps', ?),\ ('feed_recompute_interval_ms', ?),\ ('pow', ?),\ + ('offline', ?),\ ('light_mode', ?),\ - ('offline', ?)", + ('set_client_tag', ?)", )?; stmt.execute(( self.feed_chunk, @@ -148,8 +153,9 @@ impl Settings { self.max_fps, self.feed_recompute_interval_ms, self.pow, - bool_to_numstr(self.light_mode), bool_to_numstr(self.offline), + bool_to_numstr(self.light_mode), + bool_to_numstr(self.set_client_tag), ))?; // Save private key identity diff --git a/src/ui/mod.rs b/src/ui/mod.rs index eeac1200..c5fb96a4 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -105,7 +105,7 @@ impl GossipUi { // grab settings to determine whether to render dark_mode or light_mode let settings = GLOBALS.settings.blocking_read().clone(); - if ! settings.light_mode { + if !settings.light_mode { cctx.egui_ctx.set_visuals(style::dark_mode_visuals()); } else { cctx.egui_ctx.set_visuals(style::light_mode_visuals()); diff --git a/src/ui/settings.rs b/src/ui/settings.rs index 2d405c6d..f7a52a7d 100644 --- a/src/ui/settings.rs +++ b/src/ui/settings.rs @@ -5,12 +5,7 @@ use eframe::egui; use egui::widgets::{Button, Slider}; use egui::{Align, Context, Layout, Ui}; -pub(super) fn update( - app: &mut GossipUi, - _ctx: &Context, - _frame: &mut eframe::Frame, - ui: &mut Ui, -) { +pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) { ui.heading("Settings"); ui.add_space(12.0); @@ -93,6 +88,14 @@ pub(super) fn update( ui.add(Slider::new(&mut app.settings.pow, 0..=40).text("leading zeroes")); }); + ui.add_space(12.0); + + ui.checkbox( + &mut app.settings.set_client_tag, + "Add tag [\"client\",\"gossip\"] to posts", + ) + .on_hover_text("Takes effect immediately."); + ui.add_space(12.0); ui.separator(); ui.add_space(12.0);