@@ -606,6 +606,34 @@ impl NotificationClient {
606
606
get_notifications_result. remove ( event_id) . unwrap_or ( Ok ( NotificationStatus :: EventNotFound ) )
607
607
}
608
608
609
+ /// Given a (decrypted or not) event, figure out whether it should be
610
+ /// filtered out for other client-side reasons (such as the sender being
611
+ /// ignored, for instance), and returns the corresponding
612
+ /// [`NotificationStatus`].
613
+ async fn compute_status (
614
+ & self ,
615
+ room : & Room ,
616
+ push_actions : Option < & [ Action ] > ,
617
+ raw_event : RawNotificationEvent ,
618
+ state_events : Vec < Raw < AnyStateEvent > > ,
619
+ ) -> Result < NotificationStatus , Error > {
620
+ if let Some ( actions) = push_actions
621
+ && !actions. iter ( ) . any ( |a| a. should_notify ( ) )
622
+ {
623
+ // The event shouldn't notify: return early.
624
+ return Ok ( NotificationStatus :: EventFilteredOut ) ;
625
+ }
626
+
627
+ let notification_item =
628
+ NotificationItem :: new ( room, raw_event, push_actions, state_events) . await ?;
629
+
630
+ if self . client . is_user_ignored ( notification_item. event . sender ( ) ) . await {
631
+ Ok ( NotificationStatus :: EventFilteredOut )
632
+ } else {
633
+ Ok ( NotificationStatus :: Event ( Box :: new ( notification_item) ) )
634
+ }
635
+ }
636
+
609
637
/// Get a list of full notifications, given a room id and event ids.
610
638
///
611
639
/// This will run a small sliding sync to retrieve the content of the
@@ -674,34 +702,10 @@ impl NotificationClient {
674
702
}
675
703
} ;
676
704
677
- let should_notify = push_actions
678
- . as_ref ( )
679
- . is_some_and ( |actions| actions. iter ( ) . any ( |a| a. should_notify ( ) ) ) ;
680
-
681
- if !should_notify {
682
- // The event has been filtered out by the user's push rules.
683
- batch_result. insert ( event_id, Ok ( NotificationStatus :: EventFilteredOut ) ) ;
684
- continue ;
685
- }
705
+ let notification_status_result =
706
+ self . compute_status ( & room, push_actions. as_deref ( ) , raw_event, Vec :: new ( ) ) . await ;
686
707
687
- let notification_item =
688
- match NotificationItem :: new ( & room, raw_event, push_actions. as_deref ( ) , Vec :: new ( ) )
689
- . await
690
- {
691
- Ok ( item) => item,
692
- Err ( err) => {
693
- // Could not build the notification item, return an error.
694
- batch_result. insert ( event_id, Err ( err) ) ;
695
- continue ;
696
- }
697
- } ;
698
-
699
- if self . client . is_user_ignored ( notification_item. event . sender ( ) ) . await {
700
- batch_result. insert ( event_id, Ok ( NotificationStatus :: EventFilteredOut ) ) ;
701
- } else {
702
- batch_result
703
- . insert ( event_id, Ok ( NotificationStatus :: Event ( Box :: new ( notification_item) ) ) ) ;
704
- }
708
+ batch_result. insert ( event_id, notification_status_result) ;
705
709
}
706
710
707
711
Ok ( batch_result)
@@ -740,26 +744,15 @@ impl NotificationClient {
740
744
timeline_event = decrypted_event;
741
745
}
742
746
743
- if let Some ( actions) = timeline_event. push_actions ( )
744
- && !actions. iter ( ) . any ( |a| a. should_notify ( ) )
745
- {
746
- return Ok ( NotificationStatus :: EventFilteredOut ) ;
747
- }
748
-
749
747
let push_actions = timeline_event. push_actions ( ) . map ( ToOwned :: to_owned) ;
750
- let notification_item = NotificationItem :: new (
748
+
749
+ self . compute_status (
751
750
& room,
752
- RawNotificationEvent :: Timeline ( timeline_event. into_raw ( ) ) ,
753
751
push_actions. as_deref ( ) ,
752
+ RawNotificationEvent :: Timeline ( timeline_event. into_raw ( ) ) ,
754
753
state_events,
755
754
)
756
- . await ?;
757
-
758
- if self . client . is_user_ignored ( notification_item. event . sender ( ) ) . await {
759
- Ok ( NotificationStatus :: EventFilteredOut )
760
- } else {
761
- Ok ( NotificationStatus :: Event ( Box :: new ( notification_item) ) )
762
- }
755
+ . await
763
756
}
764
757
}
765
758
0 commit comments