Skip to content

Commit b66b454

Browse files
committed
feat(sdk): compute_latest_events broadcasts the update to LatestEvent.
This patch updates `compute_latest_events` to broadcast a `RoomSendQueueUpdate` onto `LatestEvent`. It introduces the new `update_with_send_queue` method.
1 parent 9b2e945 commit b66b454

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ruma::{
3131
};
3232
use tracing::warn;
3333

34-
use crate::{event_cache::RoomEventCache, room::WeakRoom};
34+
use crate::{event_cache::RoomEventCache, room::WeakRoom, send_queue::RoomSendQueueUpdate};
3535

3636
/// The latest event of a room or a thread.
3737
///
@@ -84,6 +84,12 @@ impl LatestEvent {
8484

8585
self.value.set(new_value).await;
8686
}
87+
88+
/// Update the inner latest event value, based on the send queue
89+
/// (specifically with a [`RoomSendQueueUpdate`]).
90+
pub async fn update_with_send_queue(&mut self, send_queue_update: &RoomSendQueueUpdate) {
91+
todo!()
92+
}
8793
}
8894

8995
/// A latest event value!

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,16 @@ impl RoomLatestEvents {
532532
latest_event.update_with_event_cache(&self.room_event_cache, &power_levels).await;
533533
}
534534
}
535+
536+
/// Update the latest events for the room and its threads, based on the
537+
/// send queue update.
538+
async fn update_with_send_queue(&mut self, send_queue_update: &RoomSendQueueUpdate) {
539+
self.for_the_room.update_with_send_queue(send_queue_update).await;
540+
541+
for latest_event in self.per_thread.values_mut() {
542+
latest_event.update_with_send_queue(send_queue_update).await;
543+
}
544+
}
535545
}
536546

537547
/// The task responsible to listen to the [`EventCache`] and the [`SendQueue`].
@@ -687,9 +697,15 @@ async fn compute_latest_events(
687697
}
688698

689699
LatestEventQueueUpdate::SendQueue { room_id, update } => {
690-
// let mut rooms = registered_rooms.rooms.write().await;
700+
let mut rooms = registered_rooms.rooms.write().await;
691701

692-
todo!()
702+
if let Some(room_latest_events) = rooms.get_mut(room_id) {
703+
room_latest_events.update_with_send_queue(update).await;
704+
} else {
705+
error!(?room_id, "Failed to find the room");
706+
707+
continue;
708+
}
693709
}
694710
}
695711
}

0 commit comments

Comments
 (0)