Skip to content

Commit cf16978

Browse files
committed
feat(sdk): RegisteredRooms gets a clone of EventCache.
1 parent 6a30a80 commit cf16978

File tree

1 file changed

+24
-4
lines changed
  • crates/matrix-sdk/src/latest_events

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl LatestEvents {
9494
let (room_registration_sender, room_registration_receiver) = mpsc::channel(32);
9595
let (latest_event_queue_sender, latest_event_queue_receiver) = mpsc::unbounded_channel();
9696

97-
let registered_rooms = Arc::new(RegisteredRooms::new(room_registration_sender));
97+
let registered_rooms =
98+
Arc::new(RegisteredRooms::new(room_registration_sender, &event_cache));
9899

99100
// The task listening to the event cache and the send queue updates.
100101
let listen_task_handle = spawn(listen_to_event_cache_and_send_queue_updates_task(
@@ -203,11 +204,20 @@ struct RegisteredRooms {
203204
/// The receiver part of the channel is in the
204205
/// [`listen_to_event_cache_and_send_queue_updates_task`].
205206
room_registration_sender: mpsc::Sender<RoomRegistration>,
207+
208+
event_cache: EventCache,
206209
}
207210

208211
impl RegisteredRooms {
209-
fn new(room_registration_sender: mpsc::Sender<RoomRegistration>) -> Self {
210-
Self { rooms: RwLock::new(HashMap::default()), room_registration_sender }
212+
fn new(
213+
room_registration_sender: mpsc::Sender<RoomRegistration>,
214+
event_cache: &EventCache,
215+
) -> Self {
216+
Self {
217+
rooms: RwLock::new(HashMap::default()),
218+
room_registration_sender,
219+
event_cache: event_cache.clone(),
220+
}
211221
}
212222

213223
/// Get a read lock guard to a [`RoomLatestEvents`] given a room ID and an
@@ -547,6 +557,8 @@ mod tests {
547557
client.base_client().get_or_create_room(room_id_1, RoomState::Joined);
548558
client.base_client().get_or_create_room(room_id_2, RoomState::Joined);
549559

560+
client.event_cache().subscribe().unwrap();
561+
550562
let latest_events = client.latest_events().await;
551563

552564
// Despites there are many rooms, zero `RoomLatestEvents` are created.
@@ -606,6 +618,8 @@ mod tests {
606618
client.base_client().get_or_create_room(room_id_0, RoomState::Joined);
607619
client.base_client().get_or_create_room(room_id_1, RoomState::Joined);
608620

621+
client.event_cache().subscribe().unwrap();
622+
609623
let latest_events = client.latest_events().await;
610624

611625
// Now let's fetch one room.
@@ -643,6 +657,8 @@ mod tests {
643657
client.base_client().get_or_create_room(room_id_0, RoomState::Joined);
644658
client.base_client().get_or_create_room(room_id_1, RoomState::Joined);
645659

660+
client.event_cache().subscribe().unwrap();
661+
646662
let latest_events = client.latest_events().await;
647663

648664
// Now let's fetch one thread .
@@ -868,8 +884,12 @@ mod tests {
868884
async fn test_compute_latest_events() {
869885
let room_id = owned_room_id!("!r0");
870886

887+
let (client, _server) = logged_in_client_with_server().await;
888+
let event_cache = client.event_cache();
889+
event_cache.subscribe().unwrap();
890+
871891
let (room_registration_sender, _room_registration_receiver) = mpsc::channel(1);
872-
let registered_rooms = RegisteredRooms::new(room_registration_sender);
892+
let registered_rooms = RegisteredRooms::new(room_registration_sender, event_cache);
873893

874894
compute_latest_events(&registered_rooms, &[room_id]).await;
875895
}

0 commit comments

Comments
 (0)