Use ruma-api-macros for the search endpoints.
This commit is contained in:
parent
fc29d7bf40
commit
e71760bb65
@ -35,7 +35,7 @@ pub mod r0 {
|
|||||||
pub mod receipt;
|
pub mod receipt;
|
||||||
pub mod redact;
|
pub mod redact;
|
||||||
pub mod room;
|
pub mod room;
|
||||||
// pub mod search;
|
pub mod search;
|
||||||
pub mod send;
|
pub mod send;
|
||||||
// pub mod server;
|
// pub mod server;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
|
@ -131,7 +131,7 @@ pub mod get_profile {
|
|||||||
request {
|
request {
|
||||||
/// The user whose profile will be retrieved.
|
/// The user whose profile will be retrieved.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub user_id: UserId
|
pub user_id: UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
response {
|
response {
|
||||||
@ -140,7 +140,7 @@ pub mod get_profile {
|
|||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
/// The user's display name, if set.
|
/// The user's display name, if set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub displayname: Option<String>
|
pub displayname: Option<String>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,40 @@
|
|||||||
|
|
||||||
/// [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-search)
|
/// [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-search)
|
||||||
pub mod search_events {
|
pub mod search_events {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_events::collections::all::Event;
|
use ruma_events::collections::all::Event;
|
||||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||||
|
|
||||||
use r0::filter::RoomEventFilter;
|
use r0::filter::RoomEventFilter;
|
||||||
use r0::profile::get_profile::Response as UserProfile;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
ruma_api! {
|
||||||
|
metadata {
|
||||||
|
description: "Search events.",
|
||||||
|
method: Method::Post,
|
||||||
|
name: "search",
|
||||||
|
path: "/_matrix/client/r0/search",
|
||||||
|
rate_limited: true,
|
||||||
|
requires_authentication: true,
|
||||||
|
}
|
||||||
|
|
||||||
/// This API endpoint's body parameters.
|
request {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
/// The point to return events from.
|
||||||
pub struct BodyParams {
|
///
|
||||||
|
/// If given, this should be a `next_batch` result from a previous call to this endpoint.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
pub next_batch: Option<String>,
|
||||||
/// Describes which categories to search in and their criteria.
|
/// Describes which categories to search in and their criteria.
|
||||||
pub search_categories: Categories,
|
pub search_categories: Categories,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response {
|
||||||
|
/// A grouping of search results by category.
|
||||||
|
pub search_categories: ResultCategories,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Categories of events that can be searched for.
|
/// Categories of events that can be searched for.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Categories {
|
pub struct Categories {
|
||||||
@ -53,11 +72,6 @@ pub mod search_events {
|
|||||||
pub search_term: String,
|
pub search_term: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
/// Configures whether any context for the events returned are included in the response.
|
/// Configures whether any context for the events returned are included in the response.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct EventContext {
|
pub struct EventContext {
|
||||||
@ -140,22 +154,6 @@ pub mod search_events {
|
|||||||
Recent,
|
Recent,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's query string parameters.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct QueryParams {
|
|
||||||
/// The point to return events from.
|
|
||||||
///
|
|
||||||
/// If given, this should be a `next_batch` result from a previous call to this endpoint.
|
|
||||||
pub next_batch: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This API endpoint's response.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Response {
|
|
||||||
/// A grouping of search results by category.
|
|
||||||
pub search_categories: ResultCategories,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Categories of events that can be searched for.
|
/// Categories of events that can be searched for.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct ResultCategories {
|
pub struct ResultCategories {
|
||||||
@ -211,38 +209,14 @@ pub mod search_events {
|
|||||||
pub result: Event,
|
pub result: Event,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
/// A user profile.
|
||||||
type BodyParams = BodyParams;
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
type PathParams = ();
|
pub struct UserProfile {
|
||||||
type QueryParams = QueryParams;
|
/// The user's avatar URL, if set.
|
||||||
type Response = Response;
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub avatar_url: Option<String>,
|
||||||
fn method() -> ::Method {
|
/// The user's display name, if set.
|
||||||
::Method::Post
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
}
|
pub displayname: Option<String>,
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
|
||||||
Self::router_path().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/search"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"search"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Search events."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user