Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Add the none filter #2594

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use matrix_sdk::{
RoomListEntry as MatrixRoomListEntry,
};
use matrix_sdk_ui::room_list_service::filters::{
new_filter_all, new_filter_fuzzy_match_room_name, new_filter_normalized_match_room_name,
new_filter_all, new_filter_fuzzy_match_room_name, new_filter_none,
new_filter_normalized_match_room_name,
};
use tokio::sync::RwLock;

Expand Down Expand Up @@ -370,6 +371,7 @@ impl RoomListDynamicEntriesController {

match kind {
Kind::All => self.inner.set_filter(new_filter_all()),
Kind::None => self.inner.set_filter(new_filter_none()),
Kind::NormalizedMatchRoomName { pattern } => {
self.inner.set_filter(new_filter_normalized_match_room_name(&self.client, &pattern))
}
Expand All @@ -391,6 +393,7 @@ impl RoomListDynamicEntriesController {
#[derive(uniffi::Enum)]
pub enum RoomListEntriesDynamicFilterKind {
All,
None,
NormalizedMatchRoomName { pattern: String },
FuzzyMatchRoomName { pattern: String },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ mod tests {
assert!(matcher.fuzzy_match("hello"));
}

#[test]
fn test_empty_pattern() {
let matcher = FuzzyMatcher::new();

assert!(matcher.fuzzy_match("hello"));
}

#[test]
fn test_literal() {
let matcher = FuzzyMatcher::new();
Expand Down
2 changes: 2 additions & 0 deletions crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod all;
mod fuzzy_match_room_name;
mod none;
mod normalized_match_room_name;

pub use all::new_filter as new_filter_all;
pub use fuzzy_match_room_name::new_filter as new_filter_fuzzy_match_room_name;
pub use none::new_filter as new_filter_none;
pub use normalized_match_room_name::new_filter as new_filter_normalized_match_room_name;
use unicode_normalization::{char::is_combining_mark, UnicodeNormalization};

Expand Down
25 changes: 25 additions & 0 deletions crates/matrix-sdk-ui/src/room_list_service/filters/none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use matrix_sdk::RoomListEntry;

/// Create a new filter that will reject all entries.
pub fn new_filter() -> impl Fn(&RoomListEntry) -> bool {
|_room_list_entry| -> bool { false }
}

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

use matrix_sdk::RoomListEntry;
use ruma::room_id;

use super::new_filter;

#[test]
fn test_all_kind_of_room_list_entry() {
let none = new_filter();

assert!(none(&RoomListEntry::Empty).not());
assert!(none(&RoomListEntry::Filled(room_id!("!r0:bar.org").to_owned())).not());
assert!(none(&RoomListEntry::Invalidated(room_id!("!r0:bar.org").to_owned())).not());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ mod tests {
assert!(matcher.normalized_match("hello"));
}

#[test]
fn test_empty_pattern() {
let matcher = NormalizedMatcher::new();

assert!(matcher.normalized_match("hello"));
}

#[test]
fn test_literal() {
let matcher = NormalizedMatcher::new();
Expand Down
21 changes: 16 additions & 5 deletions crates/matrix-sdk-ui/tests/integration/room_list_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use matrix_sdk::Client;
use matrix_sdk_test::async_test;
use matrix_sdk_ui::{
room_list_service::{
filters::{new_filter_all, new_filter_fuzzy_match_room_name},
filters::{new_filter_all, new_filter_fuzzy_match_room_name, new_filter_none},
Error, Input, InputResult, RoomListEntry, RoomListLoadingState, State, SyncIndicator,
ALL_ROOMS_LIST_NAME as ALL_ROOMS, INVITES_LIST_NAME as INVITES,
VISIBLE_ROOMS_LIST_NAME as VISIBLE_ROOMS,
Expand Down Expand Up @@ -120,7 +120,7 @@ macro_rules! entries {

macro_rules! assert_entries_batch {
// `append [$entries]`
( @_ [ $entries:ident ] [ append [ $( $entry:tt )+ ] ; $( $rest:tt )* ] [ $( $accumulator:tt )* ] ) => {
( @_ [ $entries:ident ] [ append [ $( $entry:tt )* ] ; $( $rest:tt )* ] [ $( $accumulator:tt )* ] ) => {
assert_entries_batch!(
@_
[ $entries ]
Expand All @@ -130,7 +130,7 @@ macro_rules! assert_entries_batch {
assert_matches!(
$entries.next(),
Some(&VectorDiff::Append { ref values }) => {
assert_eq!(values, &entries!( $( $entry )+ ));
assert_eq!(values, &entries!( $( $entry )* ));
}
);
]
Expand Down Expand Up @@ -206,7 +206,7 @@ macro_rules! assert_entries_batch {
};

// `reset [$entries]`
( @_ [ $entries:ident ] [ reset [ $( $entry:tt )+ ] ; $( $rest:tt )* ] [ $( $accumulator:tt )* ] ) => {
( @_ [ $entries:ident ] [ reset [ $( $entry:tt )* ] ; $( $rest:tt )* ] [ $( $accumulator:tt )* ] ) => {
assert_entries_batch!(
@_
[ $entries ]
Expand All @@ -216,7 +216,7 @@ macro_rules! assert_entries_batch {
assert_matches!(
$entries.next(),
Some(&VectorDiff::Reset { ref values }) => {
assert_eq!(values, &entries!( $( $entry )+ ));
assert_eq!(values, &entries!( $( $entry )* ));
}
);
]
Expand Down Expand Up @@ -1804,6 +1804,17 @@ async fn test_dynamic_entries_stream() -> Result<(), Error> {
}
assert_pending!(dynamic_entries_stream);

// Now, let's change again the dynamic filter!
dynamic_entries.set_filter(new_filter_none());

// Assert the dynamic entries.
assert_entries_batch! {
[dynamic_entries_stream]
// Receive a `reset` again because the filter has been reset.
reset [];
end;
};

// Now, let's change again the dynamic filter!
dynamic_entries.set_filter(new_filter_all());

Expand Down