matrix_sdk_ui/room_list_service/filters/
favourite.rs1use super::{super::Room, Filter};
16
17struct FavouriteRoomMatcher<F>
18where
19 F: Fn(&Room) -> bool,
20{
21 is_favourite: F,
22}
23
24impl<F> FavouriteRoomMatcher<F>
25where
26 F: Fn(&Room) -> bool,
27{
28 fn matches(&self, room: &Room) -> bool {
29 (self.is_favourite)(room)
30 }
31}
32
33pub fn new_filter() -> impl Filter {
36 let matcher = FavouriteRoomMatcher { is_favourite: move |room| room.is_favourite() };
37
38 move |room| -> bool { matcher.matches(room) }
39}
40
41#[cfg(test)]
42mod tests {
43 use std::ops::Not;
44
45 use matrix_sdk::test_utils::logged_in_client_with_server;
46 use matrix_sdk_test::async_test;
47 use ruma::room_id;
48
49 use super::{super::new_rooms, *};
50
51 #[async_test]
52 async fn test_is_favourite() {
53 let (client, server) = logged_in_client_with_server().await;
54 let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;
55
56 let matcher = FavouriteRoomMatcher { is_favourite: |_| true };
57
58 assert!(matcher.matches(&room));
59 }
60
61 #[async_test]
62 async fn test_is_not_favourite() {
63 let (client, server) = logged_in_client_with_server().await;
64 let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;
65
66 let matcher = FavouriteRoomMatcher { is_favourite: |_| false };
67
68 assert!(matcher.matches(&room).not());
69 }
70}