Skip to content

Commit 1fe71ac

Browse files
authored
change(room_list): request space rooms through sliding sync and expose a room list filter for them (#5479)
This is a breaking change as spaces are now requested through sliding sync and they need to manually be excluded from the room list by using the newly introduced non-space filter.
1 parent 0e054de commit 1fe71ac

File tree

8 files changed

+72
-11
lines changed

8 files changed

+72
-11
lines changed

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

Lines changed: 5 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_none,
19+
new_filter_joined, 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,
@@ -454,7 +454,10 @@ impl RoomListDynamicEntriesController {
454454
pub enum RoomListEntriesDynamicFilterKind {
455455
All { filters: Vec<RoomListEntriesDynamicFilterKind> },
456456
Any { filters: Vec<RoomListEntriesDynamicFilterKind> },
457+
NonSpace,
457458
NonLeft,
459+
// Not { filter: RoomListEntriesDynamicFilterKind } - requires recursive enum
460+
// support in uniffi https://github.com/mozilla/uniffi-rs/issues/396
458461
Joined,
459462
Unread,
460463
Favourite,
@@ -493,6 +496,7 @@ impl From<RoomListEntriesDynamicFilterKind> for BoxedFilterFn {
493496
filters.into_iter().map(|filter| BoxedFilterFn::from(filter)).collect(),
494497
)),
495498
Kind::NonLeft => Box::new(new_filter_non_left()),
499+
Kind::NonSpace => Box::new(new_filter_non_space()),
496500
Kind::Joined => Box::new(new_filter_joined()),
497501
Kind::Unread => Box::new(new_filter_unread()),
498502
Kind::Favourite => Box::new(new_filter_favourite()),

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ All notable changes to this project will be documented in this file.
77
## [Unreleased] - ReleaseDate
88

99
### Features
10-
10+
- [**breaking**] Space rooms are now being retrieved through sliding sync and the newly introduced
11+
[`room_list_service::filters::new_filter_non_space`] filter should be used to exclude them from any room list.
12+
([5479](https://github.com/matrix-org/matrix-rust-sdk/pull/5479))
1113
- [**breaking**] [`Timeline::send_gallery()`] now automatically fills in the thread relationship,
1214
based on the timeline focus. As a result, the `GalleryConfig::reply()` builder method has been
1315
replaced with `GalleryConfig::in_reply_to`, and only takes an optional event id (the event that is

crates/matrix-sdk-ui/src/notification_client.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use ruma::{
2727
EventId, OwnedEventId, OwnedRoomId, RoomId, UserId,
2828
api::client::sync::sync_events::v5 as http,
2929
assign,
30-
directory::RoomTypeFilter,
3130
events::{
3231
AnyFullStateEventContent, AnyMessageLikeEventContent, AnyStateEvent,
3332
AnySyncMessageLikeEvent, AnySyncTimelineEvent, FullStateEventContent, StateEventType,
@@ -496,7 +495,6 @@ impl NotificationClient {
496495
.required_state(required_state.clone())
497496
.filters(Some(assign!(http::request::ListFilters::default(), {
498497
is_invite: Some(true),
499-
not_room_types: vec![RoomTypeFilter::Space],
500498
})));
501499

502500
let sync = self

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
@@ -60,6 +60,7 @@ mod fuzzy_match_room_name;
6060
mod invite;
6161
mod joined;
6262
mod non_left;
63+
mod non_space;
6364
mod none;
6465
mod normalized_match_room_name;
6566
mod not;
@@ -79,6 +80,7 @@ use matrix_sdk::Room;
7980
#[cfg(test)]
8081
use matrix_sdk_test::{JoinedRoomBuilder, SyncResponseBuilder};
8182
pub use non_left::new_filter as new_filter_non_left;
83+
pub use non_space::new_filter as new_filter_non_space;
8284
pub use none::new_filter as new_filter_none;
8385
pub use normalized_match_room_name::new_filter as new_filter_normalized_match_room_name;
8486
pub use not::new_filter as new_filter_not;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2025 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 NonSpaceRoomMatcher<F>
18+
where
19+
F: Fn(&Room) -> bool,
20+
{
21+
is_not_space: F,
22+
}
23+
24+
impl<F> NonSpaceRoomMatcher<F>
25+
where
26+
F: Fn(&Room) -> bool,
27+
{
28+
fn matches(&self, room: &Room) -> bool {
29+
(self.is_not_space)(room)
30+
}
31+
}
32+
33+
/// Create a new filter that will filter out rooms that are not spaces, i.e.
34+
/// room with a `room_type` of `m.space` as defined in <https://spec.matrix.org/latest/client-server-api/#spaces>
35+
pub fn new_filter() -> impl Filter {
36+
let matcher = NonSpaceRoomMatcher { is_not_space: move |room| !room.is_space() };
37+
38+
move |room| -> bool { matcher.matches(room) }
39+
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use matrix_sdk::test_utils::logged_in_client_with_server;
44+
use matrix_sdk_test::async_test;
45+
use ruma::room_id;
46+
47+
use super::{super::new_rooms, *};
48+
49+
#[async_test]
50+
async fn test_not_space() {
51+
let (client, server) = logged_in_client_with_server().await;
52+
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;
53+
54+
let matcher = NonSpaceRoomMatcher { is_not_space: |_| false };
55+
assert!(!matcher.matches(&room));
56+
57+
let matcher = NonSpaceRoomMatcher { is_not_space: |_| true };
58+
assert!(matcher.matches(&room));
59+
}
60+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use matrix_sdk::{
6868
pub use room_list::*;
6969
use ruma::{
7070
OwnedRoomId, RoomId, UInt, api::client::sync::sync_events::v5 as http, assign,
71-
directory::RoomTypeFilter, events::StateEventType,
71+
events::StateEventType,
7272
};
7373
pub use state::*;
7474
use thiserror::Error;
@@ -177,7 +177,6 @@ impl RoomListService {
177177
// If unset, both invited and joined rooms are returned. If false, no invited rooms are
178178
// returned. If true, only invited rooms are returned.
179179
is_invite: None,
180-
not_room_types: vec![RoomTypeFilter::Space],
181180
}))),
182181
)
183182
.await

crates/matrix-sdk-ui/tests/integration/notification_client.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ async fn test_notification_client_sliding_sync() {
233233
],
234234
"filters": {
235235
"is_invite": true,
236-
"not_room_types": ["m.space"],
237236
},
238237
"timeline_limit": 8,
239238
}
@@ -726,7 +725,6 @@ async fn test_notification_client_mixed() {
726725
],
727726
"filters": {
728727
"is_invite": true,
729-
"not_room_types": ["m.space"],
730728
},
731729
"timeline_limit": 8,
732730
}

crates/matrix-sdk-ui/tests/integration/room_list_service.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
370370
["m.room.history_visibility", ""],
371371
["io.element.functional_members", ""],
372372
],
373-
"filters": {
374-
"not_room_types": ["m.space"],
375-
},
373+
"filters": {},
376374
"timeline_limit": 1,
377375
},
378376
},

0 commit comments

Comments
 (0)