1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! `GET /_matrix/client/*/user/mutual_rooms/{user_id}`
//!
//! Get mutual rooms with another user.

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::{request, response, Metadata},
        metadata, OwnedRoomId, OwnedUserId,
    };

    const METADATA: Metadata = metadata! {
        method: GET,
        rate_limited: true,
        authentication: AccessToken,
        history: {
            unstable => "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms",
        }
    };

    /// Request type for the `mutual_rooms` endpoint.
    #[request(error = crate::Error)]
    pub struct Request {
        /// The user to search mutual rooms for.
        #[ruma_api(query)]
        pub user_id: OwnedUserId,

        /// The `next_batch_token` returned from a previous response, to get the next batch of
        /// rooms.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[ruma_api(query)]
        pub batch_token: Option<String>,
    }

    /// Response type for the `mutual_rooms` endpoint.
    #[response(error = crate::Error)]
    pub struct Response {
        /// A list of rooms the user is in together with the authenticated user.
        pub joined: Vec<OwnedRoomId>,

        /// An opaque string, returned when the server paginates this response.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub next_batch_token: Option<String>,
    }

    impl Request {
        /// Creates a new `Request` with the given user id.
        pub fn new(user_id: OwnedUserId) -> Self {
            Self { user_id, batch_token: None }
        }

        /// Creates a new `Request` with the given user id, together with a batch token.
        pub fn with_token(user_id: OwnedUserId, token: String) -> Self {
            Self { user_id, batch_token: Some(token) }
        }
    }

    impl Response {
        /// Creates a `Response` with the given room ids.
        pub fn new(joined: Vec<OwnedRoomId>) -> Self {
            Self { joined, next_batch_token: None }
        }

        /// Creates a `Response` with the given room ids, together with a batch token.
        pub fn with_token(joined: Vec<OwnedRoomId>, token: String) -> Self {
            Self { joined, next_batch_token: Some(token) }
        }
    }
}