Merge pull request #20 from jplatte/more-modules

Use ruma-api-macros for more endpoints
This commit is contained in:
Jimmy Cuadra 2017-07-04 12:09:55 -07:00 committed by GitHub
commit ebb05dc076
6 changed files with 311 additions and 652 deletions

View File

@ -35,12 +35,12 @@ pub mod r0 {
// pub mod push;
// pub mod receipt;
// pub mod redact;
// pub mod room;
pub mod room;
// pub mod search;
// pub mod send;
pub mod send;
// pub mod server;
// pub mod session;
// pub mod sync;
pub mod session;
pub mod sync;
// pub mod tag;
// pub mod typing;
// pub mod voip;

View File

@ -24,7 +24,6 @@ pub mod set_room_account_data {
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
#[serde(rename = "type")]
pub event_type: String,
/// The ID of the room to set account_data on.
#[ruma_api(path)]
@ -64,7 +63,6 @@ pub mod set_global_account_data {
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
#[serde(rename = "type")]
pub event_type: String,
/// The ID of the user to set account_data for.
///

View File

@ -3,10 +3,19 @@
/// [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom)
pub mod create_room {
use ruma_identifiers::{RoomId, UserId};
use ruma_api_macros::ruma_api;
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
ruma_api! {
metadata {
description: "Create a new room.",
method: Method::Post,
name: "create_room",
path: "/_matrix/client/r0/createRoom",
rate_limited: false,
requires_authentication: true,
}
request {
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_content: Option<CreationContent>,
#[serde(skip_serializing_if = "Vec::is_empty")]
@ -25,6 +34,11 @@ pub mod create_room {
// TODO: missing `invite_3pid`, `initial_state`
}
response {
pub room_id: RoomId,
}
}
/// Extra options to be added to the `m.room.create` event.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CreationContent {
@ -33,16 +47,6 @@ pub mod create_room {
pub federate: Option<bool>,
}
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub room_id: RoomId,
}
/// A convenience parameter for setting a few default state events.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum RoomPreset {
@ -56,39 +60,4 @@ pub mod create_room {
#[serde(rename="trusted_private_chat")]
TrustedPrivateChat,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = ();
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Post
}
fn request_path(_params: Self::PathParams) -> String {
Self::router_path().to_string()
}
fn router_path() -> &'static str {
"/_matrix/client/r0/createRoom"
}
fn name() -> &'static str {
"create_room"
}
fn description() -> &'static str {
"Create a new room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
}
}

View File

@ -2,193 +2,118 @@
/// [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype)
pub mod send_state_event_for_empty_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
use serde_json::Value;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
ruma_api! {
metadata {
description: "Send a state event to a room associated with the empty state key.",
method: Method::Put,
name: "send_state_event_for_empty_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type",
rate_limited: false,
requires_authentication: true,
}
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
request {
/// The room to set the state in.
#[ruma_api(path)]
pub room_id: RoomId,
pub event_type: EventType
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
/// The event's content.
#[ruma_api(body)]
pub data: Value,
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}",
params.room_id,
params.event_type
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type"
}
fn name() -> &'static str {
"send_state_event_for_empty_key"
}
fn description() -> &'static str {
"Send a state event to a room associated with the empty state key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
}
}
/// [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
pub mod send_state_event_for_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
use serde_json::Value;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
ruma_api! {
metadata {
description: "Send a state event to a room associated with a given state key.",
method: Method::Put,
name: "send_state_event_for_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key",
rate_limited: false,
requires_authentication: true,
}
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
request {
/// The room to set the state in.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
pub state_key: String
/// The state_key for the state to send. Defaults to the empty string.
#[ruma_api(path)]
pub state_key: String,
/// The event's content.
#[ruma_api(body)]
pub data: Value,
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}/{}",
params.room_id,
params.event_type,
params.state_key
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key"
}
fn name() -> &'static str {
"send_state_event_for_key"
}
fn description() -> &'static str {
"Send a state event to a room associated with a given state key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
}
}
/// [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
pub mod send_message_event {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
use ruma_events::room::message::MessageEventContent;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
ruma_api! {
metadata {
description: "Send a message event to a room.",
method: Method::Put,
name: "send_message_event",
path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id",
rate_limited: false,
requires_authentication: true,
}
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
request {
/// The room to send the event to.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
pub txn_id: String
/// The transaction ID for this event.
///
/// Clients should generate an ID unique across requests with the
/// same access token; it will be used by the server to ensure
/// idempotency of requests.
#[ruma_api(path)]
pub txn_id: String,
/// The event's content.
#[ruma_api(body)]
pub data: MessageEventContent,
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/send/{}/{}",
params.room_id,
params.event_type,
params.txn_id
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id"
}
fn name() -> &'static str {
"send_message_event"
}
fn description() -> &'static str {
"Send a message event to a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
}
}

