Use subscription display name as title when possible

This commit is contained in:
ranfdev
2023-10-24 16:39:09 +02:00
parent 82c205b150
commit ed3e9fae42
2 changed files with 22 additions and 15 deletions

View File

@ -75,6 +75,15 @@ impl Message {
title_text 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<String> { pub fn display_message(&self) -> Option<String> {
self.message.as_ref().map(|message| { self.message.as_ref().map(|message| {

View File

@ -86,9 +86,8 @@ impl output_channel::Server for NotifyForwarder {
let msg: Message = pry!(serde_json::from_str(&message) let msg: Message = pry!(serde_json::from_str(&message)
.map_err(|e| Error::InvalidMessage(message.to_string(), e))); .map_err(|e| Error::InvalidMessage(message.to_string(), e)));
let np = self.env.proxy.clone(); let np = self.env.proxy.clone();
tokio::task::spawn_local(async move {
let title = msg.display_title(); let title = { msg.notification_title(&*self.model.borrow()) };
let title = title.as_ref().map(|x| x.as_str()).unwrap_or(&msg.topic);
let n = models::Notification { let n = models::Notification {
title: title.to_string(), title: title.to_string(),
@ -102,7 +101,6 @@ impl output_channel::Server for NotifyForwarder {
info!("Showing notification"); info!("Showing notification");
np.send(n).unwrap(); np.send(n).unwrap();
});
} }
// Forward // Forward