ruma_client_api/membership/mutual_rooms.rs
1//! `GET /_matrix/client/*/mutual_rooms`
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]
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]
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}
74
75pub mod v1 {
76 //! `/v1/` ([spec])
77 //!
78 //! [spec]: https://spec.matrix.org/v1.19/client-server-api/#get_matrixclientv1mutual_rooms
79
80 use js_int::UInt;
81 use ruma_common::{
82 OwnedRoomId, OwnedUserId,
83 api::{auth_scheme::AccessToken, request, response},
84 metadata,
85 };
86
87 metadata! {
88 method: GET,
89 rate_limited: true,
90 authentication: AccessToken,
91 history: {
92 1.19 | stable("uk.half-shot.msc2666.query_mutual_rooms.stable") => "/_matrix/client/v1/mutual_rooms",
93 }
94 }
95
96 /// Request type for the `mutual_rooms` endpoint.
97 #[request]
98 pub struct Request {
99 /// The user to search mutual rooms for.
100 #[ruma_api(query)]
101 pub user_id: OwnedUserId,
102
103 /// The `next_batch` returned from a previous response, to get the next batch of
104 /// rooms.
105 #[serde(skip_serializing_if = "Option::is_none")]
106 #[ruma_api(query)]
107 pub from: Option<String>,
108 }
109
110 /// Response type for the `mutual_rooms` endpoint.
111 #[response]
112 pub struct Response {
113 /// The total number of rooms the user is in together with the authenticated user.
114 ///
115 /// This is unaffected by batching.
116 pub count: UInt,
117
118 /// A list of rooms the user is in together with the authenticated user.
119 pub joined: Vec<OwnedRoomId>,
120
121 /// An opaque string, returned when the server paginates this response.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub next_batch: Option<String>,
124 }
125
126 impl Request {
127 /// Creates a new `Request` with the given user id.
128 pub fn new(user_id: OwnedUserId) -> Self {
129 Self { user_id, from: None }
130 }
131
132 /// Creates a new `Request` with the given user id, together with a batch token.
133 pub fn with_batch_token(user_id: OwnedUserId, token: String) -> Self {
134 Self { user_id, from: Some(token) }
135 }
136 }
137
138 impl Response {
139 /// Creates a `Response` with the given count and room IDs.
140 pub fn new(count: UInt, joined: Vec<OwnedRoomId>) -> Self {
141 Self { count, joined, next_batch: None }
142 }
143
144 /// Creates a `Response` with the given count and room IDs, together with a batch token.
145 pub fn with_batch_token(count: UInt, joined: Vec<OwnedRoomId>, token: String) -> Self {
146 Self { count, joined, next_batch: Some(token) }
147 }
148 }
149}