Skip to content

Commit e687435

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

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::{
2021
room::power_levels::{
2122
RoomPowerLevelsEvent, RoomPowerLevelsEventContent, StrippedRoomPowerLevelsEvent,
@@ -294,11 +295,13 @@ pub async fn get_push_room_context(
294295
.map(|event| event.power_levels().into())
295296
};
296297

297-
Ok(Some(PushConditionRoomCtx {
298-
user_id: user_id.to_owned(),
299-
room_id: room_id.to_owned(),
300-
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
301-
user_display_name,
302-
power_levels,
303-
}))
298+
Ok(Some(assign!(
299+
PushConditionRoomCtx::new(
300+
room_id.to_owned(),
301+
UInt::new(member_count).unwrap_or(UInt::MAX),
302+
user_id.to_owned(),
303+
user_display_name
304+
),
305+
{ power_levels }
306+
)))
304307
}

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},
@@ -399,18 +400,20 @@ impl RoomDataProvider for TestRoomDataProvider {
399400

400401
async fn push_context(&self) -> Option<PushContext> {
401402
let push_rules = Ruleset::server_default(&ALICE);
402-
let power_levels = PushConditionPowerLevelsCtx {
403-
users: BTreeMap::new(),
404-
users_default: int!(0),
405-
notifications: NotificationPowerLevels::new(),
406-
};
407-
let push_condition_room_ctx = PushConditionRoomCtx {
408-
room_id: room_id!("!my_room:server.name").to_owned(),
409-
member_count: uint!(2),
410-
user_id: ALICE.to_owned(),
411-
user_display_name: "Alice".to_owned(),
412-
power_levels: Some(power_levels),
413-
};
403+
let power_levels = PushConditionPowerLevelsCtx::new(
404+
BTreeMap::new(),
405+
int!(0),
406+
NotificationPowerLevels::new(),
407+
);
408+
let push_condition_room_ctx = assign!(
409+
PushConditionRoomCtx::new(
410+
room_id!("!my_room:server.name").to_owned(),
411+
uint!(2),
412+
ALICE.to_owned(),
413+
"Alice".to_owned(),
414+
),
415+
{ power_levels: Some(power_levels) }
416+
);
414417
Some(PushContext::new(push_condition_room_ctx, push_rules))
415418
}
416419

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,13 +2936,15 @@ impl Room {
29362936
.and_then(|e| e.deserialize().ok())
29372937
.map(|e| e.power_levels().into());
29382938

2939-
Ok(Some(PushConditionRoomCtx {
2940-
user_id: user_id.to_owned(),
2941-
room_id: room_id.to_owned(),
2942-
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
2943-
user_display_name,
2944-
power_levels,
2945-
}))
2939+
Ok(Some(assign!(
2940+
PushConditionRoomCtx::new(
2941+
room_id.to_owned(),
2942+
UInt::new(member_count).unwrap_or(UInt::MAX),
2943+
user_id.to_owned(),
2944+
user_display_name,
2945+
),
2946+
{ power_levels }
2947+
)))
29462948
}
29472949

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

0 commit comments

Comments
 (0)