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
})
}
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> {
self.message.as_ref().map(|message| {

View File

@ -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