From 48dcfe93158088d089c226dcb905c0a20d9cb5b6 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 14 Nov 2019 13:42:22 +0100 Subject: [PATCH] Add user directory endpoints --- src/r0.rs | 1 + src/r0/user_directory.rs | 3 ++ src/r0/user_directory/search_users.rs | 47 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/r0/user_directory.rs create mode 100644 src/r0/user_directory/search_users.rs diff --git a/src/r0.rs b/src/r0.rs index 275100a5..22171154 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -22,4 +22,5 @@ pub mod session; pub mod sync; pub mod tag; pub mod typing; +pub mod user_directory; pub mod voip; diff --git a/src/r0/user_directory.rs b/src/r0/user_directory.rs new file mode 100644 index 00000000..f63505ed --- /dev/null +++ b/src/r0/user_directory.rs @@ -0,0 +1,3 @@ +//! Endpoints for the user directory. + +pub mod search_users; diff --git a/src/r0/user_directory/search_users.rs b/src/r0/user_directory/search_users.rs new file mode 100644 index 00000000..403e3eed --- /dev/null +++ b/src/r0/user_directory/search_users.rs @@ -0,0 +1,47 @@ +//! [POST /_matrix/client/r0/user_directory/search](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-directory-search) + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::UserId; +use serde::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Performs a search for users on the homeserver.", + method: POST, + name: "search_users", + path: "/_matrix/client/r0/user_directory/search", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The term to search for. + pub search_term: String, + /// The maximum number of results to return. + /// + /// Defaults to 10. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + } + + response { + /// Ordered by rank and then whether or not profile info is available. + pub results: Vec, + /// Indicates if the result list has been truncated by the limit. + pub limited: bool, + } +} + +/// User data as result of a search. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct User { + /// The user's matrix user ID. + pub user_id: UserId, + /// The display name of the user, if one exists. + #[serde(skip_serializing_if = "Option::is_none")] + pub display_name: Option, + /// The avatar url, as an MXC, if one exists. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, +}