ruma_federation_api/query/
get_profile_information.rs1pub mod v1 {
6 use std::collections::btree_map;
11
12 use ruma_common::{
13 OwnedUserId,
14 api::{request, response},
15 metadata,
16 profile::{ProfileFieldName, ProfileFieldValue, StaticProfileField, UserProfile},
17 };
18 use serde_json::Value as JsonValue;
19
20 use crate::authentication::ServerSignatures;
21
22 metadata! {
23 method: GET,
24 rate_limited: false,
25 authentication: ServerSignatures,
26 path: "/_matrix/federation/v1/query/profile",
27 }
28
29 #[request]
31 pub struct Request {
32 #[ruma_api(query)]
34 pub user_id: OwnedUserId,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
38 #[ruma_api(query)]
39 pub field: Option<ProfileFieldName>,
40 }
41
42 impl Request {
43 pub fn new(user_id: OwnedUserId) -> Self {
45 Self { user_id, field: None }
46 }
47 }
48
49 #[response]
51 #[derive(Default)]
52 pub struct Response {
53 #[ruma_api(body)]
55 pub data: UserProfile,
56 }
57
58 impl Response {
59 pub fn new() -> Self {
61 Self::default()
62 }
63
64 pub fn get(&self, field: &str) -> Option<&JsonValue> {
66 self.data.get(field)
67 }
68
69 pub fn get_static<F: StaticProfileField>(
75 &self,
76 ) -> Result<Option<F::Value>, serde_json::Error> {
77 self.data.get_static::<F>()
78 }
79
80 pub fn iter(&self) -> btree_map::Iter<'_, String, JsonValue> {
82 self.data.iter()
83 }
84
85 pub fn set(&mut self, field: String, value: JsonValue) {
87 self.data.set(field, value);
88 }
89 }
90
91 impl From<UserProfile> for Response {
92 fn from(value: UserProfile) -> Self {
93 Self { data: value }
94 }
95 }
96
97 impl FromIterator<(String, JsonValue)> for Response {
98 fn from_iter<T: IntoIterator<Item = (String, JsonValue)>>(iter: T) -> Self {
99 Self { data: UserProfile::from_iter(iter) }
100 }
101 }
102
103 impl FromIterator<(ProfileFieldName, JsonValue)> for Response {
104 fn from_iter<T: IntoIterator<Item = (ProfileFieldName, JsonValue)>>(iter: T) -> Self {
105 Self { data: UserProfile::from_iter(iter) }
106 }
107 }
108
109 impl FromIterator<ProfileFieldValue> for Response {
110 fn from_iter<T: IntoIterator<Item = ProfileFieldValue>>(iter: T) -> Self {
111 Self { data: UserProfile::from_iter(iter) }
112 }
113 }
114
115 impl Extend<(String, JsonValue)> for Response {
116 fn extend<T: IntoIterator<Item = (String, JsonValue)>>(&mut self, iter: T) {
117 self.data.extend(iter);
118 }
119 }
120
121 impl Extend<(ProfileFieldName, JsonValue)> for Response {
122 fn extend<T: IntoIterator<Item = (ProfileFieldName, JsonValue)>>(&mut self, iter: T) {
123 self.data.extend(iter);
124 }
125 }
126
127 impl Extend<ProfileFieldValue> for Response {
128 fn extend<T: IntoIterator<Item = ProfileFieldValue>>(&mut self, iter: T) {
129 self.data.extend(iter);
130 }
131 }
132
133 impl IntoIterator for Response {
134 type Item = (String, JsonValue);
135 type IntoIter = btree_map::IntoIter<String, JsonValue>;
136
137 fn into_iter(self) -> Self::IntoIter {
138 self.data.into_iter()
139 }
140 }
141}