ruma_client_api/config/get_room_account_data.rs
1//! `GET /_matrix/client/*/user/{userId}/rooms/{roomId}/account_data/{type}`
2//!
3//! Gets account data room for a user for a given room
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3useruseridroomsroomidaccount_datatype
9
10 use ruma_common::{
11 api::{request, response, Metadata},
12 metadata,
13 serde::Raw,
14 OwnedRoomId, OwnedUserId,
15 };
16 use ruma_events::{AnyRoomAccountDataEventContent, RoomAccountDataEventType};
17
18 const METADATA: Metadata = metadata! {
19 method: GET,
20 rate_limited: false,
21 authentication: AccessToken,
22 history: {
23 1.0 => "/_matrix/client/r0/user/{user_id}/rooms/{room_id}/account_data/{event_type}",
24 1.1 => "/_matrix/client/v3/user/{user_id}/rooms/{room_id}/account_data/{event_type}",
25 }
26 };
27
28 /// Request type for the `get_room_account_data` endpoint.
29 #[request(error = crate::Error)]
30 pub struct Request {
31 /// User ID of user for whom to retrieve data.
32 #[ruma_api(path)]
33 pub user_id: OwnedUserId,
34
35 /// Room ID for which to retrieve data.
36 #[ruma_api(path)]
37 pub room_id: OwnedRoomId,
38
39 /// Type of data to retrieve.
40 #[ruma_api(path)]
41 pub event_type: RoomAccountDataEventType,
42 }
43
44 /// Response type for the `get_room_account_data` endpoint.
45 #[response(error = crate::Error)]
46 pub struct Response {
47 /// Account data content for the given type.
48 ///
49 /// Since the inner type of the `Raw` does not implement `Deserialize`, you need to use
50 /// `.deserialize_as_unchecked::<T>()` or
51 /// `.cast_ref_unchecked::<T>().deserialize_with_type()` to deserialize it.
52 #[ruma_api(body)]
53 pub account_data: Raw<AnyRoomAccountDataEventContent>,
54 }
55
56 impl Request {
57 /// Creates a new `Request` with the given user ID, room ID and event type.
58 pub fn new(
59 user_id: OwnedUserId,
60 room_id: OwnedRoomId,
61 event_type: RoomAccountDataEventType,
62 ) -> Self {
63 Self { user_id, room_id, event_type }
64 }
65 }
66
67 impl Response {
68 /// Creates a new `Response` with the given account data.
69 pub fn new(account_data: Raw<AnyRoomAccountDataEventContent>) -> Self {
70 Self { account_data }
71 }
72 }
73}