@@ -196,10 +196,7 @@ const TYPING_NOTICE_RESEND_TIMEOUT: Duration = Duration::from_secs(3);
196196#[ derive( Debug ) ]
197197pub struct PushContext {
198198 /// The Ruma context used to compute the push actions.
199- ///
200- /// May be missing if some state events were missing for the current room
201- /// (e.g. the member information for the logged-in user was missing).
202- push_condition_room_ctx : Option < PushConditionRoomCtx > ,
199+ push_condition_room_ctx : PushConditionRoomCtx ,
203200
204201 /// Push rules for this room, based on the push rules state event, or the
205202 /// global server default as defined by [`Ruleset::server_default`].
@@ -208,11 +205,8 @@ pub struct PushContext {
208205
209206impl PushContext {
210207 /// Compute the push rules for a given event.
211- ///
212- /// Will return `None` if and only if the underlying
213- /// [`PushConditionRoomCtx`] is missing.
214- pub fn for_event < T > ( & self , event : & Raw < T > ) -> Option < Vec < Action > > {
215- Some ( self . push_rules . get_actions ( event, self . push_condition_room_ctx . as_ref ( ) ?) . to_owned ( ) )
208+ pub fn for_event < T > ( & self , event : & Raw < T > ) -> Vec < Action > {
209+ self . push_rules . get_actions ( event, & self . push_condition_room_ctx ) . to_owned ( )
216210 }
217211}
218212
@@ -360,7 +354,10 @@ impl Room {
360354
361355 let push_action_ctx = self . push_context ( ) . await ?;
362356 let chunk = join_all (
363- http_response. chunk . into_iter ( ) . map ( |ev| self . try_decrypt_event ( ev, & push_action_ctx) ) ,
357+ http_response
358+ . chunk
359+ . into_iter ( )
360+ . map ( |ev| self . try_decrypt_event ( ev, push_action_ctx. as_ref ( ) ) ) ,
364361 )
365362 . await ;
366363
@@ -471,7 +468,7 @@ impl Room {
471468 async fn try_decrypt_event (
472469 & self ,
473470 event : Raw < AnyTimelineEvent > ,
474- push_ctx : & PushContext ,
471+ push_ctx : Option < & PushContext > ,
475472 ) -> TimelineEvent {
476473 #[ cfg( feature = "e2e-encryption" ) ]
477474 if let Ok ( AnySyncTimelineEvent :: MessageLike ( AnySyncMessageLikeEvent :: RoomEncrypted (
@@ -484,7 +481,7 @@ impl Room {
484481 }
485482
486483 let mut event = TimelineEvent :: new ( event. cast ( ) ) ;
487- event. push_actions = push_ctx. for_event ( event. raw ( ) ) ;
484+ event. push_actions = push_ctx. map ( |ctx| ctx . for_event ( event. raw ( ) ) ) ;
488485
489486 event
490487 }
@@ -503,7 +500,7 @@ impl Room {
503500
504501 let raw_event = self . client . send ( request) . with_request_config ( request_config) . await ?. event ;
505502 let push_action_ctx = self . push_context ( ) . await ?;
506- let event = self . try_decrypt_event ( raw_event, & push_action_ctx) . await ;
503+ let event = self . try_decrypt_event ( raw_event, push_action_ctx. as_ref ( ) ) . await ;
507504
508505 // Save the event into the event cache, if it's set up.
509506 if let Ok ( ( cache, _handles) ) = self . event_cache ( ) . await {
@@ -560,8 +557,9 @@ impl Room {
560557 let response = self . client . send ( request) . with_request_config ( request_config) . await ?;
561558
562559 let push_action_ctx = self . push_context ( ) . await ?;
560+ let push_action_ctx = push_action_ctx. as_ref ( ) ;
563561 let target_event = if let Some ( event) = response. event {
564- Some ( self . try_decrypt_event ( event, & push_action_ctx) . await )
562+ Some ( self . try_decrypt_event ( event, push_action_ctx) . await )
565563 } else {
566564 None
567565 } ;
@@ -574,13 +572,13 @@ impl Room {
574572 response
575573 . events_before
576574 . into_iter( )
577- . map( |ev| self . try_decrypt_event( ev, & push_action_ctx) ) ,
575+ . map( |ev| self . try_decrypt_event( ev, push_action_ctx) ) ,
578576 ) ,
579577 join_all(
580578 response
581579 . events_after
582580 . into_iter( )
583- . map( |ev| self . try_decrypt_event( ev, & push_action_ctx) ) ,
581+ . map( |ev| self . try_decrypt_event( ev, push_action_ctx) ) ,
584582 ) ,
585583 ) ;
586584
@@ -1369,7 +1367,7 @@ impl Room {
13691367 pub async fn decrypt_event (
13701368 & self ,
13711369 event : & Raw < OriginalSyncRoomEncryptedEvent > ,
1372- push_ctx : & PushContext ,
1370+ push_ctx : Option < & PushContext > ,
13731371 ) -> Result < TimelineEvent > {
13741372 let machine = self . client . olm_machine ( ) . await ;
13751373 let machine = machine. as_ref ( ) . ok_or ( Error :: NoOlmMachine ) ?;
@@ -1391,7 +1389,7 @@ impl Room {
13911389 }
13921390 } ;
13931391
1394- event. push_actions = push_ctx. for_event ( event. raw ( ) ) ;
1392+ event. push_actions = push_ctx. map ( |ctx| ctx . for_event ( event. raw ( ) ) ) ;
13951393 Ok ( event)
13961394 }
13971395
@@ -2952,31 +2950,21 @@ impl Room {
29522950
29532951 /// Retrieves a [`PushContext`] that can be used to compute the push
29542952 /// actions for events.
2955- pub async fn push_context ( & self ) -> Result < PushContext > {
2956- let push_condition_room_ctx = self . push_condition_room_ctx ( ) . await ?;
2957- if push_condition_room_ctx. is_none ( ) {
2953+ pub async fn push_context ( & self ) -> Result < Option < PushContext > > {
2954+ let Some ( push_condition_room_ctx) = self . push_condition_room_ctx ( ) . await ? else {
29582955 debug ! ( "Could not aggregate push context" ) ;
2959- }
2956+ return Ok ( None ) ;
2957+ } ;
29602958 let push_rules = self . client ( ) . account ( ) . push_rules ( ) . await ?;
2961- Ok ( PushContext { push_condition_room_ctx, push_rules } )
2959+ Ok ( Some ( PushContext { push_condition_room_ctx, push_rules } ) )
29622960 }
29632961
29642962 /// Get the push actions for the given event with the current room state.
29652963 ///
29662964 /// Note that it is possible that no push action is returned because the
29672965 /// current room state does not have all the required state events.
2968- #[ deprecated(
2969- note = "Use `Room::push_context` to retrieve a `PushContext` instead, and call `PushContext::for_event` on your event."
2970- ) ]
29712966 pub async fn event_push_actions < T > ( & self , event : & Raw < T > ) -> Result < Option < Vec < Action > > > {
2972- let Some ( push_context) = self . push_condition_room_ctx ( ) . await ? else {
2973- debug ! ( "Could not aggregate push context" ) ;
2974- return Ok ( None ) ;
2975- } ;
2976-
2977- let push_rules = self . client ( ) . account ( ) . push_rules ( ) . await ?;
2978-
2979- Ok ( Some ( push_rules. get_actions ( event, & push_context) . to_owned ( ) ) )
2967+ Ok ( self . push_context ( ) . await ?. map ( |ctx| ctx. for_event ( event) ) )
29802968 }
29812969
29822970 /// The membership details of the (latest) invite for the logged-in user in
0 commit comments