diff --git a/benches/app.rs b/benches/app.rs index dc395e2f..4d3f43b7 100644 --- a/benches/app.rs +++ b/benches/app.rs @@ -2,7 +2,7 @@ use std::path::Path; use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; use gurk::app::App; -use gurk::config::{Config, User}; +use gurk::config::{Config, NotificationConfig, User}; use gurk::signal::test::SignalManagerMock; use gurk::storage::{ForgetfulStorage, MemCache}; use presage::libsignal_service::content::Content; @@ -11,7 +11,10 @@ use tracing::info; fn test_app() -> App { let (app, _) = App::try_new( Config { - notifications: false, + notifications: NotificationConfig { + enabled: false, + ..Default::default() + }, ..Config::with_user(User { display_name: "Tyler Durden".to_string(), }) diff --git a/src/app.rs b/src/app.rs index 434a6782..b812bd47 100644 --- a/src/app.rs +++ b/src/app.rs @@ -719,8 +719,8 @@ impl App { emoji, HandleReactionOptions::new() .remove(remove.unwrap_or(false)) - .notify(true) - .bell(true), + .notify(self.config.notifications.show_reactions) + .bell(!self.config.notifications.mute_reactions_bell), ) .await; read.into_iter().for_each(|r| { @@ -769,8 +769,8 @@ impl App { emoji, HandleReactionOptions::new() .remove(remove.unwrap_or(false)) - .notify(true) - .bell(true), + .notify(self.config.notifications.show_reactions) + .bell(!self.config.notifications.mute_reactions_bell), ) .await; return Ok(()); @@ -1424,8 +1424,20 @@ impl App { } fn notify(&self, summary: &str, text: &str) { - if self.config.notifications { - if let Err(e) = Notification::new().summary(summary).body(text).show() { + if self.config.notifications.enabled { + if let Err(e) = Notification::new() + .summary(if self.config.notifications.show_message_chat { + summary + } else { + "gurk" + }) + .body(if self.config.notifications.show_message_text { + text + } else { + "New message!" + }) + .show() + { error!("failed to send notification: {}", e); } } diff --git a/src/config.rs b/src/config.rs index 358cce96..f68de8c3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -39,9 +39,9 @@ pub struct Config { /// Whether to show receipts (sent, delivered, read) information next to your user name in UI #[serde(default = "default_true")] pub show_receipts: bool, - /// Whether to show system notifications on incoming messages - #[serde(default = "default_true")] - pub notifications: bool, + /// Notification settings + #[serde(default)] + pub notifications: NotificationConfig, #[serde(default = "default_true")] pub bell: bool, /// User configuration @@ -72,6 +72,37 @@ pub struct User { pub display_name: String, } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct NotificationConfig { + /// Whether to show system notifications on incoming messages + #[serde(default = "default_true")] + pub enabled: bool, + /// Whether to show message preview in notifications + #[serde(default = "default_true")] + pub show_message_text: bool, + /// Whether to show message origin in notifications + #[serde(default = "default_true")] + pub show_message_chat: bool, + /// Whether to show reactions in notifications + #[serde(default = "default_true")] + pub show_reactions: bool, + /// Whether to mute reactions bell + #[serde(default)] + pub mute_reactions_bell: bool, +} + +impl Default for NotificationConfig { + fn default() -> Self { + Self { + enabled: true, + show_message_text: true, + show_message_chat: true, + show_reactions: true, + mute_reactions_bell: false, + } + } +} + #[cfg(feature = "dev")] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct DeveloperConfig { @@ -127,7 +158,7 @@ impl Config { deprecated_signal_db_path: default_signal_db_path(), first_name_only: false, show_receipts: true, - notifications: true, + notifications: NotificationConfig::default(), bell: true, #[cfg(feature = "dev")] developer: Default::default(), @@ -220,6 +251,16 @@ impl Config { message: "will be removed in a future version; use `/gurk.sqlite` instead", }); } + if config_value + .get("notifications") + .and_then(|v| v.as_bool()) + .is_some() + { + keys.push(DeprecatedConfigKey { + key: "notifications", + message: "boolean format is deprecated; use [notifications] section with enabled, show_message_text, show_message_chat, show_reactions and mute_reactions_bell fields", + }); + } let deprecated_keys = DeprecatedKeys { file_path: path.to_path_buf(),