Skip to content

Commit

Permalink
Merge pull request #3540 from Hywan/fix-ui-roomlist-latest-event
Browse files Browse the repository at this point in the history
chore(ui): `room_list_service::Room::latest_event` no longer uses `SlidingSyncRoom` (+ drop `SlidingSyncRoomExt`)
  • Loading branch information
Hywan authored Jun 13, 2024
2 parents f770248 + 6d12894 commit 6da17b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 156 deletions.
32 changes: 22 additions & 10 deletions crates/matrix-sdk-ui/src/room_list_service/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ruma::{api::client::sync::sync_events::v4::RoomSubscription, events::StateEv

use super::Error;
use crate::{
timeline::{EventTimelineItem, SlidingSyncRoomExt, TimelineBuilder},
timeline::{EventTimelineItem, TimelineBuilder},
Timeline,
};

Expand Down Expand Up @@ -150,26 +150,38 @@ impl Room {

/// Get the latest event in the timeline.
///
/// The latest event comes first from the `Timeline` if it exists and if it
/// contains a local event. Otherwise, it comes from the cache. This method
/// does not fetch any events or calculate anything — if it's not
/// already available, we return `None`.
/// The latest event comes first from the `Timeline`, it can be a local or a
/// remote event. Note that the `Timeline` can have more information esp. if
/// it has run a backpagination for example. Otherwise if the `Timeline`
/// doesn't have any latest event, it comes from the cache. This method
/// does not fetch any events or calculate anything — if it's not already
/// available, we return `None`.
///
/// Reminder: this method also returns `None` is the latest event is not
/// suitable for use in a message preview.
pub async fn latest_event(&self) -> Option<EventTimelineItem> {
// Look for a local event in the `Timeline`.
//
// First off, let's see if a `Timeline` exists…
if let Some(timeline) = self.inner.timeline.get() {
// If it contains a `latest_event`…
if let Some(timeline_last_event) = timeline.latest_event().await {
// If it's a local echo…
if timeline_last_event.is_local_echo() {
return Some(timeline_last_event);
}
// If it's a local event or a remote event, we return it.
return Some(timeline_last_event);
}
}

// Otherwise, fallback to the classical path.
self.inner.sliding_sync_room.latest_timeline_item().await
if let Some(latest_event) = self.inner.room.latest_event() {
EventTimelineItem::from_latest_event(
self.inner.room.client(),
self.inner.room.room_id(),
latest_event,
)
.await
} else {
None
}
}

/// Create a new [`TimelineBuilder`] with the default configuration.
Expand Down
2 changes: 0 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ mod pagination;
mod polls;
mod reactions;
mod read_receipts;
mod sliding_sync_ext;
#[cfg(test)]
mod tests;
#[cfg(feature = "e2e-encryption")]
Expand All @@ -102,7 +101,6 @@ pub use self::{
pagination::LiveBackPaginationStatus,
polls::PollResult,
reactions::ReactionSenderData,
sliding_sync_ext::SlidingSyncRoomExt,
traits::RoomExt,
virtual_item::VirtualTimelineItem,
};
Expand Down
140 changes: 0 additions & 140 deletions crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/matrix-sdk/src/sliding_sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ copies accordingly. Because of where the loop sits in the stack, that can
be a bit tedious though, so lists and rooms have an additional way of
subscribing to updates via [`eyeball`].

The `Timeline` one can receive per room by calling `.timeline()` (from
`matrix_sdk_ui::timeline::SlidingSyncRoomExt`) will be populated with the
currently cached timeline events.

## Caching

All room data, for filled but also _invalidated_ rooms, including the entire
Expand Down

0 comments on commit 6da17b3

Please sign in to comment.