Skip to content

Commit 80a7aad

Browse files
Hywanstefanceriu
authored andcommitted
feat(base): changes::save_only will also broadcast room info notable updates.
This patch changes the `changes::save_only` and `changes::save_and_apply` response processors to both broadcast the `RoomInfoNotableUpdates`.
1 parent 4837add commit 80a7aad

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ use tracing::{error, instrument, trace};
2222
use super::Context;
2323
use crate::{
2424
store::{BaseStateStore, StateStoreExt as _},
25-
Result, StateChanges,
25+
Result,
2626
};
2727

2828
/// Save the [`StateChanges`] from the [`Context`] inside the [`BaseStateStore`]
2929
/// only! The changes aren't applied on the in-memory rooms.
3030
#[instrument(skip_all)]
3131
pub async fn save_only(context: Context, state_store: &BaseStateStore) -> Result<()> {
32-
save_changes(&context.state_changes, state_store, None).await
32+
save_changes(&context, state_store, None).await?;
33+
broadcast_room_info_notable_updates(&context, state_store);
34+
35+
Ok(())
3336
}
3437

3538
/// Save the [`StateChanges`] from the [`Context`] inside the
@@ -46,20 +49,21 @@ pub async fn save_and_apply(
4649
let previous_ignored_user_list =
4750
state_store.get_account_data_event_static().await.ok().flatten();
4851

49-
save_changes(&context.state_changes, state_store, sync_token).await?;
50-
apply_changes(context, state_store, ignore_user_list_changes, previous_ignored_user_list);
52+
save_changes(&context, state_store, sync_token).await?;
53+
apply_changes(&context, ignore_user_list_changes, previous_ignored_user_list);
54+
broadcast_room_info_notable_updates(&context, state_store);
5155

5256
trace!("applied changes");
5357

5458
Ok(())
5559
}
5660

5761
async fn save_changes(
58-
state_changes: &StateChanges,
62+
context: &Context,
5963
state_store: &BaseStateStore,
6064
sync_token: Option<String>,
6165
) -> Result<()> {
62-
state_store.save_changes(state_changes).await?;
66+
state_store.save_changes(&context.state_changes).await?;
6367

6468
if let Some(sync_token) = sync_token {
6569
*state_store.sync_token.write().await = Some(sync_token);
@@ -69,15 +73,12 @@ async fn save_changes(
6973
}
7074

7175
fn apply_changes(
72-
context: Context,
73-
state_store: &BaseStateStore,
76+
context: &Context,
7477
ignore_user_list_changes: &SharedObservable<Vec<String>>,
7578
previous_ignored_user_list: Option<Raw<IgnoredUserListEvent>>,
7679
) {
77-
let (state_changes, room_info_notable_updates) = context.into_parts();
78-
7980
if let Some(event) =
80-
state_changes.account_data.get(&GlobalAccountDataEventType::IgnoredUserList)
81+
context.state_changes.account_data.get(&GlobalAccountDataEventType::IgnoredUserList)
8182
{
8283
match event.deserialize_as::<IgnoredUserListEvent>() {
8384
Ok(event) => {
@@ -110,11 +111,13 @@ fn apply_changes(
110111
}
111112
}
112113
}
114+
}
113115

114-
for (room_id, room_info) in &state_changes.room_infos {
116+
fn broadcast_room_info_notable_updates(context: &Context, state_store: &BaseStateStore) {
117+
for (room_id, room_info) in &context.state_changes.room_infos {
115118
if let Some(room) = state_store.room(room_id) {
116119
let room_info_notable_update_reasons =
117-
room_info_notable_updates.get(room_id).copied().unwrap_or_default();
120+
context.room_info_notable_updates.get(room_id).copied().unwrap_or_default();
118121

119122
room.set_room_info(room_info.clone(), room_info_notable_update_reasons)
120123
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,4 @@ impl Context {
4646
pub fn new(state_changes: StateChanges) -> Self {
4747
Self { state_changes, room_info_notable_updates: Default::default() }
4848
}
49-
50-
pub fn into_parts(self) -> (StateChanges, RoomInfoNotableUpdates) {
51-
let Self { state_changes, room_info_notable_updates } = self;
52-
53-
(state_changes, room_info_notable_updates)
54-
}
5549
}

0 commit comments

Comments
 (0)