feat(sdk,ui): Automatically subscribe to LatestEvents if EventCache has subscribed.

This commit is contained in:
Ivan Enderlin
2025-09-23 13:46:29 +02:00
parent b316c534ea
commit f7e1866bda
3 changed files with 17 additions and 6 deletions
@@ -465,13 +465,15 @@ impl RoomListService {
// Before subscribing, let's listen these rooms to calculate their latest
// events.
let latest_events = self.client.latest_events().await;
if self.client.event_cache().has_subscribed() {
let latest_events = self.client.latest_events().await;
for room_id in room_ids {
if let Err(error) = latest_events.listen_to_room(room_id).await {
// Let's not fail the room subscription. Instead, emit a log because it's very
// unlikely to happen.
error!(?error, ?room_id, "Failed to listen to the latest event for this room");
for room_id in room_ids {
if let Err(error) = latest_events.listen_to_room(room_id).await {
// Let's not fail the room subscription. Instead, emit a log because it's very
// unlikely to happen.
error!(?error, ?room_id, "Failed to listen to the latest event for this room");
}
}
}
+5
View File
@@ -408,6 +408,11 @@ impl EventCache {
info!("Auto-shrink linked chunk task has been closed, exiting");
}
/// Check whether [`EventCache::subscribe`] has been called.
pub fn has_subscribed(&self) -> bool {
self.inner.drop_handles.get().is_some()
}
/// Return a room-specific view over the [`EventCache`].
pub(crate) async fn for_room(
&self,
+4
View File
@@ -359,6 +359,10 @@ pub(crate) async fn subscribe_to_room_latest_events<'a, R>(client: &'a Client, r
where
R: Iterator<Item = &'a OwnedRoomId>,
{
if !client.event_cache().has_subscribed() {
return;
}
let latest_events = client.latest_events().await;
for room_id in room_ids {