ruma_client_api/user_directory/
search_users.rs1pub mod v3 {
6 use http::header::ACCEPT_LANGUAGE;
11 use js_int::{uint, UInt};
12 use ruma_common::{
13 api::{request, response, Metadata},
14 metadata, OwnedMxcUri, OwnedUserId,
15 };
16 use serde::{Deserialize, Serialize};
17
18 const METADATA: Metadata = metadata! {
19 method: POST,
20 rate_limited: true,
21 authentication: AccessToken,
22 history: {
23 1.0 => "/_matrix/client/r0/user_directory/search",
24 1.1 => "/_matrix/client/v3/user_directory/search",
25 }
26 };
27
28 #[request(error = crate::Error)]
30 pub struct Request {
31 pub search_term: String,
33
34 #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
38 pub limit: UInt,
39
40 #[ruma_api(header = ACCEPT_LANGUAGE)]
46 pub language: Option<String>,
47 }
48
49 #[response(error = crate::Error)]
51 pub struct Response {
52 pub results: Vec<User>,
54
55 pub limited: bool,
57 }
58
59 impl Request {
60 pub fn new(search_term: String) -> Self {
62 Self { search_term, limit: default_limit(), language: None }
63 }
64 }
65
66 impl Response {
67 pub fn new(results: Vec<User>, limited: bool) -> Self {
69 Self { results, limited }
70 }
71 }
72
73 fn default_limit() -> UInt {
74 uint!(10)
75 }
76
77 fn is_default_limit(limit: &UInt) -> bool {
78 limit == &default_limit()
79 }
80
81 #[derive(Clone, Debug, Deserialize, Serialize)]
83 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
84 pub struct User {
85 pub user_id: OwnedUserId,
87
88 #[serde(skip_serializing_if = "Option::is_none")]
90 pub display_name: Option<String>,
91
92 #[serde(skip_serializing_if = "Option::is_none")]
97 #[cfg_attr(
98 feature = "compat-empty-string-null",
99 serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
100 )]
101 pub avatar_url: Option<OwnedMxcUri>,
102 }
103
104 impl User {
105 pub fn new(user_id: OwnedUserId) -> Self {
107 Self { user_id, display_name: None, avatar_url: None }
108 }
109 }
110}