matrix_sdk_ui/room_list_service/filters/
favourite.rsuse super::{super::Room, Filter};
struct FavouriteRoomMatcher<F>
where
F: Fn(&Room) -> bool,
{
is_favourite: F,
}
impl<F> FavouriteRoomMatcher<F>
where
F: Fn(&Room) -> bool,
{
fn matches(&self, room: &Room) -> bool {
(self.is_favourite)(room)
}
}
pub fn new_filter() -> impl Filter {
let matcher = FavouriteRoomMatcher { is_favourite: move |room| room.is_favourite() };
move |room| -> bool { matcher.matches(room) }
}
#[cfg(test)]
mod tests {
use std::ops::Not;
use matrix_sdk_test::async_test;
use ruma::room_id;
use super::{
super::{client_and_server_prelude, 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 matcher = FavouriteRoomMatcher { is_favourite: |_| true };
assert!(matcher.matches(&room));
}
#[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 matcher = FavouriteRoomMatcher { is_favourite: |_| false };
assert!(matcher.matches(&room).not());
}
}