@@ -22,14 +22,17 @@ use tracing::{error, instrument, trace};
2222use super :: Context ;
2323use 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) ]
3131pub 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
5761async 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
7175fn 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 }
0 commit comments