Skip to content

Commit 91fbe4e

Browse files
committed
refactor: Adapt to non-exhaustive PushConditionRoomCtx
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent d23641f commit 91fbe4e

File tree

3 files changed

+34
-26
lines changed
  • crates

3 files changed

+34
-26
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use matrix_sdk_common::deserialized_responses::TimelineEvent;
1616
#[cfg(feature = "e2e-encryption")]
1717
use ruma::events::SyncMessageLikeEvent;
1818
use ruma::{
19+
assign,
1920
events::{AnySyncMessageLikeEvent, AnySyncTimelineEvent},
2021
push::{Action, PushConditionRoomCtx},
2122
UInt, UserId,
@@ -238,11 +239,13 @@ pub async fn get_push_room_context(
238239
room.power_levels().await.ok()
239240
};
240241

241-
Ok(Some(PushConditionRoomCtx {
242-
user_id: user_id.to_owned(),
243-
room_id: room_id.to_owned(),
244-
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
245-
user_display_name,
246-
power_levels: power_levels.map(Into::into),
247-
}))
242+
Ok(Some(assign!(
243+
PushConditionRoomCtx::new(
244+
room_id.to_owned(),
245+
UInt::new(member_count).unwrap_or(UInt::MAX),
246+
user_id.to_owned(),
247+
user_display_name
248+
),
249+
{ power_levels: power_levels.map(Into::into) }
250+
)))
248251
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use matrix_sdk_base::{
4040
};
4141
use matrix_sdk_test::{event_factory::EventFactory, ALICE, DEFAULT_TEST_ROOM_ID};
4242
use ruma::{
43+
assign,
4344
events::{
4445
reaction::ReactionEventContent,
4546
receipt::{Receipt, ReceiptThread, ReceiptType},
@@ -406,18 +407,20 @@ impl RoomDataProvider for TestRoomDataProvider {
406407

407408
async fn push_context(&self) -> Option<PushContext> {
408409
let push_rules = Ruleset::server_default(&ALICE);
409-
let power_levels = PushConditionPowerLevelsCtx {
410-
users: BTreeMap::new(),
411-
users_default: int!(0),
412-
notifications: NotificationPowerLevels::new(),
413-
};
414-
let push_condition_room_ctx = PushConditionRoomCtx {
415-
room_id: room_id!("!my_room:server.name").to_owned(),
416-
member_count: uint!(2),
417-
user_id: ALICE.to_owned(),
418-
user_display_name: "Alice".to_owned(),
419-
power_levels: Some(power_levels),
420-
};
410+
let power_levels = PushConditionPowerLevelsCtx::new(
411+
BTreeMap::new(),
412+
int!(0),
413+
NotificationPowerLevels::new(),
414+
);
415+
let push_condition_room_ctx = assign!(
416+
PushConditionRoomCtx::new(
417+
room_id!("!my_room:server.name").to_owned(),
418+
uint!(2),
419+
ALICE.to_owned(),
420+
"Alice".to_owned(),
421+
),
422+
{ power_levels: Some(power_levels) }
423+
);
421424
Some(PushContext::new(push_condition_room_ctx, push_rules))
422425
}
423426

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,13 +2932,15 @@ impl Room {
29322932

29332933
let power_levels = self.power_levels().await.ok().map(Into::into);
29342934

2935-
Ok(Some(PushConditionRoomCtx {
2936-
user_id: user_id.to_owned(),
2937-
room_id: room_id.to_owned(),
2938-
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
2939-
user_display_name,
2940-
power_levels,
2941-
}))
2935+
Ok(Some(assign!(
2936+
PushConditionRoomCtx::new(
2937+
room_id.to_owned(),
2938+
UInt::new(member_count).unwrap_or(UInt::MAX),
2939+
user_id.to_owned(),
2940+
user_display_name,
2941+
),
2942+
{ power_levels }
2943+
)))
29422944
}
29432945

29442946
/// Retrieves a [`PushContext`] that can be used to compute the push

0 commit comments

Comments
 (0)