From 34863ca80fec3e7254e7ca0eee56b888a8058040 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Wed, 15 Jun 2022 11:45:53 +0200 Subject: [PATCH] client-api: Add support for mutual rooms endpoint (MSC2666) --- crates/ruma-client-api/Cargo.toml | 1 + crates/ruma-client-api/src/membership.rs | 2 + .../src/membership/mutual_rooms.rs | 47 +++++++++++++++++++ crates/ruma/Cargo.toml | 2 + 4 files changed, 52 insertions(+) create mode 100644 crates/ruma-client-api/src/membership/mutual_rooms.rs diff --git a/crates/ruma-client-api/Cargo.toml b/crates/ruma-client-api/Cargo.toml index 1ea56c86..8da6f2aa 100644 --- a/crates/ruma-client-api/Cargo.toml +++ b/crates/ruma-client-api/Cargo.toml @@ -19,6 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"] compat = [] unstable-exhaustive-types = [] unstable-msc2246 = [] +unstable-msc2666 = [] unstable-msc2448 = [] unstable-msc2654 = [] unstable-msc2675 = [] diff --git a/crates/ruma-client-api/src/membership.rs b/crates/ruma-client-api/src/membership.rs index 4809f0c4..82ce0241 100644 --- a/crates/ruma-client-api/src/membership.rs +++ b/crates/ruma-client-api/src/membership.rs @@ -10,6 +10,8 @@ pub mod joined_members; pub mod joined_rooms; pub mod kick_user; pub mod leave_room; +#[cfg(feature = "unstable-msc2666")] +pub mod mutual_rooms; pub mod unban_user; use std::collections::BTreeMap; diff --git a/crates/ruma-client-api/src/membership/mutual_rooms.rs b/crates/ruma-client-api/src/membership/mutual_rooms.rs new file mode 100644 index 00000000..4a523167 --- /dev/null +++ b/crates/ruma-client-api/src/membership/mutual_rooms.rs @@ -0,0 +1,47 @@ +//! `GET /_matrix/client/*/user/mutual_rooms/{user_id}` + +pub mod unstable { + //! `/unstable/` ([spec]) + //! + //! [spec]: https://github.com/matrix-org/matrix-spec-proposals/blob/hs/shared-rooms/proposals/2666-get-rooms-in-common.md + + use ruma_common::{api::ruma_api, OwnedRoomId, UserId}; + + ruma_api! { + metadata: { + description: "Get mutual rooms with another user.", + method: GET, + name: "mutual_rooms", + unstable_path: "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/:user_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The user to search mutual rooms for. + #[ruma_api(path)] + pub user_id: &'a UserId, + } + + response: { + /// A list of rooms the user is in together with the authenticated user. + pub joined: Vec, + } + + error: crate::Error + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given user id. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } + } + + impl Response { + /// Creates a `Response` with the given room ids. + pub fn new(joined: Vec) -> Self { + Self { joined } + } + } +} diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index 74e72955..5bea2f23 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -124,6 +124,7 @@ unstable-msc2448 = [ "ruma-federation-api?/unstable-msc2448" ] unstable-msc2654 = ["ruma-client-api?/unstable-msc2654"] +unstable-msc2666 = ["ruma-client-api?/unstable-msc2666"] unstable-msc2675 = [ "ruma-client-api?/unstable-msc2675", "ruma-common/unstable-msc2675", @@ -164,6 +165,7 @@ __ci = [ "unstable-pre-spec", "unstable-msc1767", "unstable-msc2448", + "unstable-msc2666", "unstable-msc2654", "unstable-msc2675", "unstable-msc2676",