ruma_client_api/membership/
mutual_rooms.rs

1//! `GET /_matrix/client/*/user/mutual_rooms/{user_id}`
2//!
3//! Get mutual rooms with another user.
4
5pub mod unstable {
6    //! `/unstable/` ([spec])
7    //!
8    //! [spec]: https://github.com/matrix-org/matrix-spec-proposals/blob/hs/shared-rooms/proposals/2666-get-rooms-in-common.md
9
10    use ruma_common::{
11        OwnedRoomId, OwnedUserId,
12        api::{auth_scheme::AccessToken, request, response},
13        metadata,
14    };
15
16    metadata! {
17        method: GET,
18        rate_limited: true,
19        authentication: AccessToken,
20        history: {
21            unstable("uk.half-shot.msc2666.query_mutual_rooms") => "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms",
22        }
23    }
24
25    /// Request type for the `mutual_rooms` endpoint.
26    #[request(error = crate::Error)]
27    pub struct Request {
28        /// The user to search mutual rooms for.
29        #[ruma_api(query)]
30        pub user_id: OwnedUserId,
31
32        /// The `next_batch_token` returned from a previous response, to get the next batch of
33        /// rooms.
34        #[serde(skip_serializing_if = "Option::is_none")]
35        #[ruma_api(query)]
36        pub batch_token: Option<String>,
37    }
38
39    /// Response type for the `mutual_rooms` endpoint.
40    #[response(error = crate::Error)]
41    pub struct Response {
42        /// A list of rooms the user is in together with the authenticated user.
43        pub joined: Vec<OwnedRoomId>,
44
45        /// An opaque string, returned when the server paginates this response.
46        #[serde(skip_serializing_if = "Option::is_none")]
47        pub next_batch_token: Option<String>,
48    }
49
50    impl Request {
51        /// Creates a new `Request` with the given user id.
52        pub fn new(user_id: OwnedUserId) -> Self {
53            Self { user_id, batch_token: None }
54        }
55
56        /// Creates a new `Request` with the given user id, together with a batch token.
57        pub fn with_token(user_id: OwnedUserId, token: String) -> Self {
58            Self { user_id, batch_token: Some(token) }
59        }
60    }
61
62    impl Response {
63        /// Creates a `Response` with the given room ids.
64        pub fn new(joined: Vec<OwnedRoomId>) -> Self {
65            Self { joined, next_batch_token: None }
66        }
67
68        /// Creates a `Response` with the given room ids, together with a batch token.
69        pub fn with_token(joined: Vec<OwnedRoomId>, token: String) -> Self {
70            Self { joined, next_batch_token: Some(token) }
71        }
72    }
73}