Skip to content

Commit 8a29f17

Browse files
zecakehHywan
authored andcommitted
refactor(base): Call Room::power_levels instead of loading event from the store
To reduce code duplication. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent fab520a commit 8a29f17

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ pub mod stripped {
270270
// We need to check for notifications after we have handled all state
271271
// events, to make sure we have the full push context.
272272
if let Some(push_condition_room_ctx) =
273-
timeline::get_push_room_context(context, room, room_info, notification.state_store)
274-
.await?
273+
timeline::get_push_room_context(context, room, room_info).await?
275274
{
276275
let room_id = room.room_id();
277276

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ use matrix_sdk_common::deserialized_responses::TimelineEvent;
1616
#[cfg(feature = "e2e-encryption")]
1717
use ruma::events::SyncMessageLikeEvent;
1818
use ruma::{
19-
events::{
20-
room::power_levels::RoomPowerLevelsEventContent, AnySyncMessageLikeEvent,
21-
AnySyncTimelineEvent,
22-
},
19+
events::{AnySyncMessageLikeEvent, AnySyncTimelineEvent},
2320
push::{Action, PushConditionRoomCtx},
2421
UInt, UserId,
2522
};
@@ -28,11 +25,7 @@ use tracing::{instrument, trace, warn};
2825
#[cfg(feature = "e2e-encryption")]
2926
use super::{e2ee, verification};
3027
use super::{notification, Context};
31-
use crate::{
32-
store::{BaseStateStore, StateStoreExt as _},
33-
sync::Timeline,
34-
Result, Room, RoomInfo,
35-
};
28+
use crate::{sync::Timeline, Result, Room, RoomInfo};
3629

3730
/// Process a set of sync timeline event, and create a [`Timeline`].
3831
///
@@ -51,8 +44,7 @@ pub async fn build<'notification, 'e2ee>(
5144
#[cfg(feature = "e2e-encryption")] e2ee: e2ee::E2EE<'e2ee>,
5245
) -> Result<Timeline> {
5346
let mut timeline = Timeline::new(timeline_inputs.limited, timeline_inputs.prev_batch);
54-
let mut push_condition_room_ctx =
55-
get_push_room_context(context, room, room_info, notification.state_store).await?;
47+
let mut push_condition_room_ctx = get_push_room_context(context, room, room_info).await?;
5648
let room_id = room.room_id();
5749

5850
for raw_event in timeline_inputs.raw_events {
@@ -131,8 +123,7 @@ pub async fn build<'notification, 'e2ee>(
131123
)
132124
} else {
133125
push_condition_room_ctx =
134-
get_push_room_context(context, room, room_info, notification.state_store)
135-
.await?;
126+
get_push_room_context(context, room, room_info).await?;
136127
}
137128

138129
if let Some(push_condition_room_ctx) = &push_condition_room_ctx {
@@ -225,7 +216,6 @@ pub async fn get_push_room_context(
225216
context: &Context,
226217
room: &Room,
227218
room_info: &RoomInfo,
228-
state_store: &BaseStateStore,
229219
) -> Result<Option<PushConditionRoomCtx>> {
230220
let room_id = room.room_id();
231221
let user_id = room.own_user_id();
@@ -245,11 +235,7 @@ pub async fn get_push_room_context(
245235
let power_levels = if let Some(power_levels) = context.state_changes.power_levels(room_id) {
246236
Some(power_levels)
247237
} else {
248-
state_store
249-
.get_state_event_static::<RoomPowerLevelsEventContent>(room_id)
250-
.await?
251-
.and_then(|e| e.deserialize().ok())
252-
.map(|event| event.power_levels())
238+
room.power_levels().await.ok()
253239
};
254240

255241
Ok(Some(PushConditionRoomCtx {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,11 +2930,7 @@ impl Room {
29302930
return Ok(None);
29312931
};
29322932

2933-
let power_levels = self
2934-
.get_state_event_static::<RoomPowerLevelsEventContent>()
2935-
.await?
2936-
.and_then(|e| e.deserialize().ok())
2937-
.map(|e| e.power_levels().into());
2933+
let power_levels = self.power_levels().await.ok().map(Into::into);
29382934

29392935
Ok(Some(PushConditionRoomCtx {
29402936
user_id: user_id.to_owned(),

0 commit comments

Comments
 (0)