-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Moaaar filters: add
all
, any
, not
, unread
and `cate…
…gory` filters feat(ui): Moaaar filters: add `all`, `any`, `not`, `unread` and `category` filters
- Loading branch information
Showing
16 changed files
with
665 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use super::{super::room_list::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)) } | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::ops::Not; | ||
|
||
use matrix_sdk::RoomListEntry; | ||
use ruma::room_id; | ||
|
||
use super::new_filter; | ||
|
||
#[test] | ||
fn test_one_filter_is_true() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter = |_: &_| true; | ||
let any = new_filter(vec![Box::new(filter)]); | ||
|
||
assert!(any(&room_list_entry)); | ||
} | ||
|
||
#[test] | ||
fn test_one_filter_is_false() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter = |_: &_| false; | ||
let any = new_filter(vec![Box::new(filter)]); | ||
|
||
assert!(any(&room_list_entry).not()); | ||
} | ||
|
||
#[test] | ||
fn test_two_filters_with_true_true() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter1 = |_: &_| true; | ||
let filter2 = |_: &_| true; | ||
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]); | ||
|
||
assert!(any(&room_list_entry)); | ||
} | ||
|
||
#[test] | ||
fn test_two_filters_with_true_false() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter1 = |_: &_| true; | ||
let filter2 = |_: &_| false; | ||
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]); | ||
|
||
assert!(any(&room_list_entry)); | ||
} | ||
|
||
#[test] | ||
fn test_two_filters_with_false_true() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter1 = |_: &_| false; | ||
let filter2 = |_: &_| true; | ||
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]); | ||
|
||
assert!(any(&room_list_entry)); | ||
} | ||
|
||
#[test] | ||
fn test_two_filters_with_false_false() { | ||
let room_list_entry = RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned()); | ||
|
||
let filter1 = |_: &_| false; | ||
let filter2 = |_: &_| false; | ||
let any = new_filter(vec![Box::new(filter1), Box::new(filter2)]); | ||
|
||
assert!(any(&room_list_entry).not()); | ||
} | ||
} |
Oops, something went wrong.