Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 85814e9

Browse files
committed
implement unstable MSC2666 support for querying mutual rooms
matrix-org/matrix-spec-proposals#2666 Signed-off-by: strawberry <[email protected]>
1 parent 0dc3ace commit 85814e9

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,16 @@ features = [
252252
"federation-api",
253253
"push-gateway-api-c",
254254
"state-res",
255-
"unstable-msc2448",
256-
"unstable-msc3575",
257255
"unstable-exhaustive-types",
258256
"ring-compat",
259257
"unstable-unspecified",
258+
"unstable-msc2448",
259+
"unstable-msc2666",
260260
"unstable-msc2867",
261261
"unstable-msc2870",
262262
"unstable-msc3026",
263263
"unstable-msc3061",
264+
"unstable-msc3575",
264265
"unstable-msc4121",
265266
"unstable-extensible-events",
266267
]

src/api/client_server/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod thirdparty;
2929
mod threads;
3030
mod to_device;
3131
mod typing;
32+
mod unstable;
3233
mod unversioned;
3334
mod user_directory;
3435
mod voip;
@@ -64,6 +65,7 @@ pub use thirdparty::*;
6465
pub use threads::*;
6566
pub use to_device::*;
6667
pub use typing::*;
68+
pub use unstable::*;
6769
pub use unversioned::*;
6870
pub use user_directory::*;
6971
pub use voip::*;

src/api/client_server/unstable.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use ruma::{
2+
api::client::{error::ErrorKind, membership::mutual_rooms},
3+
OwnedRoomId,
4+
};
5+
6+
use crate::{services, Error, Result, Ruma};
7+
8+
/// # `GET /_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`
9+
///
10+
/// Gets all the rooms the sender shares with the specified user.
11+
///
12+
/// TODO: Implement pagination, currently this just returns everything
13+
///
14+
/// An implementation of [MSC2666](https://github.com/matrix-org/matrix-spec-proposals/pull/2666)
15+
pub async fn get_mutual_rooms_route(
16+
body: Ruma<mutual_rooms::unstable::Request>,
17+
) -> Result<mutual_rooms::unstable::Response> {
18+
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
19+
20+
if sender_user == &body.user_id {
21+
return Err(Error::BadRequest(
22+
ErrorKind::Unknown,
23+
"You cannot request rooms in common with yourself.",
24+
));
25+
}
26+
27+
if !services().users.exists(&body.user_id)? {
28+
return Ok(mutual_rooms::unstable::Response {
29+
joined: vec![],
30+
next_batch_token: None,
31+
});
32+
}
33+
34+
let mutual_rooms: Vec<OwnedRoomId> = services()
35+
.rooms
36+
.user
37+
.get_shared_rooms(vec![sender_user.clone(), body.user_id.clone()])?
38+
.filter_map(Result::ok)
39+
.collect();
40+
41+
Ok(mutual_rooms::unstable::Response {
42+
joined: mutual_rooms,
43+
next_batch_token: None,
44+
})
45+
}

src/api/client_server/unversioned.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ pub async fn get_supported_versions_route(
4545
unstable_features: BTreeMap::from_iter([
4646
("org.matrix.e2e_cross_signing".to_owned(), true),
4747
("org.matrix.msc2285.stable".to_owned(), true),
48+
("uk.half-shot.msc2666.query_mutual_rooms".to_owned(), true),
4849
("org.matrix.msc2836".to_owned(), true),
4950
("org.matrix.msc2946".to_owned(), true),
50-
("org.matrix.msc3827".to_owned(), true),
5151
("org.matrix.msc3026.busy_presence".to_owned(), true),
52+
("org.matrix.msc3827".to_owned(), true),
5253
]),
5354
};
5455

src/routes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ pub fn routes() -> Router {
206206
.ruma_route(server_server::get_keys_route)
207207
.ruma_route(server_server::claim_keys_route)
208208
.ruma_route(server_server::get_hierarchy_route)
209+
.ruma_route(client_server::get_mutual_rooms_route)
209210
.ruma_route(client_server::well_known_support)
210211
.route("/_conduwuit/server_version", get(client_server::conduwuit_server_version))
211212
.route("/_matrix/client/r0/rooms/:room_id/initialSync", get(initial_sync))

0 commit comments

Comments
 (0)