Skip to content

Commit 1ada5ad

Browse files
committed
refactor(sdk): rename a few push_action_ctx variables back into push_ctx
1 parent fb0fe52 commit 1ada5ad

File tree

10 files changed

+44
-50
lines changed

10 files changed

+44
-50
lines changed

crates/matrix-sdk-base/src/response_processors/notification.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ impl<'a> Notification<'a> {
5555

5656
/// Push a new [`sync::Notification`] in [`Self::notifications`] from
5757
/// `event` if and only if `predicate` returns `true` for at least one of
58-
/// the [`Action`]s associated to this event and this `push_context`
59-
/// (based on `Self::push_rules`).
58+
/// the [`Action`]s associated to this event and this
59+
/// `push_condition_room_ctx`. (based on `Self::push_rules`).
6060
///
6161
/// This method returns the fetched [`Action`]s.
6262
pub fn push_notification_from_event_if<E, P>(
6363
&mut self,
6464
room_id: &RoomId,
65-
push_context: &PushConditionRoomCtx,
65+
push_condition_room_ctx: &PushConditionRoomCtx,
6666
event: &Raw<E>,
6767
predicate: P,
6868
) -> &[Action]
6969
where
7070
Raw<E>: Into<RawAnySyncOrStrippedTimelineEvent>,
7171
P: Fn(&Action) -> bool,
7272
{
73-
let actions = self.push_rules.get_actions(event, push_context);
73+
let actions = self.push_rules.get_actions(event, push_condition_room_ctx);
7474

7575
if actions.iter().any(predicate) {
7676
self.push_notification(room_id, actions.to_owned(), event.clone().into());

crates/matrix-sdk-base/src/response_processors/state_events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub mod stripped {
179179

180180
// We need to check for notifications after we have handled all state
181181
// events, to make sure we have the full push context.
182-
if let Some(push_context) =
182+
if let Some(push_condition_room_ctx) =
183183
timeline::get_push_room_context(context, room, room_info, notification.state_store)
184184
.await?
185185
{
@@ -189,7 +189,7 @@ pub mod stripped {
189189
for event in state_events.values().flat_map(|map| map.values()) {
190190
notification.push_notification_from_event_if(
191191
room_id,
192-
&push_context,
192+
&push_condition_room_ctx,
193193
event,
194194
Action::should_notify,
195195
);

crates/matrix-sdk-base/src/response_processors/timeline.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub async fn build<'notification, 'e2ee>(
5454
#[cfg(feature = "e2e-encryption")] e2ee: e2ee::E2EE<'e2ee>,
5555
) -> Result<Timeline> {
5656
let mut timeline = Timeline::new(timeline_inputs.limited, timeline_inputs.prev_batch);
57-
let mut push_context =
57+
let mut push_condition_room_ctx =
5858
get_push_room_context(context, room, room_info, notification.state_store).await?;
5959
let room_id = room.room_id();
6060

@@ -127,18 +127,23 @@ pub async fn build<'notification, 'e2ee>(
127127
AnySyncTimelineEvent::MessageLike(_) => (),
128128
}
129129

130-
if let Some(push_context) = &mut push_context {
131-
update_push_room_context(context, push_context, room.own_user_id(), room_info)
130+
if let Some(push_condition_room_ctx) = &mut push_condition_room_ctx {
131+
update_push_room_context(
132+
context,
133+
push_condition_room_ctx,
134+
room.own_user_id(),
135+
room_info,
136+
)
132137
} else {
133-
push_context =
138+
push_condition_room_ctx =
134139
get_push_room_context(context, room, room_info, notification.state_store)
135140
.await?;
136141
}
137142

138-
if let Some(push_context) = &push_context {
143+
if let Some(push_condition_room_ctx) = &push_condition_room_ctx {
139144
let actions = notification.push_notification_from_event_if(
140145
room_id,
141-
push_context,
146+
push_condition_room_ctx,
142147
timeline_event.raw(),
143148
Action::should_notify,
144149
);

crates/matrix-sdk-ui/src/notification_client.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl NotificationClient {
188188
NotificationProcessSetup::MultipleProcesses
189189
));
190190

191-
let push_action_ctx = room.push_context().await?;
191+
let push_ctx = room.push_context().await?;
192192
let sync_permit_guard = match &self.process_setup {
193193
NotificationProcessSetup::MultipleProcesses => {
194194
// We're running on our own process, dedicated for notifications. In that case,
@@ -218,9 +218,8 @@ impl NotificationClient {
218218

219219
sleep(Duration::from_millis(wait)).await;
220220

221-
let new_event = room
222-
.decrypt_event(raw_event.cast_ref(), push_action_ctx.as_ref())
223-
.await?;
221+
let new_event =
222+
room.decrypt_event(raw_event.cast_ref(), push_ctx.as_ref()).await?;
224223

225224
match new_event.kind {
226225
matrix_sdk::deserialized_responses::TimelineEventKind::UnableToDecrypt {
@@ -261,7 +260,7 @@ impl NotificationClient {
261260

262261
match encryption_sync {
263262
Ok(sync) => match sync.run_fixed_iterations(2, sync_permit_guard).await {
264-
Ok(()) => match room.decrypt_event(raw_event.cast_ref(), push_action_ctx.as_ref()).await {
263+
Ok(()) => match room.decrypt_event(raw_event.cast_ref(), push_ctx.as_ref()).await {
265264
Ok(new_event) => match new_event.kind {
266265
matrix_sdk::deserialized_responses::TimelineEventKind::UnableToDecrypt {
267266
utd_info, ..

crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ async fn decrypt_by_index<D: Decryptor>(
255255
should_retry: impl Fn(&str) -> bool,
256256
retry_indices: Vec<usize>,
257257
) {
258-
let push_context = room_data_provider.push_context().await;
259-
let push_context = push_context.as_ref();
258+
let push_ctx = room_data_provider.push_context().await;
259+
let push_ctx = push_ctx.as_ref();
260260
let unable_to_decrypt_hook = state.meta.unable_to_decrypt_hook.clone();
261261

262262
let retry_one = |item: Arc<TimelineItem>| {
@@ -291,7 +291,7 @@ async fn decrypt_by_index<D: Decryptor>(
291291
return None;
292292
};
293293

294-
match decryptor.decrypt_event_impl(original_json, push_context).await {
294+
match decryptor.decrypt_event_impl(original_json, push_ctx).await {
295295
Ok(event) => {
296296
if let SdkTimelineEventKind::UnableToDecrypt { utd_info, .. } = event.kind {
297297
info!(

crates/matrix-sdk-ui/src/timeline/tests/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,14 @@ impl RoomDataProvider for TestRoomDataProvider {
394394
users_default: int!(0),
395395
notifications: NotificationPowerLevels::new(),
396396
};
397-
let push_context = PushConditionRoomCtx {
397+
let push_condition_room_ctx = PushConditionRoomCtx {
398398
room_id: room_id!("!my_room:server.name").to_owned(),
399399
member_count: uint!(2),
400400
user_id: ALICE.to_owned(),
401401
user_display_name: "Alice".to_owned(),
402402
power_levels: Some(power_levels),
403403
};
404-
405-
Some(PushContext::new(push_context, push_rules))
404+
Some(PushContext::new(push_condition_room_ctx, push_rules))
406405
}
407406

408407
async fn load_fully_read_marker(&self) -> Option<OwnedEventId> {

crates/matrix-sdk-ui/src/timeline/traits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,17 @@ pub(super) trait Decryptor: AsyncTraitDeps + Clone + 'static {
282282
fn decrypt_event_impl(
283283
&self,
284284
raw: &Raw<AnySyncTimelineEvent>,
285-
push_context: Option<&PushContext>,
285+
push_ctx: Option<&PushContext>,
286286
) -> impl Future<Output = Result<TimelineEvent>> + SendOutsideWasm;
287287
}
288288

289289
impl Decryptor for Room {
290290
async fn decrypt_event_impl(
291291
&self,
292292
raw: &Raw<AnySyncTimelineEvent>,
293-
push_context: Option<&PushContext>,
293+
push_ctx: Option<&PushContext>,
294294
) -> Result<TimelineEvent> {
295-
self.decrypt_event(raw.cast_ref(), push_context).await
295+
self.decrypt_event(raw.cast_ref(), push_ctx).await
296296
}
297297
}
298298

@@ -301,7 +301,7 @@ impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) {
301301
async fn decrypt_event_impl(
302302
&self,
303303
raw: &Raw<AnySyncTimelineEvent>,
304-
push_context: Option<&PushContext>,
304+
push_ctx: Option<&PushContext>,
305305
) -> Result<TimelineEvent> {
306306
let (olm_machine, room_id) = self;
307307
let decryption_settings =
@@ -318,7 +318,7 @@ impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) {
318318
};
319319

320320
// Fill the push actions here, to mimic what `Room::decrypt_event` does.
321-
timeline_event.push_actions = push_context.map(|ctx| ctx.for_event(timeline_event.raw()));
321+
timeline_event.push_actions = push_ctx.map(|ctx| ctx.for_event(timeline_event.raw()));
322322

323323
Ok(timeline_event)
324324
}

crates/matrix-sdk/src/room/mod.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,9 @@ impl Room {
360360
let request = options.into_request(room_id);
361361
let http_response = self.client.send(request).await?;
362362

363-
let push_action_ctx = self.push_context().await?;
363+
let push_ctx = self.push_context().await?;
364364
let chunk = join_all(
365-
http_response
366-
.chunk
367-
.into_iter()
368-
.map(|ev| self.try_decrypt_event(ev, push_action_ctx.as_ref())),
365+
http_response.chunk.into_iter().map(|ev| self.try_decrypt_event(ev, push_ctx.as_ref())),
369366
)
370367
.await;
371368

@@ -496,8 +493,8 @@ impl Room {
496493
get_room_event::v3::Request::new(self.room_id().to_owned(), event_id.to_owned());
497494

498495
let raw_event = self.client.send(request).with_request_config(request_config).await?.event;
499-
let push_action_ctx = self.push_context().await?;
500-
let event = self.try_decrypt_event(raw_event, push_action_ctx.as_ref()).await;
496+
let push_ctx = self.push_context().await?;
497+
let event = self.try_decrypt_event(raw_event, push_ctx.as_ref()).await;
501498

502499
// Save the event into the event cache, if it's set up.
503500
if let Ok((cache, _handles)) = self.event_cache().await {
@@ -553,10 +550,10 @@ impl Room {
553550

554551
let response = self.client.send(request).with_request_config(request_config).await?;
555552

556-
let push_action_ctx = self.push_context().await?;
557-
let push_action_ctx = push_action_ctx.as_ref();
553+
let push_ctx = self.push_context().await?;
554+
let push_ctx = push_ctx.as_ref();
558555
let target_event = if let Some(event) = response.event {
559-
Some(self.try_decrypt_event(event, push_action_ctx).await)
556+
Some(self.try_decrypt_event(event, push_ctx).await)
560557
} else {
561558
None
562559
};
@@ -566,16 +563,10 @@ impl Room {
566563
// decryption error, so we should prevent against most bad cases here.
567564
let (events_before, events_after) = join!(
568565
join_all(
569-
response
570-
.events_before
571-
.into_iter()
572-
.map(|ev| self.try_decrypt_event(ev, push_action_ctx)),
566+
response.events_before.into_iter().map(|ev| self.try_decrypt_event(ev, push_ctx)),
573567
),
574568
join_all(
575-
response
576-
.events_after
577-
.into_iter()
578-
.map(|ev| self.try_decrypt_event(ev, push_action_ctx)),
569+
response.events_after.into_iter().map(|ev| self.try_decrypt_event(ev, push_ctx)),
579570
),
580571
);
581572

crates/matrix-sdk/tests/integration/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,10 @@ async fn test_encrypt_room_event() {
770770
.expect("We should be able to construct a full event from the encrypted event content")
771771
.cast();
772772

773-
let push_action_ctx =
773+
let push_ctx =
774774
room.push_context().await.expect("We should be able to get the push action context");
775775
let timeline_event = room
776-
.decrypt_event(&event, push_action_ctx.as_ref())
776+
.decrypt_event(&event, push_ctx.as_ref())
777777
.await
778778
.expect("We should be able to decrypt an event that we ourselves have encrypted");
779779

testing/matrix-sdk-integration-testing/src/tests/nse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ async fn decrypt_event(
425425
event: &Raw<OriginalSyncMessageLikeEvent<RoomEncryptedEventContent>>,
426426
) -> Option<(OwnedEventId, String)> {
427427
let room = client.get_room(room_id).unwrap();
428-
let push_action_ctx = room.push_context().await.unwrap();
429-
let Ok(decrypted) = room.decrypt_event(event, push_action_ctx.as_ref()).await else {
428+
let push_ctx = room.push_context().await.unwrap();
429+
let Ok(decrypted) = room.decrypt_event(event, push_ctx.as_ref()).await else {
430430
return None;
431431
};
432432

0 commit comments

Comments
 (0)