Skip to content

Commit

Permalink
feat(ui): RoomList::entries* manipulates a Room.
Browse files Browse the repository at this point in the history
This patch is quite big… `RoomList::entries*` now returns `Room`s
instead of `RoomListEntry`s. This patch consequently updates all the
filters to manipulate `Room` instead of `RoomListEntry`. No more
`Client` is needed in the filters.

This patch also disables the `RoomList` integration test suite in order
to keep this patch “small”.
  • Loading branch information
Hywan committed Jun 19, 2024
1 parent 8d03e34 commit c65c6f1
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 486 deletions.
38 changes: 21 additions & 17 deletions crates/matrix-sdk-ui/src/room_list_service/filters/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,80 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::{super::room_list::BoxedFilterFn, Filter};
use super::{BoxedFilterFn, Filter};

/// Create a new filter that will run multiple filters. It returns `false` if at
/// least one of the filter returns `false`.
pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
move |room_list_entry| -> bool { filters.iter().all(|filter| filter(room_list_entry)) }
move |room| -> bool { filters.iter().all(|filter| filter(room)) }
}

#[cfg(test)]
mod tests {
use std::ops::Not;

use matrix_sdk::RoomListEntry;
use ruma::room_id;
use matrix_sdk_test::async_test;

use super::new_filter;
use super::{
super::{client_and_server_prelude, new_room, Room},
*,
};

#[test]
fn test_one_filter() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_one_filter() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

{
let filter = |_: &_| true;
let all = new_filter(vec![Box::new(filter)]);

assert!(all(&room_list_entry));
assert!(all(&room));
}

{
let filter = |_: &_| false;
let all = new_filter(vec![Box::new(filter)]);

assert!(all(&room_list_entry).not());
assert!(all(&room).not());
}
}

#[test]
fn test_two_filters() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_two_filters() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

{
let filter1 = |_: &_| true;
let filter2 = |_: &_| true;
let all = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(all(&room_list_entry));
assert!(all(&room));
}

{
let filter1 = |_: &_| true;
let filter2 = |_: &_| false;
let all = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(all(&room_list_entry).not());
assert!(all(&room).not());
}

{
let filter1 = |_: &_| false;
let filter2 = |_: &_| true;
let all = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(all(&room_list_entry).not());
assert!(all(&room).not());
}

{
let filter1 = |_: &_| false;
let filter2 = |_: &_| false;
let all = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(all(&room_list_entry).not());
assert!(all(&room).not());
}
}
}
66 changes: 37 additions & 29 deletions crates/matrix-sdk-ui/src/room_list_service/filters/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,92 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::{super::room_list::BoxedFilterFn, Filter};
use super::{BoxedFilterFn, Filter};

/// Create a new filter that will run multiple filters. It returns `true` if at
/// least one of the filter returns `true`.
pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
move |room_list_entry| -> bool { filters.iter().any(|filter| filter(room_list_entry)) }
move |room| -> bool { filters.iter().any(|filter| filter(room)) }
}

#[cfg(test)]
mod tests {
use std::ops::Not;

use matrix_sdk::RoomListEntry;
use ruma::room_id;
use matrix_sdk_test::async_test;

use super::new_filter;
use super::{
super::{client_and_server_prelude, new_room},
*,
};

#[test]
fn test_one_filter_is_true() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_one_filter_is_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter = |_: &_| true;
let any = new_filter(vec![Box::new(filter)]);

assert!(any(&room_list_entry));
assert!(any(&room));
}

#[test]
fn test_one_filter_is_false() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_one_filter_is_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter = |_: &_| false;
let any = new_filter(vec![Box::new(filter)]);

assert!(any(&room_list_entry).not());
assert!(any(&room).not());
}

#[test]
fn test_two_filters_with_true_true() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_two_filters_with_true_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| true;
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(any(&room_list_entry));
assert!(any(&room));
}

#[test]
fn test_two_filters_with_true_false() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_two_filters_with_true_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| false;
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(any(&room_list_entry));
assert!(any(&room));
}

#[test]
fn test_two_filters_with_false_true() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_two_filters_with_false_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| true;
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(any(&room_list_entry));
assert!(any(&room));
}

#[test]
fn test_two_filters_with_false_false() {
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned());
#[async_test]
async fn test_two_filters_with_false_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let room = new_room(&client, &server, &sliding_sync).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| false;
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]);

assert!(any(&room_list_entry).not());
assert!(any(&room).not());
}
}
Loading

0 comments on commit c65c6f1

Please sign in to comment.