From ed3e9fae426d293c1c664f96c7e8a6a6f40734bf Mon Sep 17 00:00:00 2001 From: ranfdev Date: Tue, 24 Oct 2023 16:39:09 +0200 Subject: [PATCH] Use subscription display name as title when possible --- ntfy-daemon/src/models.rs | 9 +++++++++ ntfy-daemon/src/system_client.rs | 28 +++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ntfy-daemon/src/models.rs b/ntfy-daemon/src/models.rs index aaa6425..9ce5a5e 100644 --- a/ntfy-daemon/src/models.rs +++ b/ntfy-daemon/src/models.rs @@ -75,6 +75,15 @@ impl Message { title_text }) } + pub fn notification_title(&self, subscription: &Subscription) -> String { + self.display_title() + .or(if subscription.display_name.is_empty() { + None + } else { + Some(subscription.display_name.to_string()) + }) + .unwrap_or(self.topic.to_string()) + } pub fn display_message(&self) -> Option { self.message.as_ref().map(|message| { diff --git a/ntfy-daemon/src/system_client.rs b/ntfy-daemon/src/system_client.rs index 36f48e6..100e1d3 100644 --- a/ntfy-daemon/src/system_client.rs +++ b/ntfy-daemon/src/system_client.rs @@ -86,23 +86,21 @@ impl output_channel::Server for NotifyForwarder { let msg: Message = pry!(serde_json::from_str(&message) .map_err(|e| Error::InvalidMessage(message.to_string(), e))); let np = self.env.proxy.clone(); - tokio::task::spawn_local(async move { - let title = msg.display_title(); - let title = title.as_ref().map(|x| x.as_str()).unwrap_or(&msg.topic); - let n = models::Notification { - title: title.to_string(), - body: msg - .display_message() - .as_ref() - .map(|x| x.as_str()) - .unwrap_or("") - .to_string(), - }; + let title = { msg.notification_title(&*self.model.borrow()) }; - info!("Showing notification"); - np.send(n).unwrap(); - }); + let n = models::Notification { + title: title.to_string(), + body: msg + .display_message() + .as_ref() + .map(|x| x.as_str()) + .unwrap_or("") + .to_string(), + }; + + info!("Showing notification"); + np.send(n).unwrap(); } // Forward