Skip to content

Commit f617b89

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

File tree

3 files changed

+34
-27
lines changed
  • crates

3 files changed

+34
-27
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use matrix_sdk_base::{
4141
use matrix_sdk_test::{ALICE, DEFAULT_TEST_ROOM_ID, event_factory::EventFactory};
4242
use ruma::{
4343
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId,
44-
OwnedUserId, TransactionId, UInt, UserId,
44+
OwnedUserId, TransactionId, UInt, UserId, assign,
4545
events::{
4646
AnyMessageLikeEventContent, AnyTimelineEvent,
4747
reaction::ReactionEventContent,
@@ -407,18 +407,20 @@ impl RoomDataProvider for TestRoomDataProvider {
407407

408408
async fn push_context(&self) -> Option<PushContext> {
409409
let push_rules = Ruleset::server_default(&ALICE);
410-
let power_levels = PushConditionPowerLevelsCtx {
411-
users: BTreeMap::new(),
412-
users_default: int!(0),
413-
notifications: NotificationPowerLevels::new(),
414-
};
415-
let push_condition_room_ctx = PushConditionRoomCtx {
416-
room_id: room_id!("!my_room:server.name").to_owned(),
417-
member_count: uint!(2),
418-
user_id: ALICE.to_owned(),
419-
user_display_name: "Alice".to_owned(),
420-
power_levels: Some(power_levels),
421-
};
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+
);
422424
Some(PushContext::new(push_condition_room_ctx, push_rules))
423425
}
424426

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)