@@ -9,7 +9,7 @@ use glib::Properties;
99use gtk:: { gio, glib} ;
1010use ntfy_daemon:: models;
1111use ntfy_daemon:: ntfy_capnp:: { output_channel, subscription, watch_handle, Status } ;
12- use tracing:: { debug, debug_span , error, instrument} ;
12+ use tracing:: { debug, error, instrument} ;
1313
1414struct TopicWatcher {
1515 sub : glib:: WeakRef < Subscription > ,
@@ -217,8 +217,7 @@ impl Subscription {
217217 val. set_display_name ( & * imp. display_name . borrow ( ) ) ;
218218 val. set_read_until ( imp. read_until . get ( ) ) ;
219219 Promise :: from_future ( async move {
220- let _span = debug_span ! ( "send_updated_info" ) . entered ( ) ;
221- debug ! ( "sending" ) ;
220+ debug ! ( "sending update_info" ) ;
222221 req. send ( ) . promise . await ?;
223222 Ok ( ( ) )
224223 } )
@@ -233,12 +232,8 @@ impl Subscription {
233232 }
234233 fn update_unread_count ( & self ) {
235234 let imp = self . imp ( ) ;
236- if let Some ( last) = Self :: last_message ( & imp. messages ) {
237- if last. time > imp. read_until . get ( ) {
238- imp. unread_count . set ( 1 ) ;
239- } else {
240- imp. unread_count . set ( 0 ) ;
241- }
235+ if Self :: last_message ( & imp. messages ) . map ( |last| last. time ) > Some ( imp. read_until . get ( ) ) {
236+ imp. unread_count . set ( 1 ) ;
242237 } else {
243238 imp. unread_count . set ( 0 ) ;
244239 }
@@ -256,13 +251,12 @@ impl Subscription {
256251 }
257252 pub fn flag_all_as_read ( & self ) -> Promise < ( ) , capnp:: Error > {
258253 let imp = self . imp ( ) ;
259- let Some ( last) = Self :: last_message ( & imp. messages ) else {
254+ let Some ( value) = Self :: last_message ( & imp. messages )
255+ . map ( |last| last. time )
256+ . filter ( |time| * time > self . imp ( ) . read_until . get ( ) )
257+ else {
260258 return Promise :: ok ( ( ) ) ;
261259 } ;
262- let value = last. time ;
263- if self . imp ( ) . read_until . get ( ) == value {
264- return Promise :: ok ( ( ) ) ;
265- }
266260
267261 let this = self . clone ( ) ;
268262 Promise :: from_future ( async move {
@@ -276,14 +270,15 @@ impl Subscription {
276270 }
277271 pub fn publish_msg ( & self , mut msg : models:: Message ) -> Promise < ( ) , capnp:: Error > {
278272 let imp = self . imp ( ) ;
273+ let json = {
274+ msg. topic = self . topic ( ) ;
275+ serde_json:: to_string ( & msg) . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) )
276+ } ;
279277 let mut req = imp. client . get ( ) . unwrap ( ) . publish_request ( ) ;
280- msg. topic = self . topic ( ) ;
281- let json = serde_json:: to_string ( & msg) . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ;
282278 req. get ( ) . set_message ( & pry ! ( json) ) ;
283279
284280 Promise :: from_future ( async move {
285- let _span = debug_span ! ( "publish" ) . entered ( ) ;
286- debug ! ( "sending" ) ;
281+ debug ! ( "sending publish" ) ;
287282 req. send ( ) . promise . await ?;
288283 Ok ( ( ) )
289284 } )
@@ -294,8 +289,7 @@ impl Subscription {
294289 let req = imp. client . get ( ) . unwrap ( ) . clear_notifications_request ( ) ;
295290 let this = self . clone ( ) ;
296291 Promise :: from_future ( async move {
297- let _span = debug_span ! ( "clear_notifications" ) . entered ( ) ;
298- debug ! ( "sending" ) ;
292+ debug ! ( "sending clear_notifications" ) ;
299293 req. send ( ) . promise . await ?;
300294 this. imp ( ) . messages . remove_all ( ) ;
301295 Ok ( ( ) )
0 commit comments