Use ruma-api-macros for the context endpoints.
This commit is contained in:
parent
a40ec4e07f
commit
4b728514ca
@ -23,7 +23,7 @@ pub mod r0 {
|
|||||||
pub mod alias;
|
pub mod alias;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod contact;
|
pub mod contact;
|
||||||
// pub mod context;
|
pub mod context;
|
||||||
// pub mod directory;
|
// pub mod directory;
|
||||||
// pub mod filter;
|
// pub mod filter;
|
||||||
// pub mod media;
|
// pub mod media;
|
||||||
|
@ -4,68 +4,47 @@
|
|||||||
pub mod get_context {
|
pub mod get_context {
|
||||||
use ruma_identifiers::{EventId, RoomId};
|
use ruma_identifiers::{EventId, RoomId};
|
||||||
use ruma_events::collections::only;
|
use ruma_events::collections::only;
|
||||||
|
use ruma_api_macros::ruma_api;
|
||||||
|
|
||||||
|
ruma_api! {
|
||||||
/// Details about this API endpoint.
|
metadata {
|
||||||
#[derive(Clone, Copy, Debug)]
|
description: "Get the events immediately preceding and following a given event.",
|
||||||
pub struct Endpoint;
|
method: Method::Get,
|
||||||
|
path: "/_matrix/client/r0/rooms/:room_id/context/:event_id",
|
||||||
/// This API endpoint's path parameters.
|
name: "get_context",
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
rate_limited: false,
|
||||||
pub struct PathParams {
|
requires_authentication: true,
|
||||||
pub event_id: EventId,
|
|
||||||
pub room_id: RoomId,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This API endpoint's query string parameters.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct QueryParams {
|
|
||||||
pub limit: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This API endpoint's response.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Response {
|
|
||||||
pub end: String,
|
|
||||||
pub event: only::RoomEvent,
|
|
||||||
pub events_after: Vec<only::RoomEvent>,
|
|
||||||
pub events_before: Vec<only::RoomEvent>,
|
|
||||||
pub start: String,
|
|
||||||
pub state: Vec<only::StateEvent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
|
||||||
type BodyParams = ();
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = QueryParams;
|
|
||||||
type Response = Response;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Get
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
request {
|
||||||
format!("/_matrix/client/r0/rooms/{}/context/{}", params.room_id, params.event_id)
|
/// The event to get context around.
|
||||||
|
#[ruma_api(path)]
|
||||||
|
pub event_id: EventId,
|
||||||
|
/// The maximum number of events to return.
|
||||||
|
///
|
||||||
|
/// Defaults to 10 if not supplied.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
pub limit: u8,
|
||||||
|
/// The room to get events from.
|
||||||
|
#[ruma_api(path)]
|
||||||
|
pub room_id: RoomId,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {
|
||||||
"/_matrix/client/r0/rooms/:room_id/context/:event_id"
|
/// A token that can be used to paginate forwards with.
|
||||||
}
|
pub end: String,
|
||||||
|
/// Details of the requested event.
|
||||||
fn name() -> &'static str {
|
pub event: only::RoomEvent,
|
||||||
"get_context"
|
/// A list of room events that happened just after the requested event, in chronological
|
||||||
}
|
/// order.
|
||||||
|
pub events_after: Vec<only::RoomEvent>,
|
||||||
fn description() -> &'static str {
|
/// A list of room events that happened just before the requested event, in
|
||||||
"Get the events immediately preceding and following a given event."
|
/// reverse-chronological order.
|
||||||
}
|
pub events_before: Vec<only::RoomEvent>,
|
||||||
|
/// A token that can be used to paginate backwards with.
|
||||||
fn requires_authentication() -> bool {
|
pub start: String,
|
||||||
true
|
/// The state of the room at the last event returned.
|
||||||
}
|
pub state: Vec<only::StateEvent>,
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user