View File

@ -2,27 +2,18 @@
/// [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login)
pub mod login {
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
use ruma_api_macros::ruma_api;
/// Possible login mediums for 3rd party ID
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LoginMedium {
#[serde(rename = "email")]
Email
ruma_api! {
metadata {
description: "Login to the homeserver.",
method: Method::Post,
name: "login",
path: "/_matrix/client/r0/login",
rate_limited: true,
requires_authentication: false,
}
/// Possible kinds of login
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LoginKind {
#[serde(rename = "m.login.password")]
Password
}
/// The body parameters for this endpoint
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
request {
/// Password of the user
pub password: String,
/// Medium of 3rd party login to use
@ -37,91 +28,44 @@ pub mod login {
#[serde(skip_serializing_if = "Option::is_none")]
pub address: Option<String>
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
response {
pub access_token: String,
pub home_server: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<String>,
pub user_id: String,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = ();
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Post
}
fn request_path(_params: Self::PathParams) -> String {
Self::router_path().to_string()
/// Possible login mediums for 3rd party ID
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LoginMedium {
#[serde(rename = "email")]
Email,
}
fn router_path() -> &'static str {
"/_matrix/client/r0/login"
}
fn name() -> &'static str {
"login"
}
fn description() -> &'static str {
"Login to the homeserver."
}
fn requires_authentication() -> bool {
false
}
fn rate_limited() -> bool {
true
}
/// Possible kinds of login
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LoginKind {
#[serde(rename = "m.login.password")]
Password,
}
}
/// [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout)
pub mod logout {
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
use ruma_api_macros::ruma_api;
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = ();
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(_params: Self::PathParams) -> String {
Self::router_path().to_string()
}
fn router_path() -> &'static str {
"/_matrix/client/r0/logout"
}
fn name() -> &'static str {
"logout"
}
fn description() -> &'static str {
"Log out of the homeserver."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
ruma_api! {
metadata {
description: "Log out of the homeserver.",
method: Method::Post,
name: "logout",
path: "/_matrix/client/r0/logout",
rate_limited: false,
requires_authentication: true,
}
request {}
response {}
}
}

View File

