Skip to content

Commit

Permalink
fix(ui): Set visible_rooms with a default range
Browse files Browse the repository at this point in the history
fix(ui): Set `visible_rooms` with a default range
  • Loading branch information
Hywan authored Jun 15, 2023
2 parents 52d2fa1 + 1c48039 commit 1f6a0b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 8 additions & 3 deletions crates/matrix-sdk-ui/src/room_list/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(), {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 10 additions & 12 deletions crates/matrix-sdk-ui/tests/integration/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""],
],
Expand Down Expand Up @@ -345,7 +345,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
"ranges": [[0, 99]],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -378,7 +378,7 @@ async fn test_sync_from_init_to_enjoy() -> Result<(), Error> {
"ranges": [[0, 149]],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -451,7 +451,7 @@ async fn test_sync_resumes_from_previous_state() -> Result<(), Error> {
"ranges": [[0, 9]],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -486,7 +486,7 @@ async fn test_sync_resumes_from_previous_state() -> Result<(), Error> {
"ranges": [[0, 9]],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -580,7 +580,7 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> {
},
VISIBLE_ROOMS: {
// Hello new list.
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -856,7 +856,7 @@ async fn test_entries_stream() -> Result<(), Error> {
],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
},
},
},
Expand Down Expand Up @@ -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]],
},
},
},
Expand Down Expand Up @@ -1571,7 +1569,7 @@ async fn test_input_viewport() -> Result<(), Error> {
"ranges": [[0, 49]],
},
VISIBLE_ROOMS: {
"ranges": [],
"ranges": [[0, 19]],
"timeline_limit": 20,
},
},
Expand Down

0 comments on commit 1f6a0b2

Please sign in to comment.