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