@ -2,247 +2,159 @@
/// [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state)
pub mod get_state_events {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
use ruma_events::collections::only;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId
ruma_api! {
metadata {
description: "Get state events for a room.",
method: Method::Get,
name: "get_state_events",
path: "/_matrix/client/r0/rooms/:room_id/state",
rate_limited: false,
requires_authentication: true,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = Vec<only::StateEvent>;
fn method() -> ::Method {
::Method::Get
request {
#[ruma_api(path)]
pub room_id: RoomId,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state",
params.room_id
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state"
}
fn name() -> &'static str {
"get_state_events"
}
fn description() -> &'static str {
"Get state events for a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
pub room_state: Vec<only::StateEvent>,
}
}
}
/// [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype)
pub mod get_state_events_for_empty_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
use ruma_events::EventType;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
ruma_api! {
metadata {
description: "Get state events of a given type associated with the empty key.",
method: Method::Get,
name: "get_state_events_for_empty_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type",
rate_limited: false,
requires_authentication: true,
}
request {
/// The room to query for events
#[ruma_api(path)]
pub room_id: RoomId,
pub event_type: String
/// The type of state to look up
#[ruma_api(path)]
pub event_type: EventType,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ::serde_json::Value;
fn method() -> ::Method {
::Method::Get
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}",
params.room_id,
params.event_type
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type"
}
fn name() -> &'static str {
"get_state_events_for_empty_key"
}
fn description() -> &'static str {
"Get state events of a given type associated with the empty key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
pub content: ::serde_json::Value,
}
}
}
/// [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key)
pub mod get_state_events_for_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
ruma_api! {
metadata {
description: "Get state events associated with a given key.",
method: Method::Get,
name: "get_state_events_for_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key",
rate_limited: false,
requires_authentication: true,
}
request {
/// The room to look up the state in.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of state to look up.
#[ruma_api(path)]
pub event_type: String,
/// The key of the state to look up.
#[ruma_api(path)]
pub state_key: String,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ::serde_json::Value;
fn method() -> ::Method {
::Method::Get
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}/{}",
params.room_id,
params.event_type,
params.state_key
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key"
}
fn name() -> &'static str {
"get_state_events_for_key"
}
fn description() -> &'static str {
"Get state events associated with a given key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
pub content: ::serde_json::Value,
}
}
}
/// [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members)
pub mod get_member_events {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
use ruma_events::room::member::MemberEvent;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId,
}
/// This API endpoint's reponse.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub chunk: Vec<MemberEvent>
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Get
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/members",
params.room_id,
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/members"
}
fn name() -> &'static str {
"get_member_events"
}
fn description() -> &'static str {
"Get membership events for a room."
}
fn requires_authentication() -> bool {
ruma_api! {
metadata {
description: "Get membership events for a room.",
method: Method::Get,
name: "get_member_events",
path: "/_matrix/client/r0/rooms/:room_id/members",
rate_limited: false,
requires_authentication: false,
// TODO: not marked as requiring auth in the spec, but
// will return a 403 error is user is not a member of the
// room anyway...
false
}
fn rate_limited() -> bool {
false
request {
/// The room to look up the state in.
#[ruma_api(path)]
pub room_id: RoomId,
}
response {
pub chunk: Vec<MemberEvent>
}
}
}
/// [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages)
pub mod get_message_events {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
use ruma_events::collections::only;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
ruma_api! {
metadata {
description: "Get message events for a room.",
method: Method::Get,
name: "get_message_events",
path: "/_matrix/client/r0/rooms/:room_id/messages",
rate_limited: false,
requires_authentication: true,
}
request {
// NOTE: The non-macro version of this call included two path params, where the spec only
// has one, room_id. I've followed the spec here. -- rschulman 6/30/2017
/// The room to look up the state in.
#[ruma_api(path)]
pub room_id: RoomId,
pub event_type: String
/// Required. The token to start returning events from. This token can be obtained from a
/// prev_batch token returned for each room by the sync API, or from a start or end token
/// returned by a previous request to this endpoint.
pub from: String,
/// The token to stop returning events at. This token can be obtained from a prev_batch
/// token returned for each room by the sync endpoint, or from a start or end token returned
/// by a previous request to this endpoint.
#[serde(skip_serializing_if = "Option::is_none")]
pub to: Option<String>,
/// Required. The direction to return events from. One of: ["b", "f"]
pub dir: Direction,
/// The maximum number of events to return. Default: 10.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
}
response {
pub start: String,
pub chunk: Vec<only::RoomEvent>,
pub end: String,
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -250,69 +162,13 @@ pub mod get_message_events {
#[serde(rename="b")]
Backward,
#[serde(rename="f")]
Forward
}
/// This API endpoint's query string parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct QueryParams {
pub from: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub to: Option<String>,
pub dir: Direction,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>
}
/// This API endpoint's reponse.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub start: String,
pub chunk: Vec<only::RoomEvent>,
pub end: String
}
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 {
format!(
"/_matrix/client/r0/rooms/{}/messages",
params.room_id,
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/messages"
}
fn name() -> &'static str {
"get_message_events"
}
fn description() -> &'static str {
"Get message events for a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
Forward,
}
}
/// [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync)
pub mod sync_events {
use ruma_api_macros::ruma_api;
use ruma_events::collections::only;
use ruma_identifiers::RoomId;
@ -320,15 +176,40 @@ pub mod sync_events {
use r0::filter::FilterDefinition;
/// Details about this API endpoint.
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
ruma_api! {
metadata {
description: "Get all new events from all rooms since the last sync or a given point of time.",
method: Method::Get,
name: "sync",
path: "/_matrix/client/r0/sync",
rate_limited: false,
requires_authentication: true,
}
request {
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<Filter>,
#[serde(skip_serializing_if = "Option::is_none")]
pub since: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub full_state: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub set_presence: Option<SetPresence>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<u64>,
}
response {
pub next_batch: String,
pub rooms: Rooms,
pub presence: Presence,
}
}
/// Whether to set presence or not during sync.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum SetPresence {
#[serde(rename="offline")]
Offline
Offline,
}
/// A filter represented either as its full JSON definition or the ID of a saved filter.
@ -340,34 +221,19 @@ pub mod sync_events {
FilterId(String),
}
/// This API endpoint's query string parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct QueryParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<Filter>,
#[serde(skip_serializing_if = "Option::is_none")]
pub since: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub full_state: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub set_presence: Option<SetPresence>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<u64>
}
/// Updates to rooms
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Rooms {
pub leave: HashMap<RoomId, LeftRoom>,
pub join: HashMap<RoomId, JoinedRoom>,
pub invite: HashMap<RoomId, InvitedRoom>
pub invite: HashMap<RoomId, InvitedRoom>,
}
/// Historical updates to left rooms
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LeftRoom {
pub timeline: Timeline,
pub state: State
pub state: State,
}
/// Updates to joined rooms
@ -377,14 +243,14 @@ pub mod sync_events {
pub timeline: Timeline,
pub state: State,
pub account_data: AccountData,
pub ephemeral: Ephemeral
pub ephemeral: Ephemeral,
}
/// unread notifications count
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct UnreadNotificationsCount {
pub highlight_count: u64,
pub notification_count: u64
pub notification_count: u64,
}
/// timeline
@ -392,85 +258,42 @@ pub mod sync_events {
pub struct Timeline {
pub limited: bool,
pub prev_batch: String,
pub events: only::RoomEvent
pub events: only::RoomEvent,
}
/// state
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct State {
pub events: only::StateEvent
pub events: only::StateEvent,
}
/// account data
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccountData {
pub events: only::Event
pub events: only::Event,
}
/// ephemeral
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Ephemeral {
pub events: only::Event
pub events: only::Event,
}
/// invited room updates
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct InvitedRoom {
pub invite_state: InviteState
pub invite_state: InviteState,
}
/// invite state
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct InviteState {
pub events: only::StateEvent
pub events: only::StateEvent,
}
/// presence
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Presence {
pub events: only::Event
}
/// This API endpoint's reponse.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub next_batch: String,
pub rooms: Rooms,
pub presence: Presence
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = ();
type QueryParams = QueryParams;
type Response = Response;
fn method() -> ::Method {
::Method::Get
}
fn request_path(_params: Self::PathParams) -> String {
"/_matrix/client/r0/sync".to_string()
}
fn router_path() -> &'static str {
"/_matrix/client/r0/sync"
}
fn name() -> &'static str {
"sync"
}
fn description() -> &'static str {
"Get all new events from all rooms since the last sync or a given point of time."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
pub events: only::Event,
}
}