@@ -430,6 +430,13 @@ pub(super) struct ResetCaches<'c> {
430430 pinned_events:: PinnedEventsCacheStateLockWriteGuard < ' c > ,
431431 pinned_events:: PinnedEventsCacheUpdateSender ,
432432 ) > ,
433+ event_focused_lock : OwnedRwLockWriteGuard <
434+ HashMap < event_focused:: EventFocusedCacheKey , event_focused:: EventFocusedCache > ,
435+ > ,
436+ event_focused_locks : Vec < (
437+ OwnedRwLockWriteGuard < event_focused:: EventFocusedCacheState > ,
438+ event_focused:: EventFocusedCacheUpdateSender ,
439+ ) > ,
433440}
434441
435442impl < ' c > ResetCaches < ' c > {
@@ -459,11 +466,26 @@ impl<'c> ResetCaches<'c> {
459466 None
460467 } ;
461468
462- // TODO (in next commits).
463- let _ = event_focused;
464- todo ! ( ) ;
469+ // Acquire an exclusive access to the event-focused caches.
470+ // Then, for each event-focused, acquire an exclusive access to its state.
471+ let event_focused_lock = event_focused. clone ( ) . write_owned ( ) . await ;
472+ let mut event_focused_locks = Vec :: new ( ) ;
473+
474+ for event_focused in event_focused_lock. values ( ) {
475+ event_focused_locks. push ( (
476+ event_focused. state ( ) . clone ( ) . write_owned ( ) . await ,
477+ event_focused. update_sender ( ) . await ,
478+ ) ) ;
479+ }
465480
466- Ok ( Self { room_lock, threads_lock, thread_locks, pinned_events_lock } )
481+ Ok ( Self {
482+ room_lock,
483+ threads_lock,
484+ thread_locks,
485+ pinned_events_lock,
486+ event_focused_lock,
487+ event_focused_locks,
488+ } )
467489 }
468490
469491 /// Reset all the event caches, and broadcast the [`TimelineVectorDiffs`].
@@ -473,7 +495,14 @@ impl<'c> ResetCaches<'c> {
473495 ///
474496 /// It can fail if resetting an event cache fails.
475497 pub async fn reset_all ( self ) -> Result < ( ) > {
476- let Self { room_lock, threads_lock, thread_locks, pinned_events_lock } = self ;
498+ let Self {
499+ room_lock,
500+ threads_lock,
501+ thread_locks,
502+ pinned_events_lock,
503+ event_focused_lock,
504+ event_focused_locks,
505+ } = self ;
477506
478507 // Room.
479508 {
@@ -491,9 +520,7 @@ impl<'c> ResetCaches<'c> {
491520
492521 // Threads.
493522 {
494- for thread_lock in thread_locks {
495- let ( mut thread_state, thread_update_sender) = thread_lock;
496-
523+ for ( mut thread_state, thread_update_sender) in thread_locks {
497524 let updates_as_vector_diffs = thread_state. reset ( ) . await ?;
498525 thread_update_sender. send (
499526 TimelineVectorDiffs {
@@ -522,6 +549,20 @@ impl<'c> ResetCaches<'c> {
522549 }
523550 }
524551
552+ // Event-focused.
553+ {
554+ for ( mut event_focused_state, event_focused_update_sender) in event_focused_locks {
555+ let updates_as_vector_diffs = event_focused_state. reset ( ) ?;
556+ let _ = event_focused_update_sender. send ( TimelineVectorDiffs {
557+ diffs : updates_as_vector_diffs,
558+ origin : EventsOrigin :: Cache ,
559+ } ) ;
560+ }
561+
562+ // Now we can release the exclusive access over the event-focused caches.
563+ drop ( event_focused_lock) ;
564+ }
565+
525566 Ok ( ( ) )
526567 }
527568}
0 commit comments