Skip to content

Commit

Permalink
refactor(room list): get rid of the sliding sync in `room-list_servic…
Browse files Browse the repository at this point in the history
…e::Room`

This was only used to retrieve events cached in the timeline_queue().
  • Loading branch information
bnjbvr committed Dec 3, 2024
1 parent 991593b commit cfc0aff
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 161 deletions.
14 changes: 6 additions & 8 deletions crates/matrix-sdk-ui/src/room_list_service/filters/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_one_filter() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

{
let filter = |_: &_| true;
Expand All @@ -54,8 +52,8 @@ mod tests {

#[async_test]
async fn test_two_filters() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

{
let filter1 = |_: &_| true;
Expand Down
30 changes: 14 additions & 16 deletions crates/matrix-sdk-ui/src/room_list_service/filters/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_one_filter_is_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = |_: &_| true;
let any = new_filter(vec![Box::new(filter)]);
Expand All @@ -45,8 +43,8 @@ mod tests {

#[async_test]
async fn test_one_filter_is_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = |_: &_| false;
let any = new_filter(vec![Box::new(filter)]);
Expand All @@ -56,8 +54,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_true_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| true;
Expand All @@ -68,8 +66,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_true_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| false;
Expand All @@ -80,8 +78,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_false_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| true;
Expand All @@ -92,8 +90,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_false_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| false;
Expand Down
18 changes: 8 additions & 10 deletions crates/matrix-sdk-ui/src/room_list_service/filters/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,16 @@ pub fn new_filter(expected_category: RoomCategory) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_kind_is_group() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| Some(42) };

Expand All @@ -111,8 +109,8 @@ mod tests {

#[async_test]
async fn test_kind_is_people() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| Some(1) };

Expand All @@ -133,8 +131,8 @@ mod tests {

#[async_test]
async fn test_room_kind_cannot_be_found() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| None };

Expand Down
14 changes: 6 additions & 8 deletions crates/matrix-sdk-ui/src/room_list_service/filters/favourite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ pub fn new_filter() -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_is_favourite() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = FavouriteRoomMatcher { is_favourite: |_| true };

Expand All @@ -62,8 +60,8 @@ mod tests {

#[async_test]
async fn test_is_not_favourite() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = FavouriteRoomMatcher { is_favourite: |_| false };

Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_invite_kind() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = InviteRoomMatcher { state: |_| RoomState::Left };
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_joined_kind() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = JoinedRoomMatcher { state: |_| RoomState::Left };
Expand Down
16 changes: 2 additions & 14 deletions crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ mod normalized_match_room_name;
mod not;
mod unread;

#[cfg(test)]
use std::sync::Arc;

pub use all::new_filter as new_filter_all;
pub use any::new_filter as new_filter_any;
pub use category::{new_filter as new_filter_category, RoomCategory};
Expand All @@ -75,7 +72,7 @@ pub use fuzzy_match_room_name::new_filter as new_filter_fuzzy_match_room_name;
pub use invite::new_filter as new_filter_invite;
pub use joined::new_filter as new_filter_joined;
#[cfg(test)]
use matrix_sdk::{test_utils::logged_in_client_with_server, Client, SlidingSync};
use matrix_sdk::Client;
#[cfg(test)]
use matrix_sdk_test::{JoinedRoomBuilder, SyncResponseBuilder};
pub use non_left::new_filter as new_filter_non_left;
Expand Down Expand Up @@ -116,7 +113,6 @@ pub(super) async fn new_rooms<const N: usize>(
room_ids: [&RoomId; N],
client: &Client,
server: &MockServer,
sliding_sync: &Arc<SlidingSync>,
) -> [Room; N] {
let mut response_builder = SyncResponseBuilder::default();

Expand All @@ -135,15 +131,7 @@ pub(super) async fn new_rooms<const N: usize>(

let _response = client.sync_once(Default::default()).await.unwrap();

room_ids.map(|room_id| Room::new(client.get_room(room_id).unwrap(), sliding_sync))
}

#[cfg(test)]
pub(super) async fn client_and_server_prelude() -> (Client, MockServer, Arc<SlidingSync>) {
let (client, server) = logged_in_client_with_server().await;
let sliding_sync = Arc::new(client.sliding_sync("foo").unwrap().build().await.unwrap());

(client, server, sliding_sync)
room_ids.map(|room_id| Room::new(client.get_room(room_id).unwrap()))
}

#[cfg(test)]
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_non_left_kind_of_room_list_entry() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = NonLeftRoomMatcher { state: |_| RoomState::Left };
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ pub fn new_filter() -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_kind_of_room_list_entry() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let none = new_filter();

Expand Down
14 changes: 6 additions & 8 deletions crates/matrix-sdk-ui/src/room_list_service/filters/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ pub fn new_filter(filter: BoxedFilterFn) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = Box::new(|_: &_| true);
let not = new_filter(filter);
Expand All @@ -47,8 +45,8 @@ mod tests {

#[async_test]
async fn test_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = Box::new(|_: &_| false);
let not = new_filter(filter);
Expand Down
Loading

0 comments on commit cfc0aff

Please sign in to comment.