mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-16 12:43:01 -04:00
fix(ui): Set visible_rooms with a default range.
The MSC3575 says that if no `ranges` for a list is provided, it defaults to `0..=99`. We don't want that! This patch sets the default value to `0..=19` for the `visible_rooms`.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user