Skip to content

Commit ed3e9fa

Browse files
committed
Use subscription display name as title when possible
1 parent 82c205b commit ed3e9fa

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

ntfy-daemon/src/models.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ impl Message {
7575
title_text
7676
})
7777
}
78+
pub fn notification_title(&self, subscription: &Subscription) -> String {
79+
self.display_title()
80+
.or(if subscription.display_name.is_empty() {
81+
None
82+
} else {
83+
Some(subscription.display_name.to_string())
84+
})
85+
.unwrap_or(self.topic.to_string())
86+
}
7887

7988
pub fn display_message(&self) -> Option<String> {
8089
self.message.as_ref().map(|message| {

ntfy-daemon/src/system_client.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,21 @@ impl output_channel::Server for NotifyForwarder {
8686
let msg: Message = pry!(serde_json::from_str(&message)
8787
.map_err(|e| Error::InvalidMessage(message.to_string(), e)));
8888
let np = self.env.proxy.clone();
89-
tokio::task::spawn_local(async move {
90-
let title = msg.display_title();
91-
let title = title.as_ref().map(|x| x.as_str()).unwrap_or(&msg.topic);
92-
93-
let n = models::Notification {
94-
title: title.to_string(),
95-
body: msg
96-
.display_message()
97-
.as_ref()
98-
.map(|x| x.as_str())
99-
.unwrap_or("")
100-
.to_string(),
101-
};
102-
103-
info!("Showing notification");
104-
np.send(n).unwrap();
105-
});
89+
90+
let title = { msg.notification_title(&*self.model.borrow()) };
91+
92+
let n = models::Notification {
93+
title: title.to_string(),
94+
body: msg
95+
.display_message()
96+
.as_ref()
97+
.map(|x| x.as_str())
98+
.unwrap_or("")
99+
.to_string(),
100+
};
101+
102+
info!("Showing notification");
103+
np.send(n).unwrap();
106104
}
107105

108106
// Forward

0 commit comments

Comments
 (0)