From 3895246b72995274bdeba1c998e0278f5724b5ce Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 4 Aug 2024 16:02:06 +0100 Subject: [PATCH] fix: shout.desktop should be optional If the value isn't present, then it is treated as false --- crates/cli/src/alerts/handlers/notify_user.rs | 6 ++++-- crates/core/src/config/server.rs | 4 ++-- crates/core/src/config/tests.rs | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/cli/src/alerts/handlers/notify_user.rs b/crates/cli/src/alerts/handlers/notify_user.rs index 6b5e9ff5..00b8a705 100644 --- a/crates/cli/src/alerts/handlers/notify_user.rs +++ b/crates/cli/src/alerts/handlers/notify_user.rs @@ -26,8 +26,10 @@ impl Handler for AlertsActor { if let Some(email_config) = shout.email() { send_email(&user_notification, email_config); } - if shout.desktop() { - send_desktop_notification(&user_notification); + if let Some(desktop) = shout.desktop() { + if desktop { + send_desktop_notification(&user_notification); + } } } .in_current_span() diff --git a/crates/core/src/config/server.rs b/crates/core/src/config/server.rs index a6aa5321..794868ce 100644 --- a/crates/core/src/config/server.rs +++ b/crates/core/src/config/server.rs @@ -209,7 +209,7 @@ impl ServerStorage { pub struct Shout { webhook: Option, email: Option, - desktop: bool, + desktop: Option, } impl Shout { pub const fn webhook(&self) -> Option<&OutboundWebhook> { @@ -228,7 +228,7 @@ impl Shout { self.email.as_ref() } - pub const fn desktop(&self) -> bool { + pub const fn desktop(&self) -> Option { self.desktop } } diff --git a/crates/core/src/config/tests.rs b/crates/core/src/config/tests.rs index 87cb5b2b..65325f7d 100644 --- a/crates/core/src/config/tests.rs +++ b/crates/core/src/config/tests.rs @@ -774,7 +774,11 @@ mod given { ServerStorage::new(a_name().into()) } pub fn a_shout() -> Shout { - Shout::new(Some(an_outbound_webhook()), Some(an_email_config()), true) + Shout::new( + Some(an_outbound_webhook()), + Some(an_email_config()), + Some(true), + ) } pub fn some_forge_configs() -> BTreeMap { [(a_name(), a_forge_config())].into()