Skip to content

Commit 568e60b

Browse files
Hywanstefanceriu
authored andcommitted
refactor(base): Extract the “save” part of save_and_apply into its own function.
This patch extracts the “save” part of the `save_and_apply` response processor into its own function. Thus we have `save_changes` (new) and `apply_changes` that are used by `save_and_apply`.
1 parent d05796d commit 568e60b

File tree

1 file changed

+15
-5
lines changed
  • crates/matrix-sdk-base/src/response_processors

1 file changed

+15
-5
lines changed

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

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

2828
/// Save the [`StateChanges`] from the [`Context`] inside the
@@ -39,14 +39,24 @@ pub async fn save_and_apply(
3939
let previous_ignored_user_list =
4040
state_store.get_account_data_event_static().await.ok().flatten();
4141

42-
state_store.save_changes(&context.state_changes).await?;
42+
save_changes(&context.state_changes, state_store, sync_token).await?;
43+
apply_changes(context, state_store, ignore_user_list_changes, previous_ignored_user_list);
44+
45+
trace!("applied changes");
46+
47+
Ok(())
48+
}
49+
50+
async fn save_changes(
51+
state_changes: &StateChanges,
52+
state_store: &BaseStateStore,
53+
sync_token: Option<String>,
54+
) -> Result<()> {
55+
state_store.save_changes(state_changes).await?;
4356

4457
if let Some(sync_token) = sync_token {
4558
*state_store.sync_token.write().await = Some(sync_token);
4659
}
47-
apply_changes(context, state_store, ignore_user_list_changes, previous_ignored_user_list);
48-
49-
trace!("applied changes");
5060

5161
Ok(())
5262
}

0 commit comments

Comments
 (0)