Skip to content

Commit

Permalink
feat(sdk): Remove FrozenSlidingSyncRoom::timeline.
Browse files Browse the repository at this point in the history
This patch removes `FrozenSlidingSyncRoom::timeline`, which means we no
longer cache on-disk the latest events (up to 10). This feature will be
back in a cleaner way with `matrix_sdk_ui::event_graph`.

Because `FrozenSlidingSyncRoom::timeline` is removed, we can also remove
`SlidingSyncRoom::prev_batch`! It was stored here only to handle this
`timeline_queue` when restored back from the cache. The `prev_batch`
is already stored correctly in `RoomInfo`, no need to store it here
anymore.
  • Loading branch information
Hywan committed Feb 5, 2024
1 parent 5d49979 commit 12dc4cb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 271 deletions.
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/room_list_service/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Room {
pub async fn default_room_timeline_builder(&self) -> TimelineBuilder {
Timeline::builder(&self.inner.room)
.events(
self.inner.sliding_sync_room.prev_batch(),
self.inner.room.last_prev_batch(),
self.inner.sliding_sync_room.timeline_queue(),
)
.await
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod tests {
// Given a room with no latest event
let room_id = room_id!("!r:x.uk").to_owned();
let client = logged_in_client(None).await;
let room = SlidingSyncRoom::new(client, room_id, None, Vec::new());
let room = SlidingSyncRoom::new(client, room_id, Vec::new());

// When we ask for the latest event, it is None
assert!(room.latest_timeline_item().await.is_none());
Expand All @@ -78,7 +78,7 @@ mod tests {
process_event_via_sync_test_helper(room_id, event, &client).await;

// When we ask for the latest event in the room
let room = SlidingSyncRoom::new(client.clone(), room_id.to_owned(), None, Vec::new());
let room = SlidingSyncRoom::new(client.clone(), room_id.to_owned(), Vec::new());
let actual = room.latest_timeline_item().await.unwrap();

// Then it is wrapped as an EventTimelineItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async fn timeline_test_helper(
})?;

let timeline = Timeline::builder(&sdk_room)
.events(sliding_sync_room.prev_batch(), sliding_sync_room.timeline_queue())
.events(sdk_room.last_prev_batch(), sliding_sync_room.timeline_queue())
.await
.track_read_marker_and_receipts()
.build()
Expand Down
37 changes: 2 additions & 35 deletions crates/matrix-sdk/src/sliding_sync/list/frozen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ mod tests {
use std::collections::BTreeMap;

use imbl::vector;
use matrix_sdk_base::deserialized_responses::TimelineEvent;
use ruma::{events::room::message::RoomMessageEventContent, room_id, serde::Raw};
use ruma::room_id;
use serde_json::json;

use super::FrozenSlidingSyncList;
Expand All @@ -72,23 +71,7 @@ mod tests {
let mut rooms = BTreeMap::new();
rooms.insert(
room_id!("!foo:bar.org").to_owned(),
FrozenSlidingSyncRoom {
room_id: room_id!("!foo:bar.org").to_owned(),
prev_batch: None,
timeline_queue: vector![TimelineEvent::new(
Raw::new(&json!({
"content": RoomMessageEventContent::text_plain("let it gooo!"),
"type": "m.room.message",
"event_id": "$xxxxx:example.org",
"room_id": "!someroom:example.com",
"origin_server_ts": 2189,
"sender": "@bob:example.com",
}))
.unwrap()
.cast(),
)
.into()],
},
FrozenSlidingSyncRoom { room_id: room_id!("!foo:bar.org").to_owned() },
);

rooms
Expand All @@ -101,22 +84,6 @@ mod tests {
"rooms": {
"!foo:bar.org": {
"room_id": "!foo:bar.org",
"timeline": [
{
"event": {
"content": {
"body": "let it gooo!",
"msgtype": "m.text",
},
"event_id": "$xxxxx:example.org",
"origin_server_ts": 2189,
"room_id": "!someroom:example.com",
"sender": "@bob:example.com",
"type": "m.room.message",
},
"encryption_info": null,
}
],
},
},
})
Expand Down
9 changes: 1 addition & 8 deletions crates/matrix-sdk/src/sliding_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ impl SlidingSync {
SlidingSyncRoom::new(
self.inner.client.clone(),
room_id.clone(),
room_data.prev_batch,
timeline,
),
);
Expand Down Expand Up @@ -1984,7 +1983,6 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
no_overlap.to_owned(),
None,
vec![event_a.clone(), event_b.clone()],
),
),
Expand All @@ -1994,7 +1992,6 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
no_overlap.to_owned(),
None,
vec![event_a.clone(), event_b.clone()],
),
),
Expand All @@ -2004,7 +2001,6 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
partial_overlap.to_owned(),
None,
vec![event_a.clone(), event_b.clone(), event_c.clone()],
),
),
Expand All @@ -2014,7 +2010,6 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
partial_overlap.to_owned(),
None,
vec![event_c.clone(), event_d.clone()],
),
),
Expand All @@ -2025,15 +2020,14 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
no_remote_events.to_owned(),
None,
vec![event_c.clone(), event_d.clone()],
),
),
(
// We don't have events for this room locally, and even if the remote room contains
// some events, it's not a limited sync.
no_local_events.to_owned(),
SlidingSyncRoom::new(client.clone(), no_local_events.to_owned(), None, vec![]),
SlidingSyncRoom::new(client.clone(), no_local_events.to_owned(), vec![]),
),
(
// Already limited, but would be marked limited if the flag wasn't ignored (same as
Expand All @@ -2042,7 +2036,6 @@ mod tests {
SlidingSyncRoom::new(
client.clone(),
already_limited.to_owned(),
None,
vec![event_a.clone(), event_b.clone(), event_c.clone()],
),
),
Expand Down
Loading

0 comments on commit 12dc4cb

Please sign in to comment.