Use subscription display name as title when possible
This commit is contained in:
@ -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| {
|
||||||
|
|||||||
@ -86,23 +86,21 @@ 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 = title.as_ref().map(|x| x.as_str()).unwrap_or(&msg.topic);
|
|
||||||
|
|
||||||
let n = models::Notification {
|
let title = { msg.notification_title(&*self.model.borrow()) };
|
||||||
title: title.to_string(),
|
|
||||||
body: msg
|
|
||||||
.display_message()
|
|
||||||
.as_ref()
|
|
||||||
.map(|x| x.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Showing notification");
|
let n = models::Notification {
|
||||||
np.send(n).unwrap();
|
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
|
// Forward
|
||||||
|
|||||||
Reference in New Issue
Block a user