diff --git a/crates/matrix-sdk-ui/src/room_list/state.rs b/crates/matrix-sdk-ui/src/room_list/state.rs index 12cf3fd0979..34d9c4cc4a6 100644 --- a/crates/matrix-sdk-ui/src/room_list/state.rs +++ b/crates/matrix-sdk-ui/src/room_list/state.rs @@ -3,7 +3,7 @@ use std::future::ready; use async_trait::async_trait; -use matrix_sdk::{SlidingSync, SlidingSyncList, SlidingSyncMode}; +use matrix_sdk::{sliding_sync::Range, SlidingSync, SlidingSyncList, SlidingSyncMode}; use once_cell::sync::Lazy; use ruma::{ api::client::sync::sync_events::v4::SyncRequestListFilters, assign, events::StateEventType, @@ -85,13 +85,18 @@ trait Action { struct AddVisibleRoomsList; +/// Default range for the `VISIBLE_ROOMS_LIST_NAME` list. +pub const VISIBLE_ROOMS_DEFAULT_RANGE: Range = 0..=19; + #[async_trait] impl Action for AddVisibleRoomsList { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync .add_list( SlidingSyncList::builder(VISIBLE_ROOMS_LIST_NAME) - .sync_mode(SlidingSyncMode::new_selective()) + .sync_mode( + SlidingSyncMode::new_selective().add_range(VISIBLE_ROOMS_DEFAULT_RANGE), + ) .timeline_limit(20) .required_state(vec![(StateEventType::RoomEncryption, "".to_owned())]) .filters(Some(assign!(SyncRequestListFilters::default(), { @@ -257,7 +262,7 @@ mod tests { sliding_sync .on_list(VISIBLE_ROOMS_LIST_NAME, |list| ready(matches!( list.sync_mode(), - SlidingSyncMode::Selective { ranges } if ranges.is_empty() + SlidingSyncMode::Selective { ranges } if ranges == vec![VISIBLE_ROOMS_DEFAULT_RANGE] ))) .await, Some(true) diff --git a/crates/matrix-sdk-ui/tests/integration/room_list.rs b/crates/matrix-sdk-ui/tests/integration/room_list.rs index 0422aaa6cd6..7898687db85 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list.rs @@ -302,7 +302,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> { "timeline_limit": 1, }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], "required_state": [ ["m.room.encryption", ""], ], @@ -345,7 +345,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> { "ranges": [[0, 99]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -378,7 +378,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> { "ranges": [[0, 149]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -451,7 +451,7 @@ async fn test_sync_resumes_from_previous_state() -> Result<(), Error> { "ranges": [[0, 9]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -486,7 +486,7 @@ async fn test_sync_resumes_from_previous_state() -> Result<(), Error> { "ranges": [[0, 9]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -580,7 +580,7 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> { }, VISIBLE_ROOMS: { // Hello new list. - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -856,7 +856,7 @@ async fn test_entries_stream() -> Result<(), Error> { ], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -979,12 +979,10 @@ async fn test_entries_stream_with_updated_filter() -> Result<(), Error> { assert request = { "lists": { ALL_ROOMS: { - "ranges": [ - [0, 9], - ], + "ranges": [[0, 9]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], }, }, }, @@ -1571,7 +1569,7 @@ async fn test_input_viewport() -> Result<(), Error> { "ranges": [[0, 49]], }, VISIBLE_ROOMS: { - "ranges": [], + "ranges": [[0, 19]], "timeline_limit": 20, }, },