ruma_client_api/tag/
get_tags.rs1pub mod v3 {
6 use ruma_common::{
11 OwnedRoomId, OwnedUserId,
12 api::{auth_scheme::AccessToken, request, response},
13 metadata,
14 };
15 use ruma_events::tag::Tags;
16
17 metadata! {
18 method: GET,
19 rate_limited: false,
20 authentication: AccessToken,
21 history: {
22 1.0 => "/_matrix/client/r0/user/{user_id}/rooms/{room_id}/tags",
23 1.1 => "/_matrix/client/v3/user/{user_id}/rooms/{room_id}/tags",
24 }
25 }
26
27 #[request]
29 pub struct Request {
30 #[ruma_api(path)]
32 pub user_id: OwnedUserId,
33
34 #[ruma_api(path)]
36 pub room_id: OwnedRoomId,
37 }
38
39 #[response]
41 pub struct Response {
42 pub tags: Tags,
44 }
45
46 impl Request {
47 pub fn new(user_id: OwnedUserId, room_id: OwnedRoomId) -> Self {
49 Self { user_id, room_id }
50 }
51 }
52
53 impl Response {
54 pub fn new(tags: Tags) -> Self {
56 Self { tags }
57 }
58 }
59
60 #[cfg(all(test, feature = "server"))]
61 mod server_tests {
62 use assign::assign;
63 use ruma_common::api::OutgoingResponseExt as _;
64 use ruma_events::tag::{TagInfo, Tags};
65 use serde_json::json;
66
67 use super::Response;
68
69 #[test]
70 fn serializing_get_tags_response() {
71 let mut tags = Tags::new();
72 tags.insert("m.favourite".into(), assign!(TagInfo::new(), { order: Some(0.25) }));
73 tags.insert("u.user_tag".into(), assign!(TagInfo::new(), { order: Some(0.11) }));
74 let response = Response { tags };
75
76 let http_response = response.try_into_http_response::<Vec<u8>>().unwrap();
77
78 let json_response: serde_json::Value =
79 serde_json::from_slice(http_response.body()).unwrap();
80 assert_eq!(
81 json_response,
82 json!({
83 "tags": {
84 "m.favourite": {
85 "order": 0.25,
86 },
87 "u.user_tag": {
88 "order": 0.11,
89 }
90 }
91 })
92 );
93 }
94 }
95}