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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
pub mod v3 {
use js_int::{uint, UInt};
use ruma_common::{api::ruma_api, OwnedMxcUri, OwnedUserId};
use serde::{Deserialize, Serialize};
ruma_api! {
metadata: {
description: "Performs a search for users.",
method: POST,
name: "search_users",
r0_path: "/_matrix/client/r0/user_directory/search",
stable_path: "/_matrix/client/v3/user_directory/search",
rate_limited: true,
authentication: AccessToken,
added: 1.0,
}
request: {
pub search_term: &'a str,
#[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
pub limit: UInt,
#[ruma_api(header = ACCEPT_LANGUAGE)]
pub language: Option<String>,
}
response: {
pub results: Vec<User>,
pub limited: bool,
}
error: crate::Error
}
impl<'a> Request<'a> {
pub fn new(search_term: &'a str) -> Self {
Self { search_term, limit: default_limit(), language: None }
}
}
impl Response {
pub fn new(results: Vec<User>, limited: bool) -> Self {
Self { results, limited }
}
}
fn default_limit() -> UInt {
uint!(10)
}
fn is_default_limit(limit: &UInt) -> bool {
limit == &default_limit()
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct User {
pub user_id: OwnedUserId,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(
feature = "compat",
serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
)]
pub avatar_url: Option<OwnedMxcUri>,
}
impl User {
pub fn new(user_id: OwnedUserId) -> Self {
Self { user_id, display_name: None, avatar_url: None }
}
}
}