Skip to content

Commit 9848d14

Browse files
Copilotpixlwave
authored andcommitted
feat: Add LowPriority filter implementation and FFI bindings
Co-authored-by: pixlwave <[email protected]>
1 parent 6c944a9 commit 9848d14

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

bindings/matrix-sdk-ffi/src/room_list.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use matrix_sdk_ui::{
1616
room_list_service::filters::{
1717
new_filter_all, new_filter_any, new_filter_category, new_filter_deduplicate_versions,
1818
new_filter_favourite, new_filter_fuzzy_match_room_name, new_filter_invite,
19-
new_filter_joined, new_filter_non_left, new_filter_non_space, new_filter_none,
19+
new_filter_joined, new_filter_low_priority, new_filter_non_left, new_filter_non_space, new_filter_none,
2020
new_filter_normalized_match_room_name, new_filter_unread, BoxedFilterFn, RoomCategory,
2121
},
2222
unable_to_decrypt_hook::UtdHookManager,
@@ -461,6 +461,7 @@ pub enum RoomListEntriesDynamicFilterKind {
461461
Joined,
462462
Unread,
463463
Favourite,
464+
LowPriority,
464465
Invite,
465466
Category { expect: RoomListFilterCategory },
466467
None,
@@ -500,6 +501,7 @@ impl From<RoomListEntriesDynamicFilterKind> for BoxedFilterFn {
500501
Kind::Joined => Box::new(new_filter_joined()),
501502
Kind::Unread => Box::new(new_filter_unread()),
502503
Kind::Favourite => Box::new(new_filter_favourite()),
504+
Kind::LowPriority => Box::new(new_filter_low_priority()),
503505
Kind::Invite => Box::new(new_filter_invite()),
504506
Kind::Category { expect } => Box::new(new_filter_category(expect.into())),
505507
Kind::None => Box::new(new_filter_none()),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2024 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use super::{super::Room, Filter};
16+
17+
struct LowPriorityRoomMatcher<F>
18+
where
19+
F: Fn(&Room) -> bool,
20+
{
21+
is_low_priority: F,
22+
}
23+
24+
impl<F> LowPriorityRoomMatcher<F>
25+
where
26+
F: Fn(&Room) -> bool,
27+
{
28+
fn matches(&self, room: &Room) -> bool {
29+
(self.is_low_priority)(room)
30+
}
31+
}
32+
33+
/// Create a new filter that will filter out rooms that are not marked as
34+
/// low priority (see [`matrix_sdk_base::Room::is_low_priority`]).
35+
pub fn new_filter() -> impl Filter {
36+
let matcher = LowPriorityRoomMatcher { is_low_priority: move |room| room.is_low_priority() };
37+
38+
move |room| -> bool { matcher.matches(room) }
39+
}
40+
41+
#[cfg(test)]
42+
mod 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_low_priority() {
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 = LowPriorityRoomMatcher { is_low_priority: |_| true };
57+
58+
assert!(matcher.matches(&room));
59+
}
60+
61+
#[async_test]
62+
async fn test_is_not_low_priority() {
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 = LowPriorityRoomMatcher { is_low_priority: |_| false };
67+
68+
assert!(matcher.matches(&room).not());
69+
}
70+
}

crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ mod favourite;
5959
mod fuzzy_match_room_name;
6060
mod invite;
6161
mod joined;
62+
mod low_priority;
6263
mod non_left;
6364
mod non_space;
6465
mod none;
@@ -74,6 +75,7 @@ pub use favourite::new_filter as new_filter_favourite;
7475
pub use fuzzy_match_room_name::new_filter as new_filter_fuzzy_match_room_name;
7576
pub use invite::new_filter as new_filter_invite;
7677
pub use joined::new_filter as new_filter_joined;
78+
pub use low_priority::new_filter as new_filter_low_priority;
7779
#[cfg(test)]
7880
use matrix_sdk::Client;
7981
use matrix_sdk::Room;

0 commit comments

Comments
 (0)