From 0251019b01f7007e0f1ac085277df28bcd9f3f9a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 29 Sep 2016 06:01:20 -0700 Subject: [PATCH 001/350] ruma-client-api --- .gitignore | 2 ++ .travis.yml | 9 +++++++++ Cargo.toml | 14 ++++++++++++++ LICENSE | 19 +++++++++++++++++++ README.md | 14 ++++++++++++++ src/lib.rs | 0 6 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fa8d85ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..4e2e913d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: "rust" +notifications: + email: false + irc: + channels: + - "chat.freenode.net#ruma" + use_notice: true +rust: + - "nightly" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..e1fae94f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] + +authors = ["Jimmy Cuadra "] +description = "Serializable request and response types for the Matrix client API." +documentation = "https://docs.rs/ruma-client-api" +homepage = "https://github.com/ruma/ruma-client-api" +keywords = ["matrix", "chat", "messaging", "ruma"] +license = "MIT" +name = "ruma-client-api" +readme = "README.md" +repository = "https://github.com/ruma/ruma-client-api" +version = "0.1.0" + +[dependencies] diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..4d376442 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2016 Jimmy Cuadra + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..1b770295 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# ruma-client-api + +[![Build Status](https://travis-ci.org/ruma/ruma-client-api.svg?branch=master)](https://travis-ci.org/ruma/ruma-client-api) + +**ruma-client-api** contains serializable types for the requests and responses for each endpoint in the [Matrix](https://matrix.org/) client API specification. +These types can be shared by client and server code. + +## Status + +This project is currently experimental and is very likely to change drastically. + +## License + +[MIT](http://opensource.org/licenses/MIT) diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..e69de29b From 409b8202f7837340dff55f25fa9db043a7cc1989 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Sep 2016 16:13:59 -0700 Subject: [PATCH 002/350] Define module layout and fill in types for a few APIs. --- Cargo.toml | 4 +++- src/lib.rs | 39 ++++++++++++++++++++++++++++++ src/r0/account.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/r0/alias.rs | 1 + src/r0/config.rs | 1 + src/r0/contact.rs | 1 + src/r0/context.rs | 1 + src/r0/directory.rs | 1 + src/r0/filter.rs | 1 + src/r0/media.rs | 1 + src/r0/membership.rs | 1 + src/r0/presence.rs | 1 + src/r0/profile.rs | 1 + src/r0/push.rs | 1 + src/r0/receipt.rs | 1 + src/r0/redact.rs | 1 + src/r0/room.rs | 48 +++++++++++++++++++++++++++++++++++++ src/r0/search.rs | 1 + src/r0/send.rs | 1 + src/r0/server.rs | 1 + src/r0/session.rs | 21 ++++++++++++++++ src/r0/sync.rs | 1 + src/r0/tag.rs | 1 + src/r0/typing.rs | 1 + src/r0/voip.rs | 1 + src/version.rs | 9 +++++++ 26 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 src/r0/account.rs create mode 100644 src/r0/alias.rs create mode 100644 src/r0/config.rs create mode 100644 src/r0/contact.rs create mode 100644 src/r0/context.rs create mode 100644 src/r0/directory.rs create mode 100644 src/r0/filter.rs create mode 100644 src/r0/media.rs create mode 100644 src/r0/membership.rs create mode 100644 src/r0/presence.rs create mode 100644 src/r0/profile.rs create mode 100644 src/r0/push.rs create mode 100644 src/r0/receipt.rs create mode 100644 src/r0/redact.rs create mode 100644 src/r0/room.rs create mode 100644 src/r0/search.rs create mode 100644 src/r0/send.rs create mode 100644 src/r0/server.rs create mode 100644 src/r0/session.rs create mode 100644 src/r0/sync.rs create mode 100644 src/r0/tag.rs create mode 100644 src/r0/typing.rs create mode 100644 src/r0/voip.rs create mode 100644 src/version.rs diff --git a/Cargo.toml b/Cargo.toml index e1fae94f..9eb9456b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,4 @@ [package] - authors = ["Jimmy Cuadra "] description = "Serializable request and response types for the Matrix client API." documentation = "https://docs.rs/ruma-client-api" @@ -12,3 +11,6 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] +ruma-identifiers = "0.4.1" +serde = "0.8.10" +serde_derive = "0.8.10" diff --git a/src/lib.rs b/src/lib.rs index e69de29b..4dd0cb5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -0,0 +1,39 @@ +//! Crate ruma_client_api contains serializable types for the requests and responses for each +//! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be +//! shared by client and server code. + +#![feature(rustc_macro)] + +extern crate ruma_identifiers; +extern crate serde; +#[macro_use] extern crate serde_derive; + +/// Endpoints for the r0.x.x versions of the client API specification. +pub mod r0 { + pub mod account; + pub mod alias; + pub mod config; + pub mod contact; + pub mod context; + pub mod directory; + pub mod filter; + pub mod media; + pub mod membership; + pub mod presence; + pub mod profile; + pub mod push; + pub mod receipt; + pub mod redact; + pub mod room; + pub mod search; + pub mod send; + pub mod server; + pub mod session; + pub mod sync; + pub mod tag; + pub mod typing; + pub mod voip; +} + +/// GET /_matrix/client/versions +pub mod version; diff --git a/src/r0/account.rs b/src/r0/account.rs new file mode 100644 index 00000000..548a06f7 --- /dev/null +++ b/src/r0/account.rs @@ -0,0 +1,57 @@ +//! Endpoints for account registration and management. + +/// POST /_matrix/client/r0/register +pub mod register { + pub const HTTP_METHOD: &'static str = "POST"; + pub const PATH: &'static str = "/_matrix/client/r0/register"; + + /// The kind of account being registered. + #[derive(Copy, Clone, Debug, Deserialize, Serialize)] + pub enum RegistrationKind { + #[serde(rename="guest")] + Guest, + #[serde(rename="user")] + User, + } + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Request { + pub bind_email: Option, + pub kind: Option, + pub password: String, + pub username: Option, + } + + /// The response type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub access_token: String, + pub home_server: String, + pub user_id: String, + } +} + +/// POST /_matrix/client/r0/account/password/email/requestToken +pub mod request_password_change_token { +} + +/// POST /_matrix/client/r0/account/deactivate +pub mod deactivate { +} + +/// POST /_matrix/client/r0/account/password +pub mod change_password { + pub const HTTP_METHOD: &'static str = "POST"; + pub const PATH: &'static str = "/_matrix/client/r0/account/password"; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Request { + pub new_password: String, + } +} + +/// POST /_matrix/client/r0/register/email/requestToken +pub mod request_register_token { +} diff --git a/src/r0/alias.rs b/src/r0/alias.rs new file mode 100644 index 00000000..207923d9 --- /dev/null +++ b/src/r0/alias.rs @@ -0,0 +1 @@ +//! Endpoints for room aliases. diff --git a/src/r0/config.rs b/src/r0/config.rs new file mode 100644 index 00000000..1f43d2f4 --- /dev/null +++ b/src/r0/config.rs @@ -0,0 +1 @@ +//! Endpoints for client configuration. diff --git a/src/r0/contact.rs b/src/r0/contact.rs new file mode 100644 index 00000000..5894ad82 --- /dev/null +++ b/src/r0/contact.rs @@ -0,0 +1 @@ +//! Endpoints for account contact information. diff --git a/src/r0/context.rs b/src/r0/context.rs new file mode 100644 index 00000000..c82e812f --- /dev/null +++ b/src/r0/context.rs @@ -0,0 +1 @@ +//! Endpoints for event context. diff --git a/src/r0/directory.rs b/src/r0/directory.rs new file mode 100644 index 00000000..89428085 --- /dev/null +++ b/src/r0/directory.rs @@ -0,0 +1 @@ +//! Endpoints for the public room directory. diff --git a/src/r0/filter.rs b/src/r0/filter.rs new file mode 100644 index 00000000..6d52bc5c --- /dev/null +++ b/src/r0/filter.rs @@ -0,0 +1 @@ +//! Endpoints for event filters. diff --git a/src/r0/media.rs b/src/r0/media.rs new file mode 100644 index 00000000..346cd571 --- /dev/null +++ b/src/r0/media.rs @@ -0,0 +1 @@ +//! Endpoints for the media repository. diff --git a/src/r0/membership.rs b/src/r0/membership.rs new file mode 100644 index 00000000..56dbe957 --- /dev/null +++ b/src/r0/membership.rs @@ -0,0 +1 @@ +//! Endpoints for room membership. diff --git a/src/r0/presence.rs b/src/r0/presence.rs new file mode 100644 index 00000000..0e5420ae --- /dev/null +++ b/src/r0/presence.rs @@ -0,0 +1 @@ +//! Endpoints for user presence. diff --git a/src/r0/profile.rs b/src/r0/profile.rs new file mode 100644 index 00000000..29f16d1f --- /dev/null +++ b/src/r0/profile.rs @@ -0,0 +1 @@ +//! Endpoints for user profiles. diff --git a/src/r0/push.rs b/src/r0/push.rs new file mode 100644 index 00000000..31a27f48 --- /dev/null +++ b/src/r0/push.rs @@ -0,0 +1 @@ +//! Endpoints for push notifications. diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs new file mode 100644 index 00000000..f955cfe1 --- /dev/null +++ b/src/r0/receipt.rs @@ -0,0 +1 @@ +//! Endpoints for event receipts. diff --git a/src/r0/redact.rs b/src/r0/redact.rs new file mode 100644 index 00000000..78ec8695 --- /dev/null +++ b/src/r0/redact.rs @@ -0,0 +1 @@ +//! Endpoints for event redaction. diff --git a/src/r0/room.rs b/src/r0/room.rs new file mode 100644 index 00000000..2d92280f --- /dev/null +++ b/src/r0/room.rs @@ -0,0 +1,48 @@ +//! Endpoints for room creation. + +/// POST /_matrix/client/r0/createRoom +pub mod create_room { + use ruma_identifiers::RoomId; + + pub const HTTP_METHOD: &'static str = "POST"; + pub const PATH: &'static str = "/_matrix/client/r0/createRoom"; + + /// Extra options to be added to the `m.room.create` event. + #[derive(Clone, Debug, Deserialize)] + pub struct CreationContent { + #[serde(rename="m.federate")] + pub federate: Option, + } + + /// The request type. + #[derive(Clone, Debug, Deserialize)] + pub struct Request { + pub creation_content: Option, + pub invite: Option>, + pub name: Option, + pub preset: Option, + pub room_alias_name: Option, + pub topic: Option, + pub visibility: Option, + } + + /// The response type. + #[derive(Debug, Serialize)] + pub struct Response { + room_id: RoomId, + } + + /// A convenience parameter for setting a few default state events. + #[derive(Clone, Copy, Debug, Deserialize)] + pub enum RoomPreset { + /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. + #[serde(rename="private_chat")] + PrivateChat, + /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. + #[serde(rename="public_chat")] + PublicChat, + /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. + #[serde(rename="trusted_private_chat")] + TrustedPrivateChat, + } +} diff --git a/src/r0/search.rs b/src/r0/search.rs new file mode 100644 index 00000000..07a22562 --- /dev/null +++ b/src/r0/search.rs @@ -0,0 +1 @@ +//! Endpoints for event searches. diff --git a/src/r0/send.rs b/src/r0/send.rs new file mode 100644 index 00000000..07e48013 --- /dev/null +++ b/src/r0/send.rs @@ -0,0 +1 @@ +//! Endpoints for sending events. diff --git a/src/r0/server.rs b/src/r0/server.rs new file mode 100644 index 00000000..bf4489c4 --- /dev/null +++ b/src/r0/server.rs @@ -0,0 +1 @@ +//! Endpoints for server administration. diff --git a/src/r0/session.rs b/src/r0/session.rs new file mode 100644 index 00000000..f0412b84 --- /dev/null +++ b/src/r0/session.rs @@ -0,0 +1,21 @@ +//! Endpoints for user session management. + +/// POST /_matrix/client/r0/login +pub mod login { + pub const HTTP_METHOD: &'static str = "POST"; + pub const PATH: &'static str = "/_matrix/client/r0/login"; + + /// The response type. + #[derive(Clone, Debug, Deserialize, Serialize)] + struct LoginResponse { + pub access_token: String, + pub home_server: String, + pub user_id: String, + } +} + +/// POST /_matrix/client/r0/logout +pub mod logout { + pub const HTTP_METHOD: &'static str = "POST"; + pub const PATH: &'static str = "/_matrix/client/r0/logout"; +} diff --git a/src/r0/sync.rs b/src/r0/sync.rs new file mode 100644 index 00000000..c77c04ec --- /dev/null +++ b/src/r0/sync.rs @@ -0,0 +1 @@ +//! Endpoints for getting and synchronizing events. diff --git a/src/r0/tag.rs b/src/r0/tag.rs new file mode 100644 index 00000000..f9601833 --- /dev/null +++ b/src/r0/tag.rs @@ -0,0 +1 @@ +//! Endpoints for tagging rooms. diff --git a/src/r0/typing.rs b/src/r0/typing.rs new file mode 100644 index 00000000..f7e677d0 --- /dev/null +++ b/src/r0/typing.rs @@ -0,0 +1 @@ +//! Endpoints for typing notifications. diff --git a/src/r0/voip.rs b/src/r0/voip.rs new file mode 100644 index 00000000..19b900a0 --- /dev/null +++ b/src/r0/voip.rs @@ -0,0 +1 @@ +//! Endpoints for Voice over IP. diff --git a/src/version.rs b/src/version.rs new file mode 100644 index 00000000..e1bbee73 --- /dev/null +++ b/src/version.rs @@ -0,0 +1,9 @@ +pub const HTTP_METHOD: &'static str = "GET"; +pub const PATH: &'static str = "/versions"; + +/// The response type. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, +} From 11285ddc959dad477fecd0fc4c4b9eb45798c942 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Sep 2016 17:22:21 -0700 Subject: [PATCH 003/350] Rename HTTP_METHOD to METHOD, document constants, fill in types for remaining session and account endpoints. --- src/r0/account.rs | 34 ++++++++++++++++++++++++++++++++-- src/r0/room.rs | 5 ++++- src/r0/session.rs | 35 ++++++++++++++++++++++++++++++++--- src/version.rs | 5 ++++- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index 548a06f7..40c39a7d 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,7 +2,10 @@ /// POST /_matrix/client/r0/register pub mod register { - pub const HTTP_METHOD: &'static str = "POST"; + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. pub const PATH: &'static str = "/_matrix/client/r0/register"; /// The kind of account being registered. @@ -34,15 +37,28 @@ pub mod register { /// POST /_matrix/client/r0/account/password/email/requestToken pub mod request_password_change_token { + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. + pub const PATH: &'static str = "/_matrix/client/r0/account/password/email/requestToken"; } /// POST /_matrix/client/r0/account/deactivate pub mod deactivate { + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. + pub const PATH: &'static str = "/_matrix/client/r0/account/deactivate"; } /// POST /_matrix/client/r0/account/password pub mod change_password { - pub const HTTP_METHOD: &'static str = "POST"; + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. pub const PATH: &'static str = "/_matrix/client/r0/account/password"; /// The request type. @@ -54,4 +70,18 @@ pub mod change_password { /// POST /_matrix/client/r0/register/email/requestToken pub mod request_register_token { + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. + pub const PATH: &'static str = "/_matrix/client/r0/register/email/requestToken"; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Request { + pub client_secret: String, + pub email: String, + pub id_server: Option, + pub send_attempt: u64, + } } diff --git a/src/r0/room.rs b/src/r0/room.rs index 2d92280f..16218a2f 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -4,7 +4,10 @@ pub mod create_room { use ruma_identifiers::RoomId; - pub const HTTP_METHOD: &'static str = "POST"; + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. pub const PATH: &'static str = "/_matrix/client/r0/createRoom"; /// Extra options to be added to the `m.room.create` event. diff --git a/src/r0/session.rs b/src/r0/session.rs index f0412b84..dec4375c 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -2,20 +2,49 @@ /// POST /_matrix/client/r0/login pub mod login { - pub const HTTP_METHOD: &'static str = "POST"; + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. pub const PATH: &'static str = "/_matrix/client/r0/login"; /// The response type. #[derive(Clone, Debug, Deserialize, Serialize)] - struct LoginResponse { + pub struct Response { pub access_token: String, pub home_server: String, + pub refresh_token: Option, pub user_id: String, } } /// POST /_matrix/client/r0/logout pub mod logout { - pub const HTTP_METHOD: &'static str = "POST"; + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. pub const PATH: &'static str = "/_matrix/client/r0/logout"; } + +/// POST /_matrix/client/r0/tokenrefresh +pub mod refresh_access_token { + /// The HTTP method. + pub const METHOD: &'static str = "POST"; + + /// The URL's path component. + pub const PATH: &'static str = "/_matrix/client/r0/tokenrefresh"; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Request { + pub refresh_token: String, + } + + /// The response type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub access_token: String, + pub refresh_token: Option, + } +} diff --git a/src/version.rs b/src/version.rs index e1bbee73..899352fe 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1,4 +1,7 @@ -pub const HTTP_METHOD: &'static str = "GET"; +/// The HTTP method. +pub const METHOD: &'static str = "GET"; + +/// The URL's path component. pub const PATH: &'static str = "/versions"; /// The response type. From c310cd13955c5033c4cba790fa3b00d18a336a87 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Oct 2016 00:55:57 -0700 Subject: [PATCH 004/350] Use a trait to represent each endpoint. --- Cargo.toml | 1 + src/lib.rs | 43 +++++++++- src/r0/account.rs | 160 +++++++++++++++++++++++++++++--------- src/r0/alias.rs | 101 ++++++++++++++++++++++++ src/r0/config.rs | 76 ++++++++++++++++++ src/r0/room.rs | 52 ++++++++----- src/r0/session.rs | 86 +++++++++++++++----- src/supported_versions.rs | 28 +++++++ src/version.rs | 12 --- 9 files changed, 471 insertions(+), 88 deletions(-) create mode 100644 src/supported_versions.rs delete mode 100644 src/version.rs diff --git a/Cargo.toml b/Cargo.toml index 9eb9456b..cd61ff9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ version = "0.1.0" ruma-identifiers = "0.4.1" serde = "0.8.10" serde_derive = "0.8.10" +serde_json = "0.8.2" diff --git a/src/lib.rs b/src/lib.rs index 4dd0cb5a..15804276 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,9 @@ extern crate ruma_identifiers; extern crate serde; #[macro_use] extern crate serde_derive; +extern crate serde_json; + +use serde::{Deserialize, Serialize}; /// Endpoints for the r0.x.x versions of the client API specification. pub mod r0 { @@ -36,4 +39,42 @@ pub mod r0 { } /// GET /_matrix/client/versions -pub mod version; +pub mod supported_versions; + +/// HTTP request methods used in Matrix APIs. +#[derive(Clone, Copy, Debug)] +pub enum Method { + /// DELETE + Delete, + /// GET + Get, + /// POST + Post, + /// PUT + Put, +} + +/// An API endpoint. +pub trait Endpoint { + /// Request parameters supplied via the body of the HTTP request. + type BodyParams: Deserialize + Serialize; + + /// Request parameters supplied via the URL's path. + type PathParams; + + /// Parameters supplied via the URL's query string. + type QueryParams; + + /// The body of the response. + type Response: Deserialize + Serialize; + + /// Returns the HTTP method used by this endpoint. + fn method() -> Method; + + /// Generates the path component of the URL for this endpoint using the supplied parameters. + fn request_path(params: Self::PathParams) -> String; + + /// Generates a generic path component of the URL for this endpoint, suitable for `Router` from + /// the router crate. + fn router_path() -> String; +} diff --git a/src/r0/account.rs b/src/r0/account.rs index 40c39a7d..35676ac8 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,11 +2,21 @@ /// POST /_matrix/client/r0/register pub mod register { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub bind_email: Option, + pub password: String, + pub username: Option, + } - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/register"; + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's query string parameters. + pub struct QueryParams { + pub kind: Option, + } /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] @@ -17,71 +27,145 @@ pub mod register { User, } - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Request { - pub bind_email: Option, - pub kind: Option, - pub password: String, - pub username: Option, - } - - /// The response type. + /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub access_token: String, pub home_server: String, pub user_id: String, } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = QueryParams; + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/register".to_string() + } + } } /// POST /_matrix/client/r0/account/password/email/requestToken pub mod request_password_change_token { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; + /// Details about this API endpoint. + pub struct Endpoint; - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/account/password/email/requestToken"; + 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/password/email/requestToken".to_string() + } + } } /// POST /_matrix/client/r0/account/deactivate pub mod deactivate { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; + /// Details about this API endpoint. + pub struct Endpoint; - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/account/deactivate"; + 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/deactivate".to_string() + } + } } /// POST /_matrix/client/r0/account/password pub mod change_password { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; - - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/account/password"; - - /// The request type. + /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Request { + pub struct BodyParams { pub new_password: String, } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/password".to_string() + } + } } /// POST /_matrix/client/r0/register/email/requestToken pub mod request_register_token { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; - - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/register/email/requestToken"; - - /// The request type. + /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Request { + pub struct BodyParams { pub client_secret: String, pub email: String, pub id_server: Option, pub send_attempt: u64, } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/register/email/requestToken".to_string() + } + } } diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 207923d9..c0d2b6e7 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -1 +1,102 @@ //! Endpoints for room aliases. + +use ruma_identifiers::RoomAlias; + +/// PUT /_matrix/client/r0/directory/room/:room_alias +pub mod create { + use ruma_identifiers::RoomId; + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub room_id: RoomId, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = super::PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + } + + fn router_path() -> String { + "/_matrix/client/r0/directory/room/:room_alias".to_string() + } + } +} + +/// DELETE /_matrix/client/r0/directory/room/:room_alias +pub mod delete { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = super::PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Delete + } + + fn request_path(params: Self::PathParams) -> String { + format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + } + + fn router_path() -> String { + "/_matrix/client/r0/directory/room/:room_alias".to_string() + } + } +} + +/// GET /_matrix/client/r0/directory/room/:room_alias +pub mod get { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub room_id: RoomId, + pub servers: Vec, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = super::PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + } + + fn router_path() -> String { + "/_matrix/client/r0/directory/room/:room_alias".to_string() + } + } +} + +/// These API endpoints' path parameters. +pub struct PathParams { + pub room_alias: RoomAlias, +} diff --git a/src/r0/config.rs b/src/r0/config.rs index 1f43d2f4..5ee51f10 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1 +1,77 @@ //! Endpoints for client configuration. + +/// PUT /_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type +pub mod set_room_account_data { + use ruma_identifiers::{RoomId, UserId}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub room_id: RoomId, + pub event_type: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = ::serde_json::Value; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/rooms/{}/account_data/{}", + params.user_id, + params.room_id, + params.event_type + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type".to_string() + } + } +} + +/// PUT /_matrix/client/r0/user/:user_id/account_data/:type +pub mod set_global_account_data { + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub event_type: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = ::serde_json::Value; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/account_data/{}", + params.user_id, + params.event_type + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/account_data/:type".to_string() + } + } +} diff --git a/src/r0/room.rs b/src/r0/room.rs index 16218a2f..e2da0085 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -4,22 +4,9 @@ pub mod create_room { use ruma_identifiers::RoomId; - /// The HTTP method. - pub const METHOD: &'static str = "POST"; - - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/createRoom"; - - /// Extra options to be added to the `m.room.create` event. - #[derive(Clone, Debug, Deserialize)] - pub struct CreationContent { - #[serde(rename="m.federate")] - pub federate: Option, - } - /// The request type. - #[derive(Clone, Debug, Deserialize)] - pub struct Request { + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { pub creation_content: Option, pub invite: Option>, pub name: Option, @@ -29,14 +16,24 @@ pub mod create_room { pub visibility: Option, } + /// Extra options to be added to the `m.room.create` event. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct CreationContent { + #[serde(rename="m.federate")] + pub federate: Option, + } + + /// Details about this API endpoint. + pub struct Endpoint; + /// The response type. - #[derive(Debug, Serialize)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { - room_id: RoomId, + pub room_id: RoomId, } /// A convenience parameter for setting a few default state events. - #[derive(Clone, Copy, Debug, Deserialize)] + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum RoomPreset { /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. #[serde(rename="private_chat")] @@ -48,4 +45,23 @@ 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/createRoom".to_string() + } + } } diff --git a/src/r0/session.rs b/src/r0/session.rs index dec4375c..c639dd81 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -2,13 +2,10 @@ /// POST /_matrix/client/r0/login pub mod login { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; + /// Details about this API endpoint. + pub struct Endpoint; - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/login"; - - /// The response type. + /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub access_token: String, @@ -16,35 +13,86 @@ pub mod login { pub refresh_token: Option, 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/login".to_string() + } + } } /// POST /_matrix/client/r0/logout pub mod logout { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; + /// Details about this API endpoint. + pub struct Endpoint; - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/logout"; + 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/logout".to_string() + } + } } /// POST /_matrix/client/r0/tokenrefresh pub mod refresh_access_token { - /// The HTTP method. - pub const METHOD: &'static str = "POST"; - - /// The URL's path component. - pub const PATH: &'static str = "/_matrix/client/r0/tokenrefresh"; - - /// The request type. + /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Request { + pub struct BodyParams { pub refresh_token: String, } - /// The response type. + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub access_token: String, pub refresh_token: Option, } + + 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() + } + + fn router_path() -> String { + "/_matrix/client/r0/tokenrefresh".to_string() + } + } } diff --git a/src/supported_versions.rs b/src/supported_versions.rs new file mode 100644 index 00000000..12dea1ed --- /dev/null +++ b/src/supported_versions.rs @@ -0,0 +1,28 @@ +/// Details about this API endpoint. +pub struct Endpoint; + +/// This API endpoint's response. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, +} + +impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/versions".to_string() + } +} diff --git a/src/version.rs b/src/version.rs deleted file mode 100644 index 899352fe..00000000 --- a/src/version.rs +++ /dev/null @@ -1,12 +0,0 @@ -/// The HTTP method. -pub const METHOD: &'static str = "GET"; - -/// The URL's path component. -pub const PATH: &'static str = "/versions"; - -/// The response type. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Response { - /// A list of Matrix client API protocol versions supported by the homeserver. - pub versions: Vec, -} From 29cbb4c0c75d9efa60a10d8a9fd758c62f87509e Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Oct 2016 01:04:00 -0700 Subject: [PATCH 005/350] Add missing imports and address warnings. --- src/r0/account.rs | 10 +++++----- src/r0/alias.rs | 6 ++---- src/r0/config.rs | 2 ++ src/r0/room.rs | 2 +- src/r0/session.rs | 6 +++--- src/supported_versions.rs | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index 35676ac8..781f7700 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -45,7 +45,7 @@ pub mod register { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -70,7 +70,7 @@ pub mod request_password_change_token { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -95,7 +95,7 @@ pub mod deactivate { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -126,7 +126,7 @@ pub mod change_password { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -160,7 +160,7 @@ pub mod request_register_token { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } diff --git a/src/r0/alias.rs b/src/r0/alias.rs index c0d2b6e7..8d35193d 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -1,6 +1,6 @@ //! Endpoints for room aliases. -use ruma_identifiers::RoomAlias; +use ruma_identifiers::RoomAliasId; /// PUT /_matrix/client/r0/directory/room/:room_alias pub mod create { @@ -37,8 +37,6 @@ pub mod create { /// DELETE /_matrix/client/r0/directory/room/:room_alias pub mod delete { - use ruma_identifiers::RoomId; - /// Details about this API endpoint. pub struct Endpoint; @@ -98,5 +96,5 @@ pub mod get { /// These API endpoints' path parameters. pub struct PathParams { - pub room_alias: RoomAlias, + pub room_alias: RoomAliasId, } diff --git a/src/r0/config.rs b/src/r0/config.rs index 5ee51f10..9a086f96 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -42,6 +42,8 @@ pub mod set_room_account_data { /// PUT /_matrix/client/r0/user/:user_id/account_data/:type pub mod set_global_account_data { + use ruma_identifiers::UserId; + /// Details about this API endpoint. pub struct Endpoint; diff --git a/src/r0/room.rs b/src/r0/room.rs index e2da0085..cc786de9 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -56,7 +56,7 @@ pub mod create_room { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } diff --git a/src/r0/session.rs b/src/r0/session.rs index c639dd81..e766d7b6 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -24,7 +24,7 @@ pub mod login { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -49,7 +49,7 @@ pub mod logout { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } @@ -87,7 +87,7 @@ pub mod refresh_access_token { ::Method::Post } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } diff --git a/src/supported_versions.rs b/src/supported_versions.rs index 12dea1ed..0e0e8299 100644 --- a/src/supported_versions.rs +++ b/src/supported_versions.rs @@ -18,7 +18,7 @@ impl ::Endpoint for Endpoint { ::Method::Get } - fn request_path(params: Self::PathParams) -> String { + fn request_path(_params: Self::PathParams) -> String { Self::router_path() } From b992542fae62141abd555beb3a61a24a5ca3c05c Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Oct 2016 03:53:43 -0700 Subject: [PATCH 006/350] Add types for account contact information endpoints. --- src/r0/contact.rs | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 5894ad82..2feff62e 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -1 +1,120 @@ //! Endpoints for account contact information. + +/// POST /_matrix/client/r0/account/3pid +pub mod add_contact { + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub bind: Option, + pub three_pid_creds: ThreePidCredentials, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// The third party credentials to associate with the account. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ThreePidCredentials { + client_secret: String, + id_server: String, + sid: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/3pid".to_string() + } + } +} + +/// GET /_matrix/client/r0/account/3pid +pub mod get_contacts { + /// Details about this API endpoint. + pub struct Endpoint; + + /// The medium of third party identifier. + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] + pub enum Medium { + #[serde(rename="email")] + Email, + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub threepids: Vec, + } + + /// An identifier external to Matrix. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ThirdPartyIdentifier { + pub address: String, + pub medium: Medium, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/3pid/email/requestToken".to_string() + } + } +} + +/// POST /_matrix/client/r0/account/3pid/email/requestToken +pub mod request_contact_verification_token { + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub client_secret: String, + pub email: String, + pub id_server: Option, + pub send_attempt: u64, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/account/3pid/email/requestToken".to_string() + } + } +} From 7c714738541a99c4f229fbd719c7df6fc2ffd92d Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Oct 2016 04:04:13 -0700 Subject: [PATCH 007/350] Add missing Clone and Debug impls. --- src/r0/account.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index 781f7700..7a1b9f98 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -14,6 +14,7 @@ pub mod register { pub struct Endpoint; /// This API endpoint's query string parameters. + #[derive(Clone, Debug)] pub struct QueryParams { pub kind: Option, } @@ -57,11 +58,20 @@ pub mod register { /// POST /_matrix/client/r0/account/password/email/requestToken pub mod request_password_change_token { + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub client_secret: String, + pub email: String, + pub id_server: Option, + pub send_attempt: u64, + } + /// Details about this API endpoint. pub struct Endpoint; impl ::Endpoint for Endpoint { - type BodyParams = (); + type BodyParams = BodyParams; type PathParams = (); type QueryParams = (); type Response = (); From 69423c5a32812617a152c9e0acfc812b91d7f867 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 4 Dec 2016 09:14:09 -0800 Subject: [PATCH 008/350] Update dependencies and Macros 1.1 feature name. --- Cargo.toml | 8 ++++---- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd61ff9e..f5769bd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -ruma-identifiers = "0.4.1" -serde = "0.8.10" -serde_derive = "0.8.10" -serde_json = "0.8.2" +ruma-identifiers = "0.4.3" +serde = "0.8.19" +serde_derive = "0.8.19" +serde_json = "0.8.3" diff --git a/src/lib.rs b/src/lib.rs index 15804276..146f2618 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! shared by client and server code. -#![feature(rustc_macro)] +#![feature(proc_macro)] extern crate ruma_identifiers; extern crate serde; From 15b01204cc23f269b8a55fa364863f044e7494c9 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 11 Dec 2016 23:26:07 -0800 Subject: [PATCH 009/350] Encrypt IRC channel name for Travis notifications. See https://github.com/travis-ci/travis-ci/issues/1094 --- .travis.yml | 2 +- Cargo.toml | 3 +++ src/lib.rs | 1 + src/r0/context.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4e2e913d..ec2e0706 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ notifications: email: false irc: channels: - - "chat.freenode.net#ruma" + - secure: "WtuFMaASfrKlPbXWg7cAzxTLSggrix/jqizB3bdGbZTWg8MR0qoa90U9St6h5ELWMc+7mQjJSky0/KXD9BOVLSlok8E12xb8H5soPMW6GjYAek4+JzUeXPYSKNYkP29ZQc26Z9P9TyN/WvJoXIQbaWfMoPmr/g3Rn4z5PyeQgp1+AC54w5zLPtLLjh+WHPYhRoCT7iAsYlx0UazEw3i+aGyN+UdogimDD9ISUKFHOWyXJGyBzFxSpAYaRESnT4I0rJo6ETBkUbEopXvTRyClOsgEk1HRb82+kVNqkampeSDZyb2aCGLbRESd16xVbcE5J2HYu59p5zc00PINMf2nApDEkN/RHERZ4w9lMaxi/fH1TMQZwoNPEd/5n1EU/SLjKi7o/kLdTKEcZyTMd7IZA+TqXjFhKHQlYouOEv742TcWz3jg5+AEhKqjkcpDZTEuNHyMAS4onHg1M9pK2rVh3xmVQ1V2iYM8yY2+73SefJzigkhtXwgnJEv6fJc8IFSPOHtEUBx2KkZps6sRwUxVz5zMgV+4t1h9l4Mt8wOSojoKSxgtAhsHj8pqPysT7vUJPhY6hzzW2nhVHd8IUt49xRNktUr9s+B7yS1Up6+84GTmPmR3lUa+dbZ1PaI2K8VVyctiA4tbkk/n+EFqXL9FY2Gh8XbaWnb7fpWHrJRuZL4=" use_notice: true rust: - "nightly" diff --git a/Cargo.toml b/Cargo.toml index f5769bd3..4d28cda5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,6 @@ ruma-identifiers = "0.4.3" serde = "0.8.19" serde_derive = "0.8.19" serde_json = "0.8.3" + +[dependencies.ruma-events] +git = "https://github.com/ruma/ruma-events" diff --git a/src/lib.rs b/src/lib.rs index 146f2618..8210b64e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![feature(proc_macro)] +extern crate ruma_events; extern crate ruma_identifiers; extern crate serde; #[macro_use] extern crate serde_derive; diff --git a/src/r0/context.rs b/src/r0/context.rs index c82e812f..baaa40a4 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -1 +1,53 @@ //! Endpoints for event context. + +/// GET /_matrix/client/r0/rooms/:room_id/context/:event_id +pub mod get_context { + use ruma_identifiers::{EventId, RoomId}; + use ruma_events::{RoomEvent, StateEvent}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub event_id: EventId, + pub room_id: RoomId, + } + + /// This API endpoint's query string parameters. + #[derive(Clone, Debug)] + pub struct QueryParams { + pub limit: u8, + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub end: String, + pub event: Box, + pub events_after: Vec>, + pub events_before: Vec>, + pub start: String, + pub state: Vec>, + } + + 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/{}/context/{}", params.room_id, params.event_id) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/context/:event_id".to_string() + } + } +} From b9eea6c0300292af1bf2b344693f17d9e5ca9a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Br=C3=B6nnimann?= Date: Wed, 14 Dec 2016 23:14:33 +0100 Subject: [PATCH 010/350] Add join by room id endpoint --- Cargo.toml | 1 + src/lib.rs | 1 + src/r0/membership.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 4d28cda5..d3cb90ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ version = "0.1.0" [dependencies] ruma-identifiers = "0.4.3" +ruma-signatures = "0.1.0" serde = "0.8.19" serde_derive = "0.8.19" serde_json = "0.8.3" diff --git a/src/lib.rs b/src/lib.rs index 8210b64e..68015918 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ extern crate ruma_events; extern crate ruma_identifiers; +extern crate ruma_signatures; extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 56dbe957..e778c6cc 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -1 +1,64 @@ //! Endpoints for room membership. + +/// POST /_matrix/client/r0/rooms/{roomId}/join +pub mod join_by_room_id { + use ruma_identifiers::RoomId; + use ruma_signatures::Signatures; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub third_party_signed: Option, + } + + /// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ThirdPartySigned { + /// The state key of the m.third_party_invite event. + pub token: String, + /// A signatures object containing a signature of the entire signed object. + pub signatures: Signatures, + /// The Matrix ID of the invitee. + pub mxid: String, + /// The Matrix ID of the user who issued the invite. + pub sender: String, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// The response type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub room_id: RoomId, + } + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/join", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/join".to_string() + } + } +} + From 5868783cd3fbd4cbeb17d2f937f3dc9af00cdbfa Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 15 Dec 2016 00:58:49 -0800 Subject: [PATCH 011/350] Use ruma-events collection types to fix the event context API. --- Cargo.toml | 8 +++----- src/r0/context.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d28cda5..5559f239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,8 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -ruma-identifiers = "0.4.3" +ruma-events = "0.1.0" +ruma-identifiers = "0.5.0" serde = "0.8.19" serde_derive = "0.8.19" -serde_json = "0.8.3" - -[dependencies.ruma-events] -git = "https://github.com/ruma/ruma-events" +serde_json = "0.8.4" diff --git a/src/r0/context.rs b/src/r0/context.rs index baaa40a4..02c2c280 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -3,7 +3,8 @@ /// GET /_matrix/client/r0/rooms/:room_id/context/:event_id pub mod get_context { use ruma_identifiers::{EventId, RoomId}; - use ruma_events::{RoomEvent, StateEvent}; + use ruma_events::collections::only; + /// Details about this API endpoint. pub struct Endpoint; @@ -25,11 +26,11 @@ pub mod get_context { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub end: String, - pub event: Box, - pub events_after: Vec>, - pub events_before: Vec>, + pub event: only::RoomEvent, + pub events_after: Vec, + pub events_before: Vec, pub start: String, - pub state: Vec>, + pub state: Vec, } impl ::Endpoint for Endpoint { From eb784ab49b923340904726984c43ca9670d565e4 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 15 Dec 2016 02:00:00 -0800 Subject: [PATCH 012/350] Extract `Method` and `Endpoint` to the ruma-api crate. --- Cargo.toml | 1 + src/lib.rs | 41 ++--------------------------------------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e6c9e6d..e759b606 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] +ruma-api = "0.1.0" ruma-events = "0.1.0" ruma-identifiers = "0.5.0" ruma-signatures = "0.1.0" diff --git a/src/lib.rs b/src/lib.rs index 68015918..4f4710d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![feature(proc_macro)] +extern crate ruma_api; extern crate ruma_events; extern crate ruma_identifiers; extern crate ruma_signatures; @@ -11,7 +12,7 @@ extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; -use serde::{Deserialize, Serialize}; +pub use ruma_api::{Endpoint, Method}; /// Endpoints for the r0.x.x versions of the client API specification. pub mod r0 { @@ -42,41 +43,3 @@ pub mod r0 { /// GET /_matrix/client/versions pub mod supported_versions; - -/// HTTP request methods used in Matrix APIs. -#[derive(Clone, Copy, Debug)] -pub enum Method { - /// DELETE - Delete, - /// GET - Get, - /// POST - Post, - /// PUT - Put, -} - -/// An API endpoint. -pub trait Endpoint { - /// Request parameters supplied via the body of the HTTP request. - type BodyParams: Deserialize + Serialize; - - /// Request parameters supplied via the URL's path. - type PathParams; - - /// Parameters supplied via the URL's query string. - type QueryParams; - - /// The body of the response. - type Response: Deserialize + Serialize; - - /// Returns the HTTP method used by this endpoint. - fn method() -> Method; - - /// Generates the path component of the URL for this endpoint using the supplied parameters. - fn request_path(params: Self::PathParams) -> String; - - /// Generates a generic path component of the URL for this endpoint, suitable for `Router` from - /// the router crate. - fn router_path() -> String; -} From 3b73d910de2f2256ce7b69084e7bc799a4c892c2 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 20 Dec 2016 23:15:13 -0800 Subject: [PATCH 013/350] Bump ruma-events to 0.2.0 and ruma-identifiers to 0.6.0. --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e759b606..48a43f71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ version = "0.1.0" [dependencies] ruma-api = "0.1.0" -ruma-events = "0.1.0" -ruma-identifiers = "0.5.0" +ruma-events = "0.2.0" +ruma-identifiers = "0.6.0" ruma-signatures = "0.1.0" serde = "0.8.19" serde_derive = "0.8.19" From 5b09f689b4263401b611f7eef8f1d601b69e1255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Br=C3=B6nnimann?= Date: Fri, 16 Dec 2016 22:40:31 +0100 Subject: [PATCH 014/350] Add room membership endpoints --- src/r0/membership.rs | 328 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 315 insertions(+), 13 deletions(-) diff --git a/src/r0/membership.rs b/src/r0/membership.rs index e778c6cc..b9e3fca8 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -1,9 +1,66 @@ //! Endpoints for room membership. -/// POST /_matrix/client/r0/rooms/{roomId}/join -pub mod join_by_room_id { +use ruma_signatures::Signatures; + +/// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ThirdPartySigned { + /// The Matrix ID of the invitee. + pub mxid: String, + /// The Matrix ID of the user who issued the invite. + pub sender: String, + /// A signatures object containing a signature of the entire signed object. + pub signatures: Signatures, + /// The state key of the m.third_party_invite event. + pub token: String, +} + +/// POST /_matrix/client/r0/rooms/{roomId}/invite +pub mod invite { use ruma_identifiers::RoomId; - use ruma_signatures::Signatures; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub user_id: String, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/invite", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/invite".to_string() + } + } +} + +/// POST /_matrix/client/r0/join/{roomIdOrAlias} +pub mod join_by_room_id_or_alias { + use ruma_identifiers::{RoomId, RoomIdOrAliasId}; + use super::ThirdPartySigned; /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -11,17 +68,63 @@ pub mod join_by_room_id { pub third_party_signed: Option, } - /// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. + /// Details about this API endpoint. + pub struct Endpoint; + + /// The response type. #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ThirdPartySigned { - /// The state key of the m.third_party_invite event. - pub token: String, - /// A signatures object containing a signature of the entire signed object. - pub signatures: Signatures, - /// The Matrix ID of the invitee. - pub mxid: String, - /// The Matrix ID of the user who issued the invite. - pub sender: String, + pub struct Response { + pub room_id: RoomId, + } + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id_or_alias: RoomIdOrAliasId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + match params.room_id_or_alias { + RoomIdOrAliasId::RoomId(room_id) => { + format!( + "/_matrix/client/r0/join/{}", + room_id + ) + } + RoomIdOrAliasId::RoomAliasId(room_alias_id) => { + format!( + "/_matrix/client/r0/join/{}", + room_alias_id + ) + } + } + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id_or_alias/join".to_string() + } + } +} + +/// POST /_matrix/client/r0/rooms/{roomId}/join +pub mod join_by_room_id { + use ruma_identifiers::RoomId; + use super::ThirdPartySigned; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub third_party_signed: Option, } /// Details about this API endpoint. @@ -62,3 +165,202 @@ pub mod join_by_room_id { } } +/// POST /_matrix/client/r0/rooms/{roomId}/forget +pub mod forget { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/forget", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/forget".to_string() + } + } +} + +/// POST /_matrix/client/r0/rooms/{roomId}/leave +pub mod leave { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/leave", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/leave".to_string() + } + } +} + +/// POST /_matrix/client/r0/rooms/{roomId}/kick +pub mod kick { + use ruma_identifiers::RoomId; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub user_id: String, + pub reason: Option, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/kick", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/kick".to_string() + } + } +} + +/// POST /_matrix/client/r0/rooms/{roomId}/unban +pub mod unban { + use ruma_identifiers::RoomId; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub user_id: String, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/unban", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/unban".to_string() + } + } +} + +/// POST /_matrix/client/r0/rooms/{roomId}/ban +pub mod ban { + use ruma_identifiers::RoomId; + + /// The request type. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub reason: Option, + pub user_id: String, + } + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/ban", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/ban".to_string() + } + } +} From a0c0890940d5695a8083528e29fb0123feb55b5a Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 12:12:16 +0100 Subject: [PATCH 015/350] Add link to the matrix spec for each endpoint. --- src/lib.rs | 2 ++ src/r0/account.rs | 10 ++++++++++ src/r0/alias.rs | 6 ++++++ src/r0/config.rs | 4 ++++ src/r0/contact.rs | 6 ++++++ src/r0/context.rs | 2 ++ src/r0/membership.rs | 16 ++++++++++++++++ src/r0/room.rs | 2 ++ src/r0/session.rs | 6 ++++++ 9 files changed, 54 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4f4710d7..afa7710c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,4 +42,6 @@ pub mod r0 { } /// GET /_matrix/client/versions +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) pub mod supported_versions; diff --git a/src/r0/account.rs b/src/r0/account.rs index 7a1b9f98..a6e3d7bb 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -1,6 +1,8 @@ //! Endpoints for account registration and management. /// POST /_matrix/client/r0/register +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) pub mod register { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -57,6 +59,8 @@ pub mod register { } /// POST /_matrix/client/r0/account/password/email/requestToken +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -91,6 +95,8 @@ pub mod request_password_change_token { } /// POST /_matrix/client/r0/account/deactivate +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) pub mod deactivate { /// Details about this API endpoint. pub struct Endpoint; @@ -116,6 +122,8 @@ pub mod deactivate { } /// POST /_matrix/client/r0/account/password +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) pub mod change_password { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -147,6 +155,8 @@ pub mod change_password { } /// POST /_matrix/client/r0/register/email/requestToken +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) pub mod request_register_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 8d35193d..12094c1f 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -3,6 +3,8 @@ use ruma_identifiers::RoomAliasId; /// PUT /_matrix/client/r0/directory/room/:room_alias +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) pub mod create { use ruma_identifiers::RoomId; @@ -36,6 +38,8 @@ pub mod create { } /// DELETE /_matrix/client/r0/directory/room/:room_alias +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) pub mod delete { /// Details about this API endpoint. pub struct Endpoint; @@ -61,6 +65,8 @@ pub mod delete { } /// GET /_matrix/client/r0/directory/room/:room_alias +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) pub mod get { use ruma_identifiers::RoomId; diff --git a/src/r0/config.rs b/src/r0/config.rs index 9a086f96..c6014f4f 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1,6 +1,8 @@ //! Endpoints for client configuration. /// PUT /_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) pub mod set_room_account_data { use ruma_identifiers::{RoomId, UserId}; @@ -41,6 +43,8 @@ pub mod set_room_account_data { } /// PUT /_matrix/client/r0/user/:user_id/account_data/:type +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) pub mod set_global_account_data { use ruma_identifiers::UserId; diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 2feff62e..775a2edb 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -1,6 +1,8 @@ //! Endpoints for account contact information. /// POST /_matrix/client/r0/account/3pid +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) pub mod add_contact { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -41,6 +43,8 @@ pub mod add_contact { } /// GET /_matrix/client/r0/account/3pid +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) pub mod get_contacts { /// Details about this API endpoint. pub struct Endpoint; @@ -86,6 +90,8 @@ pub mod get_contacts { } /// POST /_matrix/client/r0/account/3pid/email/requestToken +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/context.rs b/src/r0/context.rs index 02c2c280..57be070b 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -1,6 +1,8 @@ //! Endpoints for event context. /// GET /_matrix/client/r0/rooms/:room_id/context/:event_id +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) pub mod get_context { use ruma_identifiers::{EventId, RoomId}; use ruma_events::collections::only; diff --git a/src/r0/membership.rs b/src/r0/membership.rs index b9e3fca8..1ce0c841 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -16,6 +16,8 @@ pub struct ThirdPartySigned { } /// POST /_matrix/client/r0/rooms/{roomId}/invite +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) pub mod invite { use ruma_identifiers::RoomId; @@ -58,6 +60,8 @@ pub mod invite { } /// POST /_matrix/client/r0/join/{roomIdOrAlias} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) pub mod join_by_room_id_or_alias { use ruma_identifiers::{RoomId, RoomIdOrAliasId}; use super::ThirdPartySigned; @@ -117,6 +121,8 @@ pub mod join_by_room_id_or_alias { } /// POST /_matrix/client/r0/rooms/{roomId}/join +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) pub mod join_by_room_id { use ruma_identifiers::RoomId; use super::ThirdPartySigned; @@ -166,6 +172,8 @@ pub mod join_by_room_id { } /// POST /_matrix/client/r0/rooms/{roomId}/forget +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) pub mod forget { use ruma_identifiers::RoomId; @@ -202,6 +210,8 @@ pub mod forget { } /// POST /_matrix/client/r0/rooms/{roomId}/leave +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) pub mod leave { use ruma_identifiers::RoomId; @@ -238,6 +248,8 @@ pub mod leave { } /// POST /_matrix/client/r0/rooms/{roomId}/kick +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) pub mod kick { use ruma_identifiers::RoomId; @@ -281,6 +293,8 @@ pub mod kick { } /// POST /_matrix/client/r0/rooms/{roomId}/unban +/// +/// [matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) pub mod unban { use ruma_identifiers::RoomId; @@ -323,6 +337,8 @@ pub mod unban { } /// POST /_matrix/client/r0/rooms/{roomId}/ban +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) pub mod ban { use ruma_identifiers::RoomId; diff --git a/src/r0/room.rs b/src/r0/room.rs index cc786de9..56a8b4dd 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,6 +1,8 @@ //! Endpoints for room creation. /// POST /_matrix/client/r0/createRoom +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom) pub mod create_room { use ruma_identifiers::RoomId; diff --git a/src/r0/session.rs b/src/r0/session.rs index e766d7b6..e144123e 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -1,6 +1,8 @@ //! Endpoints for user session management. /// POST /_matrix/client/r0/login +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) pub mod login { /// Details about this API endpoint. pub struct Endpoint; @@ -35,6 +37,8 @@ pub mod login { } /// POST /_matrix/client/r0/logout +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout) pub mod logout { /// Details about this API endpoint. pub struct Endpoint; @@ -60,6 +64,8 @@ pub mod logout { } /// POST /_matrix/client/r0/tokenrefresh +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-tokenrefresh) pub mod refresh_access_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] From 3666cb8294df7cb4c35beae1e552bc7e2d8c9f36 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 14:00:25 +0100 Subject: [PATCH 016/350] Add typing endpoint. --- src/r0/typing.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/r0/typing.rs b/src/r0/typing.rs index f7e677d0..b4d6a19d 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -1 +1,48 @@ //! Endpoints for typing notifications. + +/// PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) +pub mod set_typing { + use ruma_identifiers::{UserId, RoomId}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub typing: bool, + pub timeout: Option + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/typing/{}", + params.room_id, + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/invite/:user_id".to_string() + } + } +} From f880b15f429646abb170e03c3be2737b895d45c5 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 14:36:07 +0100 Subject: [PATCH 017/350] Add presence endpoints. --- src/r0/presence.rs | 178 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 0e5420ae..e7bfc95d 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -1 +1,179 @@ //! Endpoints for user presence. + +/// PUT /_matrix/client/r0/presence/{userId}/status +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) +pub mod set_presence { + use ruma_identifiers::UserId; + use ruma_events::presence::PresenceState; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + status_msg: Option, + presence: PresenceState + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/presence/{}/status", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/presence/:user_id/status".to_string() + } + } +} + +/// GET /_matrix/client/r0/presence/{userId}/status +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) +pub mod get_presence { + use ruma_identifiers::UserId; + use ruma_events::presence::PresenceState; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub status_msg: Option, + pub currently_active: Option, + pub last_active_ago: Option, + pub presence: PresenceState + } + + 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/presence/{}/status", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/presence/:user_id/status".to_string() + } + } +} + +/// POST /_matrix/client/r0/presence/list/{userId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) +pub mod update_presence_list { + use ruma_identifiers::UserId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + drop: Option>, + invite: Option> + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/presence/list/{}", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/presence/list/:user_id".to_string() + } + } +} + +/// GET /_matrix/client/r0/presence/list/{userId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) +pub mod get_presence_list_status { + use ruma_identifiers::UserId; + use ruma_events::presence::PresenceEvent; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Vec; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/presence/list/{}", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/presence/list/:user_id".to_string() + } + } +} From 3cd398a9aed7703eb6d58050c3fc73f52e1631c4 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 14:52:28 +0100 Subject: [PATCH 018/350] Add tagging endpoints. --- src/r0/tag.rs | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/src/r0/tag.rs b/src/r0/tag.rs index f9601833..f84d0169 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -1 +1,133 @@ //! Endpoints for tagging rooms. + +/// PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +pub mod add_tag { + use ruma_identifiers::{UserId, RoomId}; + use ruma_events::tag::TagInfo; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub room_id: RoomId, + pub tag: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = TagInfo; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", + params.user_id, + params.room_id, + params.tag + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag".to_string() + } + } +} + +/// GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) +pub mod get_tags { + use ruma_identifiers::{UserId, RoomId}; + use ruma_events::tag::TagEventContent; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub room_id: RoomId + } + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub tags: TagEventContent, + } + + 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/user/{}/rooms/{}/tags", + params.user_id, + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags".to_string() + } + } +} + +/// DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +pub mod del_tag { + use ruma_identifiers::{UserId, RoomId}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub room_id: RoomId, + pub tag: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Delete + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", + params.user_id, + params.room_id, + params.tag + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag".to_string() + } + } +} From 81469d8d04cd5ce0fff97cdcdf746dd31b542453 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 15:36:43 +0100 Subject: [PATCH 019/350] Add sync endpoint. --- src/r0/sync.rs | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index c77c04ec..b891e22d 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -1 +1,133 @@ //! Endpoints for getting and synchronizing events. + +/// GET /_matrix/client/r0/sync +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) +pub mod sync { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + use std::collections::HashMap; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// Wether to set presence or not during sync + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum SetPresence { + #[serde(rename="offline")] + Offline + } + + /// This API endpoint's query parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct QueryParams { + pub filter: Option, + pub since: Option, + pub full_state: Option, + pub set_presence: Option, + pub timeout: Option + } + + /// Updates to rooms + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Rooms { + pub leave: HashMap, + pub join: HashMap, + pub invite: HashMap + } + + /// Historical updates to left rooms + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct LeftRoom { + pub timeline: Timeline, + pub state: State + } + + /// Updates to joined rooms + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct JoinedRoom { + pub unread_notifications: UnreadNotificationsCount, + pub timeline: Timeline, + pub state: State, + pub account_data: AccountData, + pub ephemeral: Ephemeral + } + + /// unread notifications count + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct UnreadNotificationsCount { + pub highlight_count: u64, + pub notification_count: u64 + } + + /// timeline + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Timeline { + pub limited: bool, + pub prev_batch: String, + pub events: only::RoomEvent + } + + /// state + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct State { + pub events: only::StateEvent + } + + /// account data + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct AccountData { + pub events: only::Event + } + + /// ephemeral + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Ephemeral { + pub events: only::Event + } + + /// invited room updates + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct InvitedRoom { + pub invite_state: InviteState + } + + /// invite state + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct InviteState { + 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() -> String { + "/_matrix/client/r0/sync".to_string() + } + } +} From 607a9d63b1f695188ba057a35aa610e20899fd36 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 15:57:30 +0100 Subject: [PATCH 020/350] Add sending endpoints. --- src/r0/send.rs | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/src/r0/send.rs b/src/r0/send.rs index 07e48013..d9399b41 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -1 +1,149 @@ //! Endpoints for sending events. + +/// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) +pub mod send_state { + use ruma_identifiers::{RoomId, EventId}; + use ruma_events::EventType; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: EventType + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub event_id: EventId, + } + + + impl ::Endpoint for Endpoint { + type BodyParams = ::serde_json::Value; + type PathParams = PathParams; + type QueryParams = (); + type 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() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + } + } +} + +/// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) +pub mod send_state_key { + use ruma_identifiers::{RoomId, EventId}; + use ruma_events::EventType; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: EventType, + pub state_key: String + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub event_id: EventId, + } + + + impl ::Endpoint for Endpoint { + type BodyParams = ::serde_json::Value; + type PathParams = PathParams; + type QueryParams = (); + type 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() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + } + } +} + +/// PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) +pub mod send_event { + use ruma_identifiers::{RoomId, EventId}; + use ruma_events::EventType; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: EventType, + pub txn_id: String + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub event_id: EventId, + } + + + impl ::Endpoint for Endpoint { + type BodyParams = ::serde_json::Value; + type PathParams = PathParams; + type QueryParams = (); + type 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() -> String { + "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id".to_string() + } + } +} From 00a7ea7294fa40d25da1c43c4dd8545a568674b6 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 16:04:16 +0100 Subject: [PATCH 021/350] Add redact endpoint. --- src/r0/redact.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 78ec8695..9dd2aadd 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -1 +1,56 @@ //! Endpoints for event redaction. + +/// PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) +pub mod send_event { + use ruma_identifiers::{RoomId, EventId}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_id: EventId, + pub txn_id: String + } + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub reason: Option + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub event_id: EventId, + } + + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/redact/{}/{}", + params.room_id, + params.event_id, + params.txn_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id".to_string() + } + } +} From 5b23117973891d068b5f7ca29e736c61c85a91cd Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 23 Dec 2016 16:08:34 +0100 Subject: [PATCH 022/350] Add turnserver endpoint. --- src/r0/voip.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 19b900a0..93ff49db 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -1 +1,37 @@ //! Endpoints for Voice over IP. + +/// GET /_matrix/client/r0/voip/turnServer +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) +pub mod turnserver { + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub username: String, + pub password: String, + pub uris: Vec, + pub ttl: u64 + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(_params: Self::PathParams) -> String { + "/_matrix/client/r0/voip/turnServer".to_string() + } + + fn router_path() -> String { + "_matrix/client/r0/voip/turnServer".to_string() + } + } +} From 72b12557ec081a30ee6da54af3da743d3dd5be3e Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 24 Dec 2016 09:10:56 +0100 Subject: [PATCH 023/350] Add missing Response types. --- src/r0/redact.rs | 2 +- src/r0/send.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 9dd2aadd..08e6fc94 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -34,7 +34,7 @@ pub mod send_event { type BodyParams = BodyParams; type PathParams = PathParams; type QueryParams = (); - type Response = (); + type Response = Response; fn method() -> ::Method { ::Method::Put diff --git a/src/r0/send.rs b/src/r0/send.rs index d9399b41..7ed322db 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -28,7 +28,7 @@ pub mod send_state { type BodyParams = ::serde_json::Value; type PathParams = PathParams; type QueryParams = (); - type Response = (); + type Response = Response; fn method() -> ::Method { ::Method::Put @@ -77,7 +77,7 @@ pub mod send_state_key { type BodyParams = ::serde_json::Value; type PathParams = PathParams; type QueryParams = (); - type Response = (); + type Response = Response; fn method() -> ::Method { ::Method::Put @@ -127,7 +127,7 @@ pub mod send_event { type BodyParams = ::serde_json::Value; type PathParams = PathParams; type QueryParams = (); - type Response = (); + type Response = Response; fn method() -> ::Method { ::Method::Put From 419031a7671567004de147f3060e4e7a110eebb2 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 16:16:42 +0100 Subject: [PATCH 024/350] publicRooms endpoint --- src/r0/directory.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 89428085..361cf0da 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1 +1,51 @@ //! Endpoints for the public room directory. + +/// GET /_matrix/client/r0/publicRooms +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) +pub mod public_rooms { + use ruma_identifiers::{RoomId, RoomAliasId}; + + /// A chunk of the response, describing one room + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PublicRoomsChunk { + pub world_readable: bool, + pub topic: Option, + pub num_joined_members: u64, + pub avatar_url: Option, + pub room_id: RoomId, + pub guest_can_join: bool, + pub aliases: Vec, + pub name: Option + } + + /// This API response type + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub start: String, + pub chunk: Vec, + pub end: String + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/publicRooms".to_string() + } + } +} From 4e7d85aa04537a7065c8e8e8b82ef97ba7fd8a03 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 16:34:17 +0100 Subject: [PATCH 025/350] profile endpoints --- src/r0/profile.rs | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 29f16d1f..b5669454 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -1 +1,223 @@ //! Endpoints for user profiles. + +/// GET /_matrix/client/r0/profile/{userId}/displayname +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) +pub mod get_display_name { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + 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/profile/{}/displayname", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/displayname".to_string() + } + } +} + + +/// PUT /_matrix/client/r0/profile/{userId}/displayname +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) +pub mod set_display_name { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/displayname", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/displayname".to_string() + } + } +} + +/// GET /_matrix/client/r0/profile/{userId}/avatar_url +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) +pub mod get_avatar_url { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub avatar_url: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + 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/profile/{}/avatar_url", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + } + } +} + +/// PUT /_matrix/client/r0/profile/{userId}/avatar_url +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) +pub mod set_avatar_url { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub avatar_url: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/avatar_url", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + } + } +} + +/// GET /_matrix/client/r0/profile/{userId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) +pub mod get_profile { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub avatar_url: Option, + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + 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/profile/{}", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id".to_string() + } + } +} From db7f614ad7a150664ce639c862ddb77916380baa Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:08:22 +0100 Subject: [PATCH 026/350] filter endpoints --- src/r0/filter.rs | 143 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 6d52bc5c..1203a0b5 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -1 +1,144 @@ //! Endpoints for event filters. + +use ruma_identifiers::{RoomId, UserId}; + +/// Format to use for returned events +#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +pub enum EventFormat { + /// Client format, as described in the Client API + #[serde(rename="client")] + Client, + /// Raw events from federation + #[serde(rename="federation")] + Federation +} + +/// Filters to be applied to room events +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomEventFilter { + pub not_types: Option>, + pub not_rooms: Option>, + pub limit: Option, + pub rooms: Option>, + pub not_senders: Option>, + pub senders: Option>, + pub types: Option> +} + +/// Filters to be applied to room data +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomFilter { + pub include_leave: Option, + pub account_data: Option, + pub timeline: Option, + pub ephemeral: Option, + pub state: Option, + pub not_rooms: Option>, + pub room: Option> +} + +/// Filter for not-room data +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Filter { + pub not_types: Option>, + pub limit: Option, + pub senders: Option>, + pub types: Option>, + pub not_senders: Option> +} + +/// A filter definition +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct FilterDefinition { + pub event_fields: Option>, + pub event_format: Option, + pub account_data: Option, + pub room: Option, + pub presence: Option +} + +/// POST /_matrix/client/r0/user/{userId}/filter +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) +pub mod create_filter { + use ruma_identifiers::UserId; + use super::FilterDefinition; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API Response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub filter_id: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = FilterDefinition; + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/filter", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/filter".to_string() + } + } +} + +/// POST /_matrix/client/r0/user/{userId}/filter/{filterId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) +pub mod get_filter { + use ruma_identifiers::UserId; + use super::FilterDefinition; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub filter_id: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = FilterDefinition; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/filter/{}", + params.user_id, + params.filter_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/filter/:filter_id".to_string() + } + } +} From 6e3406ea97e8863481d8dc281edb57df0fd3cfc6 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:29:54 +0100 Subject: [PATCH 027/350] events retrieveing endpoints --- src/lib.rs | 1 + src/r0/events.rs | 233 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 src/r0/events.rs diff --git a/src/lib.rs b/src/lib.rs index afa7710c..177e67a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ pub mod r0 { pub mod contact; pub mod context; pub mod directory; + pub mod events; pub mod filter; pub mod media; pub mod membership; diff --git a/src/r0/events.rs b/src/r0/events.rs new file mode 100644 index 00000000..955657b3 --- /dev/null +++ b/src/r0/events.rs @@ -0,0 +1,233 @@ +//! Endpoints for getting events + +/// GET /_matrix/client/r0/rooms/{roomId}/state +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state) +pub mod get_full_state { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Vec; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/state", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) +pub mod get_state_for_empty_key { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: 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 + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) +pub mod get_state_for_key { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String, + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/members +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members) +pub mod get_members { + use ruma_identifiers::RoomId; + use ruma_events::room::member::MemberEvent; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + /// This API endpoint's reponse. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub chunks: Vec + } + + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/members".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/messages +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages) +pub mod get_messages { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum Direction { + #[serde(rename="b")] + Backward, + #[serde(rename="f")] + Forward + } + + /// This API endpoint's query parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct QueryParams { + pub from: String, + pub to: Option, + pub dir: Direction, + pub limit: Option + } + + /// This API endpoint's reponse. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub start: String, + pub chunks: Vec, + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/messages".to_string() + } + } +} From 6da028c0fe0dedc9273aff215f2bee50c7fce0f7 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:36:25 +0100 Subject: [PATCH 028/350] fix doc error in get_filter --- src/r0/filter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 1203a0b5..ad1db6f1 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -102,7 +102,7 @@ pub mod create_filter { } } -/// POST /_matrix/client/r0/user/{userId}/filter/{filterId} +/// GET /_matrix/client/r0/user/{userId}/filter/{filterId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) pub mod get_filter { From 3c324d526c8cd6f4b019faa8dc7db401bcb41ffd Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 19:38:50 +0100 Subject: [PATCH 029/350] Add serde attributes to Option and Vec, and missing #[derive]s --- src/r0/account.rs | 7 ++++- src/r0/alias.rs | 1 + src/r0/contact.rs | 2 ++ src/r0/context.rs | 2 +- src/r0/directory.rs | 3 +++ src/r0/events.rs | 2 ++ src/r0/filter.rs | 63 +++++++++++++++++++++++++++++++++++--------- src/r0/membership.rs | 4 +++ src/r0/presence.rs | 12 +++++++-- src/r0/profile.rs | 6 +++++ src/r0/redact.rs | 1 + src/r0/room.rs | 11 +++++++- src/r0/session.rs | 2 ++ src/r0/sync.rs | 5 ++++ src/r0/typing.rs | 1 + 15 files changed, 104 insertions(+), 18 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index a6e3d7bb..bad73ebe 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -7,8 +7,10 @@ pub mod register { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub bind_email: Option, pub password: String, + #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, } @@ -16,8 +18,9 @@ pub mod register { pub struct Endpoint; /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { + #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, } @@ -67,6 +70,7 @@ pub mod request_password_change_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } @@ -163,6 +167,7 @@ pub mod request_register_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 12094c1f..21bc19a2 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -101,6 +101,7 @@ pub mod get { } /// These API endpoints' path parameters. +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct PathParams { pub room_alias: RoomAliasId, } diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 775a2edb..cd0d6631 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -7,6 +7,7 @@ pub mod add_contact { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub bind: Option, pub three_pid_creds: ThreePidCredentials, } @@ -98,6 +99,7 @@ pub mod request_contact_verification_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } diff --git a/src/r0/context.rs b/src/r0/context.rs index 57be070b..9bdf1da2 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -19,7 +19,7 @@ pub mod get_context { } /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { pub limit: u8, } diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 361cf0da..a8c3b51c 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -10,12 +10,15 @@ pub mod public_rooms { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { pub world_readable: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, pub num_joined_members: u64, + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, pub room_id: RoomId, pub guest_can_join: bool, pub aliases: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option } diff --git a/src/r0/events.rs b/src/r0/events.rs index 955657b3..f57a2eb5 100644 --- a/src/r0/events.rs +++ b/src/r0/events.rs @@ -196,8 +196,10 @@ pub mod get_messages { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { pub from: String, + #[serde(skip_serializing_if = "Option::is_none")] pub to: Option, pub dir: Direction, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option } diff --git a/src/r0/filter.rs b/src/r0/filter.rs index ad1db6f1..6c9f883b 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -16,44 +16,81 @@ pub enum EventFormat { /// Filters to be applied to room events #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomEventFilter { - pub not_types: Option>, - pub not_rooms: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_types: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_rooms: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, - pub rooms: Option>, - pub not_senders: Option>, - pub senders: Option>, - pub types: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub rooms: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub types: Vec } /// Filters to be applied to room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomFilter { + #[serde(skip_serializing_if = "Option::is_none")] pub include_leave: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub timeline: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub ephemeral: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - pub not_rooms: Option>, - pub room: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_rooms: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub room: Vec } /// Filter for not-room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Filter { - pub not_types: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_types: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, - pub senders: Option>, - pub types: Option>, - pub not_senders: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub types: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_senders: Vec } /// A filter definition #[derive(Clone, Debug, Deserialize, Serialize)] pub struct FilterDefinition { - pub event_fields: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub event_fields: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub event_format: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub room: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presence: Option } diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 1ce0c841..5a33ec35 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -69,6 +69,7 @@ pub mod join_by_room_id_or_alias { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub third_party_signed: Option, } @@ -130,6 +131,7 @@ pub mod join_by_room_id { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub third_party_signed: Option, } @@ -257,6 +259,7 @@ pub mod kick { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub user_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, } @@ -345,6 +348,7 @@ pub mod ban { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, pub user_id: String, } diff --git a/src/r0/presence.rs b/src/r0/presence.rs index e7bfc95d..7fc8aab0 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -19,6 +19,7 @@ pub mod set_presence { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] status_msg: Option, presence: PresenceState } @@ -65,8 +66,11 @@ pub mod get_presence { /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub status_msg: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub currently_active: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub last_active_ago: Option, pub presence: PresenceState } @@ -112,8 +116,12 @@ pub mod update_presence_list { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { - drop: Option>, - invite: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + drop: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + invite: Vec } impl ::Endpoint for Endpoint { diff --git a/src/r0/profile.rs b/src/r0/profile.rs index b5669454..30b8370b 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -15,6 +15,7 @@ pub mod get_display_name { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } @@ -60,6 +61,7 @@ pub mod set_display_name { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } @@ -104,6 +106,7 @@ pub mod get_avatar_url { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option } @@ -148,6 +151,7 @@ pub mod set_avatar_url { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option } @@ -192,7 +196,9 @@ pub mod get_profile { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 08e6fc94..93b19db1 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -20,6 +20,7 @@ pub mod send_event { /// This API endpoint's path parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option } diff --git a/src/r0/room.rs b/src/r0/room.rs index 56a8b4dd..7a15f961 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -9,12 +9,20 @@ pub mod create_room { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub creation_content: Option, - pub invite: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub room_alias_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub visibility: Option, } @@ -22,6 +30,7 @@ pub mod create_room { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreationContent { #[serde(rename="m.federate")] + #[serde(skip_serializing_if = "Option::is_none")] pub federate: Option, } diff --git a/src/r0/session.rs b/src/r0/session.rs index e144123e..a06307d3 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -12,6 +12,7 @@ pub mod login { pub struct Response { pub access_token: String, pub home_server: String, + #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, pub user_id: String, } @@ -80,6 +81,7 @@ pub mod refresh_access_token { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub access_token: String, + #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, } diff --git a/src/r0/sync.rs b/src/r0/sync.rs index b891e22d..8f1975d5 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -21,10 +21,15 @@ pub mod sync { /// This API endpoint's query parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { + #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub full_state: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub set_presence: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option } diff --git a/src/r0/typing.rs b/src/r0/typing.rs index b4d6a19d..1aafccf4 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -20,6 +20,7 @@ pub mod set_typing { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub typing: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option } From 501692aa2d30a87e74aba24c6b6dbc28683e711a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Br=C3=B6nnimann?= Date: Thu, 29 Dec 2016 19:41:14 +0100 Subject: [PATCH 030/350] The event_type is never used --- src/r0/events.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/r0/events.rs b/src/r0/events.rs index f57a2eb5..229a51c3 100644 --- a/src/r0/events.rs +++ b/src/r0/events.rs @@ -135,7 +135,6 @@ pub mod get_members { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PathParams { pub room_id: RoomId, - pub event_type: String } /// This API endpoint's reponse. From 9c1dd9e51f4303952d912d7fc68f9f7fcc9aa4d4 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 05:04:23 -0800 Subject: [PATCH 031/350] Warn on missing docs. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 177e67a7..385689f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ //! shared by client and server code. #![feature(proc_macro)] +#![warn(missing_docs)] extern crate ruma_api; extern crate ruma_events; From 48727f19683d9c99c13659c6e9a0c2beb29674fb Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 05:13:58 -0800 Subject: [PATCH 032/350] The filter parameter to /sync can be a full filter definition or a filter ID. --- src/r0/sync.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 8f1975d5..fbfee6b2 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -4,25 +4,37 @@ /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) pub mod sync { - use ruma_identifiers::RoomId; use ruma_events::collections::only; + use ruma_identifiers::RoomId; + use std::collections::HashMap; + use r0::filter::FilterDefinition; + /// Details about this API endpoint. pub struct Endpoint; - /// Wether to set presence or not during sync + /// Whether to set presence or not during sync. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum SetPresence { #[serde(rename="offline")] Offline } + /// A filter represented either as its full JSON definition or the ID of a saved filter. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum Filter { + /// A complete filter definition serialized to JSON. + FilterDefinition(FilterDefinition), + /// The ID of a filter saved on the server. + FilterId(String), + } + /// This API endpoint's query parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { #[serde(skip_serializing_if = "Option::is_none")] - pub filter: Option, + pub filter: Option, #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, #[serde(skip_serializing_if = "Option::is_none")] From e7562be4db650bea9b92899110e16f93f6fed5bf Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 05:21:21 -0800 Subject: [PATCH 033/350] Rename various modules. --- src/lib.rs | 1 - src/r0/alias.rs | 6 +- src/r0/contact.rs | 2 +- src/r0/directory.rs | 2 +- src/r0/events.rs | 234 ------------------------------------------- src/r0/membership.rs | 16 +-- src/r0/presence.rs | 4 +- src/r0/redact.rs | 2 +- src/r0/send.rs | 6 +- src/r0/sync.rs | 234 ++++++++++++++++++++++++++++++++++++++++++- src/r0/tag.rs | 4 +- src/r0/typing.rs | 2 +- src/r0/voip.rs | 2 +- 13 files changed, 256 insertions(+), 259 deletions(-) delete mode 100644 src/r0/events.rs diff --git a/src/lib.rs b/src/lib.rs index 385689f8..1f25258d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,6 @@ pub mod r0 { pub mod contact; pub mod context; pub mod directory; - pub mod events; pub mod filter; pub mod media; pub mod membership; diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 21bc19a2..4e032848 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -5,7 +5,7 @@ use ruma_identifiers::RoomAliasId; /// PUT /_matrix/client/r0/directory/room/:room_alias /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) -pub mod create { +pub mod create_alias { use ruma_identifiers::RoomId; /// This API endpoint's body parameters. @@ -40,7 +40,7 @@ pub mod create { /// DELETE /_matrix/client/r0/directory/room/:room_alias /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) -pub mod delete { +pub mod delete_alias { /// Details about this API endpoint. pub struct Endpoint; @@ -67,7 +67,7 @@ pub mod delete { /// GET /_matrix/client/r0/directory/room/:room_alias /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) -pub mod get { +pub mod get_alias { use ruma_identifiers::RoomId; /// Details about this API endpoint. diff --git a/src/r0/contact.rs b/src/r0/contact.rs index cd0d6631..4f021833 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -3,7 +3,7 @@ /// POST /_matrix/client/r0/account/3pid /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) -pub mod add_contact { +pub mod create_contact { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { diff --git a/src/r0/directory.rs b/src/r0/directory.rs index a8c3b51c..3c8aaaed 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -3,7 +3,7 @@ /// GET /_matrix/client/r0/publicRooms /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) -pub mod public_rooms { +pub mod get_public_rooms { use ruma_identifiers::{RoomId, RoomAliasId}; /// A chunk of the response, describing one room diff --git a/src/r0/events.rs b/src/r0/events.rs deleted file mode 100644 index 229a51c3..00000000 --- a/src/r0/events.rs +++ /dev/null @@ -1,234 +0,0 @@ -//! Endpoints for getting events - -/// GET /_matrix/client/r0/rooms/{roomId}/state -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state) -pub mod get_full_state { - use ruma_identifiers::RoomId; - use ruma_events::collections::only; - - /// Details about this API endpoint. - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id: RoomId - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Vec; - - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state", - params.room_id - ) - } - - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state".to_string() - } - } -} - -/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) -pub mod get_state_for_empty_key { - use ruma_identifiers::RoomId; - - /// Details about this API endpoint. - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id: RoomId, - pub event_type: 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 - ) - } - - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() - } - } -} - -/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) -pub mod get_state_for_key { - use ruma_identifiers::RoomId; - - /// Details about this API endpoint. - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id: RoomId, - pub event_type: String, - 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() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() - } - } -} - -/// GET /_matrix/client/r0/rooms/{roomId}/members -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members) -pub mod get_members { - use ruma_identifiers::RoomId; - use ruma_events::room::member::MemberEvent; - - /// Details about this API endpoint. - 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 chunks: Vec - } - - 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() -> String { - "/_matrix/client/r0/rooms/:room_id/members".to_string() - } - } -} - -/// GET /_matrix/client/r0/rooms/{roomId}/messages -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages) -pub mod get_messages { - use ruma_identifiers::RoomId; - use ruma_events::collections::only; - - /// Details about this API endpoint. - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id: RoomId, - pub event_type: String - } - - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum Direction { - #[serde(rename="b")] - Backward, - #[serde(rename="f")] - Forward - } - - /// This API endpoint's query parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct QueryParams { - pub from: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub to: Option, - pub dir: Direction, - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option - } - - /// This API endpoint's reponse. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub start: String, - pub chunks: Vec, - 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() -> String { - "/_matrix/client/r0/rooms/:room_id/messages".to_string() - } - } -} diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 5a33ec35..1ac4c99d 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -18,7 +18,7 @@ pub struct ThirdPartySigned { /// POST /_matrix/client/r0/rooms/{roomId}/invite /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) -pub mod invite { +pub mod invite_user { use ruma_identifiers::RoomId; /// The request type. @@ -62,7 +62,7 @@ pub mod invite { /// POST /_matrix/client/r0/join/{roomIdOrAlias} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) -pub mod join_by_room_id_or_alias { +pub mod join_room_by_id_or_alias { use ruma_identifiers::{RoomId, RoomIdOrAliasId}; use super::ThirdPartySigned; @@ -124,7 +124,7 @@ pub mod join_by_room_id_or_alias { /// POST /_matrix/client/r0/rooms/{roomId}/join /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) -pub mod join_by_room_id { +pub mod join_room_by_id { use ruma_identifiers::RoomId; use super::ThirdPartySigned; @@ -176,7 +176,7 @@ pub mod join_by_room_id { /// POST /_matrix/client/r0/rooms/{roomId}/forget /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) -pub mod forget { +pub mod forget_room { use ruma_identifiers::RoomId; /// Details about this API endpoint. @@ -214,7 +214,7 @@ pub mod forget { /// POST /_matrix/client/r0/rooms/{roomId}/leave /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) -pub mod leave { +pub mod leave_room { use ruma_identifiers::RoomId; /// Details about this API endpoint. @@ -252,7 +252,7 @@ pub mod leave { /// POST /_matrix/client/r0/rooms/{roomId}/kick /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) -pub mod kick { +pub mod kick_user { use ruma_identifiers::RoomId; /// The request type. @@ -298,7 +298,7 @@ pub mod kick { /// POST /_matrix/client/r0/rooms/{roomId}/unban /// /// [matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) -pub mod unban { +pub mod unban_user { use ruma_identifiers::RoomId; /// The request type. @@ -342,7 +342,7 @@ pub mod unban { /// POST /_matrix/client/r0/rooms/{roomId}/ban /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) -pub mod ban { +pub mod ban_user { use ruma_identifiers::RoomId; /// The request type. diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 7fc8aab0..af3fbe83 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -101,7 +101,7 @@ pub mod get_presence { /// POST /_matrix/client/r0/presence/list/{userId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) -pub mod update_presence_list { +pub mod update_presence_subscriptions { use ruma_identifiers::UserId; /// Details about this API endpoint. @@ -150,7 +150,7 @@ pub mod update_presence_list { /// GET /_matrix/client/r0/presence/list/{userId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) -pub mod get_presence_list_status { +pub mod get_subscribed_presences { use ruma_identifiers::UserId; use ruma_events::presence::PresenceEvent; diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 93b19db1..04bcbe9b 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -3,7 +3,7 @@ /// PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) -pub mod send_event { +pub mod redact_event { use ruma_identifiers::{RoomId, EventId}; /// Details about this API endpoint. diff --git a/src/r0/send.rs b/src/r0/send.rs index 7ed322db..c72faf8f 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -3,7 +3,7 @@ /// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) -pub mod send_state { +pub mod send_state_event { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -51,7 +51,7 @@ pub mod send_state { /// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) -pub mod send_state_key { +pub mod send_state_event_by_state_key { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -101,7 +101,7 @@ pub mod send_state_key { /// PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) -pub mod send_event { +pub mod send_message_event { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; diff --git a/src/r0/sync.rs b/src/r0/sync.rs index fbfee6b2..42edcd5b 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -1,9 +1,241 @@ //! Endpoints for getting and synchronizing events. +/// GET /_matrix/client/r0/rooms/{roomId}/state +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state) +pub mod get_state_events { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Vec; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/state", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) +pub mod get_state_event_by_event_type { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: 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 + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) +pub mod get_state_event_by_state_key { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String, + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/members +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members) +pub mod get_member_events { + use ruma_identifiers::RoomId; + use ruma_events::room::member::MemberEvent; + + /// Details about this API endpoint. + 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 chunks: Vec + } + + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/members".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/messages +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages) +pub mod get_message_events { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum Direction { + #[serde(rename="b")] + Backward, + #[serde(rename="f")] + Forward + } + + /// This API endpoint's query parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct QueryParams { + pub from: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub to: Option, + pub dir: Direction, + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option + } + + /// This API endpoint's reponse. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub start: String, + pub chunks: Vec, + 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() -> String { + "/_matrix/client/r0/rooms/:room_id/messages".to_string() + } + } +} /// GET /_matrix/client/r0/sync /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) -pub mod sync { +pub mod sync_events { use ruma_events::collections::only; use ruma_identifiers::RoomId; diff --git a/src/r0/tag.rs b/src/r0/tag.rs index f84d0169..1493789e 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -3,7 +3,7 @@ /// PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -pub mod add_tag { +pub mod create_tag { use ruma_identifiers::{UserId, RoomId}; use ruma_events::tag::TagInfo; @@ -93,7 +93,7 @@ pub mod get_tags { /// DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -pub mod del_tag { +pub mod delete_tag { use ruma_identifiers::{UserId, RoomId}; /// Details about this API endpoint. diff --git a/src/r0/typing.rs b/src/r0/typing.rs index 1aafccf4..5cf9691a 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -3,7 +3,7 @@ /// PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) -pub mod set_typing { +pub mod start_or_stop_typing { use ruma_identifiers::{UserId, RoomId}; /// Details about this API endpoint. diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 93ff49db..36846f69 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -3,7 +3,7 @@ /// GET /_matrix/client/r0/voip/turnServer /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) -pub mod turnserver { +pub mod get_turn_server_info { /// Details about this API endpoint. pub struct Endpoint; From 8df29f8898c8990ec0ef12a01548799e7fa96433 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 14:14:13 -0800 Subject: [PATCH 034/350] Implement content/media repository endpoints. --- src/r0/media.rs | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/src/r0/media.rs b/src/r0/media.rs index 346cd571..c82e8c38 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -1 +1,141 @@ //! Endpoints for the media repository. + +/// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) +pub mod get_content { + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug)] + pub struct PathParams { + /// The media ID from the mxc:// URI (the path component). + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + pub server_name: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = (); // TODO: How should a file be represented as a response? + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/media/r0/download/{}/{}", + params.server_name, + params.media_id + ) + } + + fn router_path() -> String { + "/_matrix/media/r0/download/:server_name/:media_id".to_string() + } + } +} + +/// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) +pub mod create_content { + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + /// The MXC URI for the uploaded content. + pub content_uri: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); // TODO: How should a file be represented as the request body? + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/media/r0/upload".to_string() + } + } +} + +/// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) +pub mod get_content_thumbnail { + use std::fmt::{Display, Error as FmtError, Formatter}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// The desired resizing method. + #[derive(Clone, Copy, Debug)] + pub enum Method { + /// Crop the original to produce the requested image dimensions. + Crop, + /// Maintain the original aspect ratio of the source image. + Scale, + } + + /// This API endpoint's path parameters. + pub struct PathParams { + /// The media ID from the mxc:// URI (the path component). + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + pub server_name: String, + } + + /// This API endpoint's query string parameters. + #[derive(Clone, Debug)] + pub struct QueryParams { + /// The *desired* height of the thumbnail. The actual thumbnail may not match the size + /// specified. + pub height: Option, + /// The desired resizing method. + pub method: Option, + /// The *desired* width of the thumbnail. The actual thumbnail may not match the size + /// specified. + pub width: Option, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = QueryParams; + type Response = (); // TODO: How should a file be represented as a response? + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/media/r0/thumbnail/{}/{}", + params.server_name, + params.media_id + ) + } + + fn router_path() -> String { + "/_matrix/media/r0/thumbnail/:server_name/:media_id".to_string() + } + } + + impl Display for Method { + fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + match *self { + Method::Crop => write!(f, "crop"), + Method::Scale => write!(f, "scale"), + } + } + } +} From b103b8709037e3b71644ab9165c87e3a89ae4832 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 14:26:26 -0800 Subject: [PATCH 035/350] Link endpoint paths directly to the spec. --- src/lib.rs | 4 +--- src/r0/account.rs | 20 +++++--------------- src/r0/alias.rs | 12 +++--------- src/r0/config.rs | 8 ++------ src/r0/contact.rs | 12 +++--------- src/r0/context.rs | 4 +--- src/r0/directory.rs | 4 +--- src/r0/filter.rs | 8 ++------ src/r0/membership.rs | 32 ++++++++------------------------ src/r0/presence.rs | 16 ++++------------ src/r0/profile.rs | 20 +++++--------------- src/r0/redact.rs | 4 +--- src/r0/room.rs | 4 +--- src/r0/send.rs | 12 +++--------- src/r0/session.rs | 12 +++--------- src/r0/sync.rs | 25 +++++++------------------ src/r0/tag.rs | 12 +++--------- src/r0/typing.rs | 4 +--- src/r0/voip.rs | 4 +--- 19 files changed, 55 insertions(+), 162 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1f25258d..8a89c5db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,5 @@ pub mod r0 { pub mod voip; } -/// GET /_matrix/client/versions -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) +/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) pub mod supported_versions; diff --git a/src/r0/account.rs b/src/r0/account.rs index bad73ebe..21a976d7 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -1,8 +1,6 @@ //! Endpoints for account registration and management. -/// POST /_matrix/client/r0/register -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) +/// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) pub mod register { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -61,9 +59,7 @@ pub mod register { } } -/// POST /_matrix/client/r0/account/password/email/requestToken -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) +/// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -98,9 +94,7 @@ pub mod request_password_change_token { } } -/// POST /_matrix/client/r0/account/deactivate -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) +/// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) pub mod deactivate { /// Details about this API endpoint. pub struct Endpoint; @@ -125,9 +119,7 @@ pub mod deactivate { } } -/// POST /_matrix/client/r0/account/password -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) +/// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) pub mod change_password { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -158,9 +150,7 @@ pub mod change_password { } } -/// POST /_matrix/client/r0/register/email/requestToken -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) +/// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) pub mod request_register_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 4e032848..2bbaa1e3 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -2,9 +2,7 @@ use ruma_identifiers::RoomAliasId; -/// PUT /_matrix/client/r0/directory/room/:room_alias -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) +/// [PUT /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) pub mod create_alias { use ruma_identifiers::RoomId; @@ -37,9 +35,7 @@ pub mod create_alias { } } -/// DELETE /_matrix/client/r0/directory/room/:room_alias -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) +/// [DELETE /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) pub mod delete_alias { /// Details about this API endpoint. pub struct Endpoint; @@ -64,9 +60,7 @@ pub mod delete_alias { } } -/// GET /_matrix/client/r0/directory/room/:room_alias -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) +/// [GET /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) pub mod get_alias { use ruma_identifiers::RoomId; diff --git a/src/r0/config.rs b/src/r0/config.rs index c6014f4f..cfb0a725 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1,8 +1,6 @@ //! Endpoints for client configuration. -/// PUT /_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) +/// [PUT /_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) pub mod set_room_account_data { use ruma_identifiers::{RoomId, UserId}; @@ -42,9 +40,7 @@ pub mod set_room_account_data { } } -/// PUT /_matrix/client/r0/user/:user_id/account_data/:type -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) +/// [PUT /_matrix/client/r0/user/:user_id/account_data/:type](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) pub mod set_global_account_data { use ruma_identifiers::UserId; diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 4f021833..0f3ef359 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -1,8 +1,6 @@ //! Endpoints for account contact information. -/// POST /_matrix/client/r0/account/3pid -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) +/// [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) pub mod create_contact { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -43,9 +41,7 @@ pub mod create_contact { } } -/// GET /_matrix/client/r0/account/3pid -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) +/// [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) pub mod get_contacts { /// Details about this API endpoint. pub struct Endpoint; @@ -90,9 +86,7 @@ pub mod get_contacts { } } -/// POST /_matrix/client/r0/account/3pid/email/requestToken -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) +/// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/context.rs b/src/r0/context.rs index 9bdf1da2..9d29b600 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -1,8 +1,6 @@ //! Endpoints for event context. -/// GET /_matrix/client/r0/rooms/:room_id/context/:event_id -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) +/// [GET /_matrix/client/r0/rooms/:room_id/context/:event_id](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) pub mod get_context { use ruma_identifiers::{EventId, RoomId}; use ruma_events::collections::only; diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 3c8aaaed..c59dd949 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1,8 +1,6 @@ //! Endpoints for the public room directory. -/// GET /_matrix/client/r0/publicRooms -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) +/// [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) pub mod get_public_rooms { use ruma_identifiers::{RoomId, RoomAliasId}; diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 6c9f883b..b72c1a9f 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -94,9 +94,7 @@ pub struct FilterDefinition { pub presence: Option } -/// POST /_matrix/client/r0/user/{userId}/filter -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) +/// [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) pub mod create_filter { use ruma_identifiers::UserId; use super::FilterDefinition; @@ -139,9 +137,7 @@ pub mod create_filter { } } -/// GET /_matrix/client/r0/user/{userId}/filter/{filterId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) +/// [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) pub mod get_filter { use ruma_identifiers::UserId; use super::FilterDefinition; diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 1ac4c99d..e4bf7b1e 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -15,9 +15,7 @@ pub struct ThirdPartySigned { pub token: String, } -/// POST /_matrix/client/r0/rooms/{roomId}/invite -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) +/// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) pub mod invite_user { use ruma_identifiers::RoomId; @@ -59,9 +57,7 @@ pub mod invite_user { } } -/// POST /_matrix/client/r0/join/{roomIdOrAlias} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) +/// [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) pub mod join_room_by_id_or_alias { use ruma_identifiers::{RoomId, RoomIdOrAliasId}; use super::ThirdPartySigned; @@ -121,9 +117,7 @@ pub mod join_room_by_id_or_alias { } } -/// POST /_matrix/client/r0/rooms/{roomId}/join -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) +/// [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) pub mod join_room_by_id { use ruma_identifiers::RoomId; use super::ThirdPartySigned; @@ -173,9 +167,7 @@ pub mod join_room_by_id { } } -/// POST /_matrix/client/r0/rooms/{roomId}/forget -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) +/// [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) pub mod forget_room { use ruma_identifiers::RoomId; @@ -211,9 +203,7 @@ pub mod forget_room { } } -/// POST /_matrix/client/r0/rooms/{roomId}/leave -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) +/// [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) pub mod leave_room { use ruma_identifiers::RoomId; @@ -249,9 +239,7 @@ pub mod leave_room { } } -/// POST /_matrix/client/r0/rooms/{roomId}/kick -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) +/// [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) pub mod kick_user { use ruma_identifiers::RoomId; @@ -295,9 +283,7 @@ pub mod kick_user { } } -/// POST /_matrix/client/r0/rooms/{roomId}/unban -/// -/// [matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) +/// [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) pub mod unban_user { use ruma_identifiers::RoomId; @@ -339,9 +325,7 @@ pub mod unban_user { } } -/// POST /_matrix/client/r0/rooms/{roomId}/ban -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) +/// [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) pub mod ban_user { use ruma_identifiers::RoomId; diff --git a/src/r0/presence.rs b/src/r0/presence.rs index af3fbe83..83286f67 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -1,8 +1,6 @@ //! Endpoints for user presence. -/// PUT /_matrix/client/r0/presence/{userId}/status -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) +/// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) pub mod set_presence { use ruma_identifiers::UserId; use ruma_events::presence::PresenceState; @@ -47,9 +45,7 @@ pub mod set_presence { } } -/// GET /_matrix/client/r0/presence/{userId}/status -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) +/// [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) pub mod get_presence { use ruma_identifiers::UserId; use ruma_events::presence::PresenceState; @@ -98,9 +94,7 @@ pub mod get_presence { } } -/// POST /_matrix/client/r0/presence/list/{userId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) +/// [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) pub mod update_presence_subscriptions { use ruma_identifiers::UserId; @@ -147,9 +141,7 @@ pub mod update_presence_subscriptions { } } -/// GET /_matrix/client/r0/presence/list/{userId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) +/// [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) pub mod get_subscribed_presences { use ruma_identifiers::UserId; use ruma_events::presence::PresenceEvent; diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 30b8370b..3eadd736 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -1,8 +1,6 @@ //! Endpoints for user profiles. -/// GET /_matrix/client/r0/profile/{userId}/displayname -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) +/// [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) pub mod get_display_name { use ruma_identifiers::UserId; @@ -46,9 +44,7 @@ pub mod get_display_name { } -/// PUT /_matrix/client/r0/profile/{userId}/displayname -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) +/// [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) pub mod set_display_name { use ruma_identifiers::UserId; @@ -91,9 +87,7 @@ pub mod set_display_name { } } -/// GET /_matrix/client/r0/profile/{userId}/avatar_url -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) +/// [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) pub mod get_avatar_url { use ruma_identifiers::UserId; @@ -136,9 +130,7 @@ pub mod get_avatar_url { } } -/// PUT /_matrix/client/r0/profile/{userId}/avatar_url -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) +/// [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) pub mod set_avatar_url { use ruma_identifiers::UserId; @@ -181,9 +173,7 @@ pub mod set_avatar_url { } } -/// GET /_matrix/client/r0/profile/{userId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) +/// [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) pub mod get_profile { use ruma_identifiers::UserId; diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 04bcbe9b..0e59d2e6 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -1,8 +1,6 @@ //! Endpoints for event redaction. -/// PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) +/// [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) pub mod redact_event { use ruma_identifiers::{RoomId, EventId}; diff --git a/src/r0/room.rs b/src/r0/room.rs index 7a15f961..98e4ee21 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,8 +1,6 @@ //! Endpoints for room creation. -/// POST /_matrix/client/r0/createRoom -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom) +/// [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; diff --git a/src/r0/send.rs b/src/r0/send.rs index c72faf8f..d5d4d370 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -1,8 +1,6 @@ //! Endpoints for sending events. -/// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) +/// [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 { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -48,9 +46,7 @@ pub mod send_state_event { } } -/// PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) +/// [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_by_state_key { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -98,9 +94,7 @@ pub mod send_state_event_by_state_key { } } -/// PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) +/// [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_identifiers::{RoomId, EventId}; use ruma_events::EventType; diff --git a/src/r0/session.rs b/src/r0/session.rs index a06307d3..9f6f395a 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -1,8 +1,6 @@ //! Endpoints for user session management. -/// POST /_matrix/client/r0/login -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) +/// [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. pub struct Endpoint; @@ -37,9 +35,7 @@ pub mod login { } } -/// POST /_matrix/client/r0/logout -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout) +/// [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. pub struct Endpoint; @@ -64,9 +60,7 @@ pub mod logout { } } -/// POST /_matrix/client/r0/tokenrefresh -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-tokenrefresh) +/// [POST /_matrix/client/r0/tokenrefresh](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-tokenrefresh) pub mod refresh_access_token { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 42edcd5b..06b63e4f 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -1,8 +1,6 @@ //! Endpoints for getting and synchronizing events. -/// GET /_matrix/client/r0/rooms/{roomId}/state -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state) +/// [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_identifiers::RoomId; use ruma_events::collections::only; @@ -39,9 +37,7 @@ pub mod get_state_events { } } -/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) +/// [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_event_by_event_type { use ruma_identifiers::RoomId; @@ -79,9 +75,7 @@ pub mod get_state_event_by_event_type { } } -/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) +/// [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_event_by_state_key { use ruma_identifiers::RoomId; @@ -121,9 +115,7 @@ pub mod get_state_event_by_state_key { } } -/// GET /_matrix/client/r0/rooms/{roomId}/members -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members) +/// [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_identifiers::RoomId; use ruma_events::room::member::MemberEvent; @@ -166,9 +158,7 @@ pub mod get_member_events { } } -/// GET /_matrix/client/r0/rooms/{roomId}/messages -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages) +/// [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_identifiers::RoomId; use ruma_events::collections::only; @@ -232,9 +222,8 @@ pub mod get_message_events { } } } -/// GET /_matrix/client/r0/sync -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) + +/// [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_events::collections::only; use ruma_identifiers::RoomId; diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 1493789e..9afcc103 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -1,8 +1,6 @@ //! Endpoints for tagging rooms. -/// PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +/// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod create_tag { use ruma_identifiers::{UserId, RoomId}; use ruma_events::tag::TagInfo; @@ -43,9 +41,7 @@ pub mod create_tag { } } -/// GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) +/// [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) pub mod get_tags { use ruma_identifiers::{UserId, RoomId}; use ruma_events::tag::TagEventContent; @@ -90,9 +86,7 @@ pub mod get_tags { } } -/// DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +/// [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod delete_tag { use ruma_identifiers::{UserId, RoomId}; diff --git a/src/r0/typing.rs b/src/r0/typing.rs index 5cf9691a..cb01ef60 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -1,8 +1,6 @@ //! Endpoints for typing notifications. -/// PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId} -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) +/// [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) pub mod start_or_stop_typing { use ruma_identifiers::{UserId, RoomId}; diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 36846f69..39c4423b 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -1,8 +1,6 @@ //! Endpoints for Voice over IP. -/// GET /_matrix/client/r0/voip/turnServer -/// -/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) +/// [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) pub mod get_turn_server_info { /// Details about this API endpoint. pub struct Endpoint; From 35672b968bba1fcaeb7be8d6d3a361028d9bef00 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 14:53:24 -0800 Subject: [PATCH 036/350] Implement receipt endpoints. --- src/r0/receipt.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index f955cfe1..73c25a20 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -1 +1,65 @@ //! Endpoints for event receipts. + +/// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) +pub mod create_receipt { + use ruma_identifiers::{EventId, RoomId}; + + use std::fmt::{Display, Error as FmtError, Formatter}; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This endpoint's path parameters. + #[derive(Clone, Debug)] + pub struct PathParams { + /// The event ID to acknowledge up to. + pub event_id: EventId, + /// The type of receipt to send. + pub receipt_type: ReceiptType, + /// The room in which to send the event. + pub room_id: RoomId, + } + + /// The type of receipt. + #[derive(Clone, Copy, Debug)] + pub enum ReceiptType { + /// m.read + Read, + } + + /// This API endpoint's response. + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] + pub struct Response; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/receipt/{}/{}", + params.room_id, + params.receipt_type, + params.event_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id".to_string() + } + } + + impl Display for ReceiptType { + fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + match *self { + ReceiptType::Read => write!(f, "m.read"), + } + } + } +} From 8f0905adbac9af096505deef788fe7d557fee3b5 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 15:12:22 -0800 Subject: [PATCH 037/350] Implement server administration endpoints. --- src/r0/server.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/r0/server.rs b/src/r0/server.rs index bf4489c4..3abcd4cc 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -1 +1,75 @@ //! Endpoints for server administration. + +/// [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid) +pub mod get_user_info { + use ruma_identifiers::UserId; + + use std::collections::HashMap; + + /// Information about a connection in a user session. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ConnectionInfo { + /// Most recently seen IP address of the session. + pub ip: String, + /// Unix timestamp that the session was last active. + pub last_seen: u64, + /// User agent string last seen in the session. + pub user_agent: String, + } + + /// Information about a user's device. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct DeviceInfo { + /// A list of user sessions on this device. + pub sessions: Vec, + } + + /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug)] + pub struct PathParams { + /// The user to look up. + pub user_id: UserId, + } + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + /// The Matrix user ID of the user. + pub user_id: UserId, + /// A map of the user's device identifiers to information about that device. + pub devices: HashMap, + } + + /// Information about a user session. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct SessionInfo { + /// A list of connections in this session. + pub connections: Vec, + } + + 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/admin/whois/{}", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/admin/whois/:user_id".to_string() + } + } +} From 0b295fe0f0771f28eed560e1cf1bc20a9718d0fe Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 17:42:46 -0800 Subject: [PATCH 038/350] Use consistent wording for QueryParams docs. --- src/r0/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 06b63e4f..dc8981d1 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -181,7 +181,7 @@ pub mod get_message_events { Forward } - /// This API endpoint's query parameters. + /// This API endpoint's query string parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { pub from: String, @@ -251,7 +251,7 @@ pub mod sync_events { FilterId(String), } - /// This API endpoint's query parameters. + /// This API endpoint's query string parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { #[serde(skip_serializing_if = "Option::is_none")] From 130a4b5a9890e9be20acffd8d4f9583f3786e021 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 18:54:45 -0800 Subject: [PATCH 039/350] Implement search endpoints. --- src/r0/search.rs | 230 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/src/r0/search.rs b/src/r0/search.rs index 07a22562..3ed04688 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -1 +1,231 @@ //! Endpoints for event searches. + +/// [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 { + use ruma_events::collections::all::Event; + use ruma_identifiers::{EventId, RoomId, UserId}; + + use r0::filter::RoomEventFilter; + use r0::profile::get_profile::Response as UserProfile; + + use std::collections::HashMap; + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + /// Describes which categories to search in and their criteria. + pub search_categories: Categories, + } + + /// Categories of events that can be searched for. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Categories { + /// Criteria for searching a category of events. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_events: Option + } + + /// Criteria for searching a category of events. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Criteria { + /// Configures whether any context for the events returned are included in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub event_context: Option, + /// A `Filter` to apply to the search. + // TODO: "timeline" key might need to be included. + // See https://github.com/matrix-org/matrix-doc/issues/598. + #[serde(skip_serializing_if = "Option::is_none")] + pub filter: Option, + /// Requests that the server partitions the result set based on the provided list of keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub groupings: Option, + /// Requests the server return the current state for each room returned. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_state: Option, + /// The keys to search for. Defaults to all keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub keys: Option>, + /// The order in which to search for results. + #[serde(skip_serializing_if = "Option::is_none")] + pub order_by: Option, + /// The string to search events for. + 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. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct EventContext { + /// How many events after the result are returned. + pub after_limit: u64, + /// How many events before the result are returned. + pub before_limit: u64, + /// Requests that the server returns the historic profile information for the users that + /// sent the events that were returned. + pub include_profile: bool, + } + + /// Context for search results, if requested. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct EventContextResult { + /// Pagination token for the end of the chunk. + pub end: String, + /// Events just after the result. + #[serde(skip_serializing_if = "Option::is_none")] + pub events_after: Option>, + /// Events just before the result. + #[serde(skip_serializing_if = "Option::is_none")] + pub events_before: Option>, + /// The historic profile information of the users that sent the events returned. + // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 + #[serde(skip_serializing_if = "Option::is_none")] + pub profile_info: Option>, + /// Pagination token for the start of the chunk. + pub start: String, + } + + /// A grouping for partioning the result set. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Grouping { + /// The key within events to use for this grouping. + pub key: GroupingKey + } + + /// The key within events to use for this grouping. + #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] + pub enum GroupingKey { + /// `room_id` + #[serde(rename="room_id")] + RoomId, + /// `sender` + #[serde(rename="sender")] + Sender, + } + + /// Requests that the server partitions the result set based on the provided list of keys. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Groupings { + /// List of groups to request. + pub group_by: Vec, + } + + /// The keys to search for. + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] + pub enum SearchKeys { + /// content.body + #[serde(rename="content.body")] + ContentBody, + /// content.name + #[serde(rename="content.name")] + ContentName, + /// content.topic + #[serde(rename="content.topic")] + ContentTopic, + } + + /// The order in which to search for results. + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] + pub enum OrderBy { + /// Prioritize events by a numerical ranking of how closely they matched the search + /// criteria. + #[serde(rename="rank")] + Rank, + /// Prioritize recent events. + #[serde(rename="recent")] + Recent, + } + + /// This API endpoint's query string parameters. + #[derive(Clone, Debug)] + 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, + } + + /// 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. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ResultCategories { + /// Room event results. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_events: Option, + } + + /// Categories of events that can be searched for. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct RoomEventResults { + /// An approximate count of the total number of results found. + pub count: u64, + /// Any groups that were requested. + // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 + pub groups: HashMap>, + /// Token that can be used to get the next batch of results, by passing as the `next_batch` + /// parameter to the next call. If this field is absent, there are no more results. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, + /// List of results in the requested order. + pub results: Vec, + /// The current state for every room in the results. This is included if the request had the + /// `include_state` key set with a value of `true`. + #[serde(skip_serializing_if = "Option::is_none")] + // TODO: Major WTF here. https://github.com/matrix-org/matrix-doc/issues/773 + pub state: Option<()>, + } + + /// A grouping of results, if requested. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct ResultGroup { + /// Token that can be used to get the next batch of results in the group, by passing as the + /// `next_batch` parameter to the next call. If this field is absent, there are no more + /// results in this group. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, + /// Key that can be used to order different groups. + pub order: u64, + /// Which results are in this group. + pub results: Vec, + } + + /// A search result. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct SearchResult { + /// Context for result, if requested. + #[serde(skip_serializing_if = "Option::is_none")] + pub context: Option, + /// A number that describes how closely this result matches the search. Higher is closer. + pub rank: f64, + /// The event that matched. + pub result: Event, + } + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = (); + type QueryParams = QueryParams; + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/search".to_string() + } + } +} From 0535405ae64fadc01462912290b6828ec08edb3a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 30 Dec 2016 23:13:19 -0800 Subject: [PATCH 040/350] Derive Clone, Copy, and Debug for Endpoint structs. --- src/lib.rs | 1 + src/r0/account.rs | 5 +++++ src/r0/alias.rs | 3 +++ src/r0/config.rs | 2 ++ src/r0/contact.rs | 3 +++ src/r0/context.rs | 1 + src/r0/directory.rs | 1 + src/r0/filter.rs | 2 ++ src/r0/media.rs | 4 ++++ src/r0/membership.rs | 8 ++++++++ src/r0/presence.rs | 4 ++++ src/r0/profile.rs | 5 +++++ src/r0/receipt.rs | 1 + src/r0/redact.rs | 1 + src/r0/room.rs | 1 + src/r0/send.rs | 3 +++ src/r0/session.rs | 3 +++ src/r0/sync.rs | 6 ++++++ src/r0/tag.rs | 3 +++ src/r0/typing.rs | 1 + src/r0/voip.rs | 1 + src/supported_versions.rs | 1 + 22 files changed, 60 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8a89c5db..2ed8314c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ //! shared by client and server code. #![feature(proc_macro)] +#![deny(missing_debug_implementations)] #![warn(missing_docs)] extern crate ruma_api; diff --git a/src/r0/account.rs b/src/r0/account.rs index 21a976d7..a10b171c 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -13,6 +13,7 @@ pub mod register { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's query string parameters. @@ -72,6 +73,7 @@ pub mod request_password_change_token { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -97,6 +99,7 @@ pub mod request_password_change_token { /// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) pub mod deactivate { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -128,6 +131,7 @@ pub mod change_password { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -163,6 +167,7 @@ pub mod request_register_token { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 2bbaa1e3..888e7130 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -13,6 +13,7 @@ pub mod create_alias { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -38,6 +39,7 @@ pub mod create_alias { /// [DELETE /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) pub mod delete_alias { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -65,6 +67,7 @@ pub mod get_alias { use ruma_identifiers::RoomId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's response. diff --git a/src/r0/config.rs b/src/r0/config.rs index cfb0a725..321e0cdd 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -5,6 +5,7 @@ pub mod set_room_account_data { use ruma_identifiers::{RoomId, UserId}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -45,6 +46,7 @@ pub mod set_global_account_data { use ruma_identifiers::UserId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 0f3ef359..19013ef1 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -11,6 +11,7 @@ pub mod create_contact { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The third party credentials to associate with the account. @@ -44,6 +45,7 @@ pub mod create_contact { /// [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) pub mod get_contacts { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The medium of third party identifier. @@ -99,6 +101,7 @@ pub mod request_contact_verification_token { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { diff --git a/src/r0/context.rs b/src/r0/context.rs index 9d29b600..9d47f40e 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -7,6 +7,7 @@ pub mod get_context { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/directory.rs b/src/r0/directory.rs index c59dd949..bc8288f8 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -29,6 +29,7 @@ pub mod get_public_rooms { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { diff --git a/src/r0/filter.rs b/src/r0/filter.rs index b72c1a9f..536d6ec1 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -100,6 +100,7 @@ pub mod create_filter { use super::FilterDefinition; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -143,6 +144,7 @@ pub mod get_filter { use super::FilterDefinition; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/media.rs b/src/r0/media.rs index c82e8c38..e7a1b8fd 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -3,6 +3,7 @@ /// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) pub mod get_content { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -41,6 +42,7 @@ pub mod get_content { /// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) pub mod create_content { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's response. @@ -75,6 +77,7 @@ pub mod get_content_thumbnail { use std::fmt::{Display, Error as FmtError, Formatter}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The desired resizing method. @@ -87,6 +90,7 @@ pub mod get_content_thumbnail { } /// This API endpoint's path parameters. + #[derive(Clone, Debug)] pub struct PathParams { /// The media ID from the mxc:// URI (the path component). pub media_id: String, diff --git a/src/r0/membership.rs b/src/r0/membership.rs index e4bf7b1e..343c2b5d 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -26,6 +26,7 @@ pub mod invite_user { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -70,6 +71,7 @@ pub mod join_room_by_id_or_alias { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The response type. @@ -130,6 +132,7 @@ pub mod join_room_by_id { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The response type. @@ -172,6 +175,7 @@ pub mod forget_room { use ruma_identifiers::RoomId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -208,6 +212,7 @@ pub mod leave_room { use ruma_identifiers::RoomId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -252,6 +257,7 @@ pub mod kick_user { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -294,6 +300,7 @@ pub mod unban_user { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -338,6 +345,7 @@ pub mod ban_user { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 83286f67..df206f42 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -6,6 +6,7 @@ pub mod set_presence { use ruma_events::presence::PresenceState; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -51,6 +52,7 @@ pub mod get_presence { use ruma_events::presence::PresenceState; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -99,6 +101,7 @@ pub mod update_presence_subscriptions { use ruma_identifiers::UserId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -147,6 +150,7 @@ pub mod get_subscribed_presences { use ruma_events::presence::PresenceEvent; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 3eadd736..db4cf0d1 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -18,6 +18,7 @@ pub mod get_display_name { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -62,6 +63,7 @@ pub mod set_display_name { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -105,6 +107,7 @@ pub mod get_avatar_url { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -148,6 +151,7 @@ pub mod set_avatar_url { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { @@ -193,6 +197,7 @@ pub mod get_profile { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; impl ::Endpoint for Endpoint { diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index 73c25a20..63e6a623 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -7,6 +7,7 @@ pub mod create_receipt { use std::fmt::{Display, Error as FmtError, Formatter}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This endpoint's path parameters. diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 0e59d2e6..b1847f19 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -5,6 +5,7 @@ pub mod redact_event { use ruma_identifiers::{RoomId, EventId}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/room.rs b/src/r0/room.rs index 98e4ee21..bd5f3c7c 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -33,6 +33,7 @@ pub mod create_room { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// The response type. diff --git a/src/r0/send.rs b/src/r0/send.rs index d5d4d370..649ce531 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -6,6 +6,7 @@ pub mod send_state_event { use ruma_events::EventType; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -52,6 +53,7 @@ pub mod send_state_event_by_state_key { use ruma_events::EventType; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -100,6 +102,7 @@ pub mod send_message_event { use ruma_events::EventType; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/session.rs b/src/r0/session.rs index 9f6f395a..70ad2cc6 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -3,6 +3,7 @@ /// [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; /// This API endpoint's response. @@ -38,6 +39,7 @@ pub mod login { /// [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; impl ::Endpoint for Endpoint { @@ -69,6 +71,7 @@ pub mod refresh_access_token { } /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's response. diff --git a/src/r0/sync.rs b/src/r0/sync.rs index dc8981d1..951a7217 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -6,6 +6,7 @@ pub mod get_state_events { use ruma_events::collections::only; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -42,6 +43,7 @@ pub mod get_state_event_by_event_type { use ruma_identifiers::RoomId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -80,6 +82,7 @@ pub mod get_state_event_by_state_key { use ruma_identifiers::RoomId; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -121,6 +124,7 @@ pub mod get_member_events { use ruma_events::room::member::MemberEvent; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -164,6 +168,7 @@ pub mod get_message_events { use ruma_events::collections::only; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -233,6 +238,7 @@ pub mod sync_events { use r0::filter::FilterDefinition; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// Whether to set presence or not during sync. diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 9afcc103..4b067e79 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -6,6 +6,7 @@ pub mod create_tag { use ruma_events::tag::TagInfo; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -47,6 +48,7 @@ pub mod get_tags { use ruma_events::tag::TagEventContent; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. @@ -91,6 +93,7 @@ pub mod delete_tag { use ruma_identifiers::{UserId, RoomId}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/typing.rs b/src/r0/typing.rs index cb01ef60..bf2afc6d 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -5,6 +5,7 @@ pub mod start_or_stop_typing { use ruma_identifiers::{UserId, RoomId}; /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 39c4423b..4df3f482 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -3,6 +3,7 @@ /// [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) pub mod get_turn_server_info { /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's path parameters. diff --git a/src/supported_versions.rs b/src/supported_versions.rs index 0e0e8299..bfc24b6f 100644 --- a/src/supported_versions.rs +++ b/src/supported_versions.rs @@ -1,4 +1,5 @@ /// Details about this API endpoint. +#[derive(Clone, Copy, Debug)] pub struct Endpoint; /// This API endpoint's response. From 472ce01769d86ba3ca6752cd618a9a0027802bb8 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 31 Dec 2016 12:31:39 +0100 Subject: [PATCH 041/350] Point-out inconsistencies with spec --- src/r0/account.rs | 6 ++++++ src/r0/contact.rs | 7 ++++--- src/r0/media.rs | 1 + src/r0/membership.rs | 7 +++++-- src/r0/presence.rs | 4 ++-- src/r0/room.rs | 7 ++++--- src/r0/search.rs | 5 +++-- src/r0/session.rs | 2 ++ 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index a10b171c..fa31316d 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -10,6 +10,7 @@ pub mod register { pub password: String, #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, + // TODO: `auth` field } /// Details about this API endpoint. @@ -38,6 +39,7 @@ pub mod register { pub access_token: String, pub home_server: String, pub user_id: String, + // TODO: `refresh_token` field? (more or less deprecated?) } impl ::Endpoint for Endpoint { @@ -62,6 +64,7 @@ pub mod register { /// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { + // TODO: according to the spec, this does not has any params /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { @@ -102,6 +105,8 @@ pub mod deactivate { #[derive(Clone, Copy, Debug)] pub struct Endpoint; + // TODO: missing BodyParams + impl ::Endpoint for Endpoint { type BodyParams = (); type PathParams = (); @@ -128,6 +133,7 @@ pub mod change_password { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub new_password: String, + // TODO: missing `auth` field } /// Details about this API endpoint. diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 19013ef1..571d3bb3 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -17,9 +17,9 @@ pub mod create_contact { /// The third party credentials to associate with the account. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThreePidCredentials { - client_secret: String, - id_server: String, - sid: String, + pub client_secret: String, + pub id_server: String, + pub sid: String, } impl ::Endpoint for Endpoint { @@ -90,6 +90,7 @@ pub mod get_contacts { /// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { + // TODO: according to the spec this takes no parameters /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { diff --git a/src/r0/media.rs b/src/r0/media.rs index e7a1b8fd..efe68e69 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -20,6 +20,7 @@ pub mod get_content { type PathParams = PathParams; type QueryParams = (); type Response = (); // TODO: How should a file be represented as a response? + // must include HTTP headers Content-Type and Content-Disposition (filename) fn method() -> ::Method { ::Method::Get diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 343c2b5d..f5e2fe63 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -2,6 +2,9 @@ use ruma_signatures::Signatures; +// TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } +// for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? + /// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartySigned { @@ -17,12 +20,12 @@ pub struct ThirdPartySigned { /// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) pub mod invite_user { - use ruma_identifiers::RoomId; + use ruma_identifiers::{UserId, RoomId}; /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { - pub user_id: String, + pub user_id: UserId, } /// Details about this API endpoint. diff --git a/src/r0/presence.rs b/src/r0/presence.rs index df206f42..ca07ec03 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -19,8 +19,8 @@ pub mod set_presence { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { #[serde(skip_serializing_if = "Option::is_none")] - status_msg: Option, - presence: PresenceState + pub status_msg: Option, + pub presence: PresenceState } impl ::Endpoint for Endpoint { diff --git a/src/r0/room.rs b/src/r0/room.rs index bd5f3c7c..4880d6f8 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -2,7 +2,7 @@ /// [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; + use ruma_identifiers::{RoomId, UserId}; /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -11,7 +11,7 @@ pub mod create_room { pub creation_content: Option, #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] - pub invite: Vec, + pub invite: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -21,7 +21,8 @@ pub mod create_room { #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub visibility: Option, + pub visibility: Option, // TODO: should be an enum ["public", "private"] + // TODO: missing `invite_3pid`, `initial_state` } /// Extra options to be added to the `m.room.create` event. diff --git a/src/r0/search.rs b/src/r0/search.rs index 3ed04688..f1ddf967 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -43,8 +43,9 @@ pub mod search_events { #[serde(skip_serializing_if = "Option::is_none")] pub include_state: Option, /// The keys to search for. Defaults to all keys. - #[serde(skip_serializing_if = "Option::is_none")] - pub keys: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub keys: Vec, /// The order in which to search for results. #[serde(skip_serializing_if = "Option::is_none")] pub order_by: Option, diff --git a/src/r0/session.rs b/src/r0/session.rs index 70ad2cc6..4ed5c41c 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -6,6 +6,8 @@ pub mod login { #[derive(Clone, Copy, Debug)] pub struct Endpoint; + // TODO: missing BodyParams + /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { From 1ca92148c5fd1d650a155a1fcca6f65c0c576b7b Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 2 Jan 2017 01:51:35 -0800 Subject: [PATCH 042/350] Move the supported versions API endpoint into an "unversioned" module. --- src/lib.rs | 3 +-- src/supported_versions.rs | 29 ----------------------------- src/unversioned.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 31 deletions(-) delete mode 100644 src/supported_versions.rs create mode 100644 src/unversioned.rs diff --git a/src/lib.rs b/src/lib.rs index 2ed8314c..b966b9ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,5 +43,4 @@ pub mod r0 { pub mod voip; } -/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) -pub mod supported_versions; +pub mod unversioned; diff --git a/src/supported_versions.rs b/src/supported_versions.rs deleted file mode 100644 index bfc24b6f..00000000 --- a/src/supported_versions.rs +++ /dev/null @@ -1,29 +0,0 @@ -/// Details about this API endpoint. -#[derive(Clone, Copy, Debug)] -pub struct Endpoint; - -/// This API endpoint's response. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Response { - /// A list of Matrix client API protocol versions supported by the homeserver. - pub versions: Vec, -} - -impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path() - } - - fn router_path() -> String { - "/_matrix/client/versions".to_string() - } -} diff --git a/src/unversioned.rs b/src/unversioned.rs new file mode 100644 index 00000000..a8bf5f14 --- /dev/null +++ b/src/unversioned.rs @@ -0,0 +1,34 @@ +//! Endpoints that cannot change with new versions of the Matrix specification. + +/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) +pub mod get_supported_versions { + /// Details about this API endpoint. + #[derive(Clone, Copy, Debug)] + pub struct Endpoint; + + /// This API endpoint's response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/versions".to_string() + } + } +} From 4acdf9018e30872552ee91745175e80d3474475f Mon Sep 17 00:00:00 2001 From: Antoine Proulx Date: Mon, 2 Jan 2017 10:19:59 -0500 Subject: [PATCH 043/350] Convert path parameters in docs from colon-snake-case to brace-lower-camel-case --- src/r0/alias.rs | 6 +++--- src/r0/config.rs | 4 ++-- src/r0/context.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 888e7130..de49cbaa 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -2,7 +2,7 @@ use ruma_identifiers::RoomAliasId; -/// [PUT /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) +/// [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) pub mod create_alias { use ruma_identifiers::RoomId; @@ -36,7 +36,7 @@ pub mod create_alias { } } -/// [DELETE /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) +/// [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) pub mod delete_alias { /// Details about this API endpoint. #[derive(Clone, Copy, Debug)] @@ -62,7 +62,7 @@ pub mod delete_alias { } } -/// [GET /_matrix/client/r0/directory/room/:room_alias](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) +/// [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) pub mod get_alias { use ruma_identifiers::RoomId; diff --git a/src/r0/config.rs b/src/r0/config.rs index 321e0cdd..7acec3fa 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1,6 +1,6 @@ //! Endpoints for client configuration. -/// [PUT /_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) +/// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) pub mod set_room_account_data { use ruma_identifiers::{RoomId, UserId}; @@ -41,7 +41,7 @@ pub mod set_room_account_data { } } -/// [PUT /_matrix/client/r0/user/:user_id/account_data/:type](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) +/// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) pub mod set_global_account_data { use ruma_identifiers::UserId; diff --git a/src/r0/context.rs b/src/r0/context.rs index 9d47f40e..0257c503 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -1,6 +1,6 @@ //! Endpoints for event context. -/// [GET /_matrix/client/r0/rooms/:room_id/context/:event_id](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) +/// [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) pub mod get_context { use ruma_identifiers::{EventId, RoomId}; use ruma_events::collections::only; From a7bce18b59fba5d5faa3e0621a7d885cc7c20071 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 4 Jan 2017 20:00:37 +0100 Subject: [PATCH 044/350] Update /register to most recent spec --- src/r0/account.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index fa31316d..72d6b5b7 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,15 +2,55 @@ /// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) pub mod register { + use ruma_identifiers::UserId; + /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + /// If true, the server binds the email used for authentication + /// to the Matrix ID with the ID Server. #[serde(skip_serializing_if = "Option::is_none")] pub bind_email: Option, - pub password: String, + /// The desired password for the account. + /// + /// Should only be empty for guest accounts. + // TODO: the spec says nothing about when it is actually required. + #[serde(skip_serializing_if = "Option::is_none")] + pub password: Option, + /// local part of the desired Matrix ID. + /// + /// If omitted, the homeserver MUST generate a Matrix ID local part. #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, - // TODO: `auth` field + /// ID of the client device. + /// + /// If this does not correspond to a known client device, a new device will be created. + /// The server will auto-generate a device_id if this is not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option, + /// Additional authentication information for the user-interactive authentication API. + /// + /// Note that this information is not used to define how the registered user should be + /// authenticated, but is instead used to authenticate the register call itself. + /// It should be left empty, or omitted, unless an earlier call returned an response + /// with status code 401. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option + } + + /// Additional authentication information for the user-interactive authentication API. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct AuthenticationData { + /// The login type that the client is attempting to complete. + #[serde(rename = "type")] + kind: String, + /// The value of the session key given by the homeserver. + session: Option } /// Details about this API endpoint. @@ -20,6 +60,9 @@ pub mod register { /// This API endpoint's query string parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { + /// Kind of account to register + /// + /// Defaults to `User` if ommited. #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, } @@ -27,8 +70,12 @@ pub mod register { /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] pub enum RegistrationKind { + /// A guest account + /// + /// These accounts may have limited permissions and may not be supported by all servers. #[serde(rename="guest")] Guest, + /// A regular user account #[serde(rename="user")] User, } @@ -36,10 +83,18 @@ pub mod register { /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + /// An access token for the account. + /// + /// This access token can then be used to authorize other requests. pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. pub home_server: String, - pub user_id: String, - // TODO: `refresh_token` field? (more or less deprecated?) + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, + /// ID of the registered device. + /// + /// Will be the same as the corresponding parameter in the request, if one was specified. + pub device_id: String } impl ::Endpoint for Endpoint { From 28598352aa88f6960f0887a0fb00f2d410638936 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 7 Jan 2017 05:28:17 -0800 Subject: [PATCH 045/350] Implement serialization for QueryParams. --- Cargo.toml | 8 ++++---- src/lib.rs | 1 - src/r0/media.rs | 4 ++-- src/r0/search.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 48a43f71..63792da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -ruma-api = "0.1.0" -ruma-events = "0.2.0" +ruma-api = "0.2.0" +ruma-events = "0.3.0" ruma-identifiers = "0.6.0" ruma-signatures = "0.1.0" -serde = "0.8.19" -serde_derive = "0.8.19" +serde = "0.8.21" +serde_derive = "0.8.21" serde_json = "0.8.4" diff --git a/src/lib.rs b/src/lib.rs index b966b9ff..c4aa85ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! shared by client and server code. -#![feature(proc_macro)] #![deny(missing_debug_implementations)] #![warn(missing_docs)] diff --git a/src/r0/media.rs b/src/r0/media.rs index efe68e69..b15e3925 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -82,7 +82,7 @@ pub mod get_content_thumbnail { pub struct Endpoint; /// The desired resizing method. - #[derive(Clone, Copy, Debug)] + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Method { /// Crop the original to produce the requested image dimensions. Crop, @@ -100,7 +100,7 @@ pub mod get_content_thumbnail { } /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { /// The *desired* height of the thumbnail. The actual thumbnail may not match the size /// specified. diff --git a/src/r0/search.rs b/src/r0/search.rs index f1ddf967..f5c14d29 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -141,7 +141,7 @@ pub mod search_events { } /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { /// The point to return events from. /// From 8ab3c737b8406843e2d2faa7e8441d9ef3574cac Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 7 Jan 2017 18:27:55 +0100 Subject: [PATCH 046/350] Update to ruma-api v0.3. Also fixes a few errors encountered in the process and remove depcrecated tokenrefresh endpoint. --- Cargo.toml | 2 +- src/r0/account.rs | 112 ++++++++++++++++++++++++++---- src/r0/alias.rs | 60 ++++++++++++++-- src/r0/config.rs | 40 +++++++++-- src/r0/contact.rs | 68 +++++++++++++++--- src/r0/context.rs | 20 +++++- src/r0/directory.rs | 22 +++++- src/r0/filter.rs | 42 +++++++++-- src/r0/media.rs | 65 +++++++++++++++-- src/r0/membership.rs | 162 ++++++++++++++++++++++++++++++++++++++----- src/r0/presence.rs | 81 +++++++++++++++++++--- src/r0/profile.rs | 100 +++++++++++++++++++++++--- src/r0/receipt.rs | 20 +++++- src/r0/redact.rs | 20 +++++- src/r0/room.rs | 22 +++++- src/r0/search.rs | 22 +++++- src/r0/send.rs | 64 ++++++++++++++--- src/r0/server.rs | 20 +++++- src/r0/session.rs | 116 ++++++++++++++++++------------- src/r0/sync.rs | 127 +++++++++++++++++++++++++++++---- src/r0/tag.rs | 60 ++++++++++++++-- src/r0/typing.rs | 22 +++++- src/r0/voip.rs | 22 +++++- src/unversioned.rs | 22 +++++- 24 files changed, 1128 insertions(+), 183 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63792da6..24ab361e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -ruma-api = "0.2.0" +ruma-api = "0.3.0" ruma-events = "0.3.0" ruma-identifiers = "0.6.0" ruma-signatures = "0.1.0" diff --git a/src/r0/account.rs b/src/r0/account.rs index 72d6b5b7..d532d62c 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -108,11 +108,27 @@ pub mod register { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/register".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/register" + } + + fn name() -> &'static str { + "register" + } + + fn description() -> &'static str { + "Register an account on this homeserver." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + true } } } @@ -120,6 +136,8 @@ pub mod register { /// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { // TODO: according to the spec, this does not has any params + // probably the spec's fault, as this would not make any sense. + // But the BodyParams here are probably wrong /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { @@ -145,11 +163,27 @@ pub mod request_password_change_token { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/password/email/requestToken".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/password/email/requestToken" + } + + fn name() -> &'static str { + "request_password_change_token" + } + + fn description() -> &'static str { + "Request that a password change token is sent to the given email address." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } @@ -173,11 +207,27 @@ pub mod deactivate { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/deactivate".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/deactivate" + } + + fn name() -> &'static str { + "deactivate" + } + + fn description() -> &'static str { + "Deactivate the current user's account." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -206,11 +256,27 @@ pub mod change_password { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/password".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/password" + } + + fn name() -> &'static str { + "change_password" + } + + fn description() -> &'static str { + "Change the password of the current user's account." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -242,11 +308,27 @@ pub mod request_register_token { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/register/email/requestToken".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/register/email/requestToken" + } + + fn name() -> &'static str { + "request_register_token" + } + + fn description() -> &'static str { + "Request a register token with a 3rd party email." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } diff --git a/src/r0/alias.rs b/src/r0/alias.rs index de49cbaa..64ceba75 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -30,8 +30,24 @@ pub mod create_alias { format!("/_matrix/client/r0/directory/room/{}", params.room_alias) } - fn router_path() -> String { - "/_matrix/client/r0/directory/room/:room_alias".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/directory/room/:room_alias" + } + + fn name() -> &'static str { + "create_alias" + } + + fn description() -> &'static str { + "Add an alias to a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -56,8 +72,24 @@ pub mod delete_alias { format!("/_matrix/client/r0/directory/room/{}", params.room_alias) } - fn router_path() -> String { - "/_matrix/client/r0/directory/room/:room_alias".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/directory/room/:room_alias" + } + + fn name() -> &'static str { + "delete_alias" + } + + fn description() -> &'static str { + "Remove an alias from a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -91,8 +123,24 @@ pub mod get_alias { format!("/_matrix/client/r0/directory/room/{}", params.room_alias) } - fn router_path() -> String { - "/_matrix/client/r0/directory/room/:room_alias".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/directory/room/:room_alias" + } + + fn name() -> &'static str { + "get_alias" + } + + fn description() -> &'static str { + "Resolve a room alias to a room ID." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/config.rs b/src/r0/config.rs index 7acec3fa..1b9147da 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -35,8 +35,24 @@ pub mod set_room_account_data { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type" + } + + fn name() -> &'static str { + "set_room_account_data" + } + + fn description() -> &'static str { + "Associate account data with a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -74,8 +90,24 @@ pub mod set_global_account_data { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/account_data/:type".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/account_data/:type" + } + + fn name() -> &'static str { + "set_global_account_data" + } + + fn description() -> &'static str { + "Sets global account data." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 571d3bb3..e2878e7d 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -33,11 +33,27 @@ pub mod create_contact { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/3pid".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/3pid" + } + + fn name() -> &'static str { + "create_contact" + } + + fn description() -> &'static str { + "Adds contact information to the user's account." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -79,18 +95,33 @@ pub mod get_contacts { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/3pid/email/requestToken".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/3pid/email/requestToken" + } + + fn name() -> &'static str { + "get_contacts" + } + + fn description() -> &'static str { + "Get a list of 3rd party contacts associated with the user's account." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } /// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { - // TODO: according to the spec this takes no parameters /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { @@ -116,11 +147,28 @@ pub mod request_contact_verification_token { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/account/3pid/email/requestToken".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/account/3pid/email/requestToken" + } + + fn name() -> &'static str { + "request_contact_verification_token" + } + + fn description() -> &'static str { + "Ask for a verification token for a given 3rd party ID." + } + + fn requires_authentication() -> bool { + // Not sure why this don't require auth? + false + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/context.rs b/src/r0/context.rs index 0257c503..7eebca4f 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -48,8 +48,24 @@ pub mod get_context { format!("/_matrix/client/r0/rooms/{}/context/{}", params.room_id, params.event_id) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/context/:event_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/context/:event_id" + } + + fn name() -> &'static str { + "get_context" + } + + fn description() -> &'static str { + "Get the events immediately preceding and following a given event." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/directory.rs b/src/r0/directory.rs index bc8288f8..cd7aa498 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -43,11 +43,27 @@ pub mod get_public_rooms { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/publicRooms".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/publicRooms" + } + + fn name() -> &'static str { + "get_public_rooms" + } + + fn description() -> &'static str { + "Get the list of rooms in this homeserver's public directory." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 536d6ec1..dac73e7e 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -132,8 +132,24 @@ pub mod create_filter { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/filter".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/filter" + } + + fn name() -> &'static str { + "create_filter" + } + + fn description() -> &'static str { + "Create a new filter for event retrieval." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -172,8 +188,26 @@ pub mod get_filter { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/filter/:filter_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/filter/:filter_id" + } + + fn name() -> &'static str { + "get_filter" + } + + fn description() -> &'static str { + "Retrieve a previously created filter." + } + + fn requires_authentication() -> bool { + // TODO: not sure why, as I guess you should not be able to retrieve + // other users filters? + false + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/media.rs b/src/r0/media.rs index b15e3925..7978bd0e 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -34,8 +34,24 @@ pub mod get_content { ) } - fn router_path() -> String { - "/_matrix/media/r0/download/:server_name/:media_id".to_string() + fn router_path() -> &'static str { + "/_matrix/media/r0/download/:server_name/:media_id" + } + + fn name() -> &'static str { + "get_media_content" + } + + fn description() -> &'static str { + "Retrieve content from the media store." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } @@ -64,11 +80,28 @@ pub mod create_content { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/media/r0/upload".to_string() + fn router_path() -> &'static str { + "/_matrix/media/r0/upload" + } + + fn name() -> &'static str { + "create_media_content" + } + + fn description() -> &'static str { + "Upload content to the media store." + } + + fn requires_authentication() -> bool { + // TODO: How comes this does not require authentication? + false + } + + fn rate_limited() -> bool { + false } } } @@ -85,8 +118,10 @@ pub mod get_content_thumbnail { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Method { /// Crop the original to produce the requested image dimensions. + #[serde(rename = "crop")] Crop, /// Maintain the original aspect ratio of the source image. + #[serde(rename = "scale")] Scale, } @@ -130,8 +165,24 @@ pub mod get_content_thumbnail { ) } - fn router_path() -> String { - "/_matrix/media/r0/thumbnail/:server_name/:media_id".to_string() + fn router_path() -> &'static str { + "/_matrix/media/r0/thumbnail/:server_name/:media_id" + } + + fn name() -> &'static str { + "get_content_thumbnail" + } + + fn description() -> &'static str { + "Get a thumbnail of content from the media store." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } diff --git a/src/r0/membership.rs b/src/r0/membership.rs index f5e2fe63..540b96f3 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -22,7 +22,7 @@ pub struct ThirdPartySigned { pub mod invite_user { use ruma_identifiers::{UserId, RoomId}; - /// The request type. + /// The request body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub user_id: UserId, @@ -55,8 +55,24 @@ pub mod invite_user { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/invite".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/invite" + } + + fn name() -> &'static str { + "invite_user" + } + + fn description() -> &'static str { + "Invite a user to a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -116,8 +132,24 @@ pub mod join_room_by_id_or_alias { } } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id_or_alias/join".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/join/:room_id_or_alias" + } + + fn name() -> &'static str { + "join_room_by_id_or_alias" + } + + fn description() -> &'static str { + "Join a room using its ID or one of its aliases." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -167,8 +199,24 @@ pub mod join_room_by_id { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/join".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/join" + } + + fn name() -> &'static str { + "join_room_by_id" + } + + fn description() -> &'static str { + "Join a room using its ID." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -204,8 +252,24 @@ pub mod forget_room { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/forget".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/forget" + } + + fn name() -> &'static str { + "forget_room" + } + + fn description() -> &'static str { + "Forget a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -241,8 +305,24 @@ pub mod leave_room { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/leave".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/leave" + } + + fn name() -> &'static str { + "leave_room" + } + + fn description() -> &'static str { + "Leave a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -286,8 +366,24 @@ pub mod kick_user { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/kick".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/kick" + } + + fn name() -> &'static str { + "kick_user" + } + + fn description() -> &'static str { + "Kick a user from a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -329,8 +425,24 @@ pub mod unban_user { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/unban".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/unban" + } + + fn name() -> &'static str { + "unban_user" + } + + fn description() -> &'static str { + "unban a user from a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -374,8 +486,24 @@ pub mod ban_user { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/ban".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/ban" + } + + fn name() -> &'static str { + "ban_user" + } + + fn description() -> &'static str { + "Ban a user from a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/presence.rs b/src/r0/presence.rs index ca07ec03..cc6ed8e4 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -40,8 +40,24 @@ pub mod set_presence { ) } - fn router_path() -> String { - "/_matrix/client/r0/presence/:user_id/status".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/presence/:user_id/status" + } + + fn name() -> &'static str { + "set_presence" + } + + fn description() -> &'static str { + "Set presence status for this user." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -90,8 +106,24 @@ pub mod get_presence { ) } - fn router_path() -> String { - "/_matrix/client/r0/presence/:user_id/status".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/presence/:user_id/status" + } + + fn name() -> &'static str { + "get_presence" + } + + fn description() -> &'static str { + "Get presence status for this user." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } @@ -138,8 +170,24 @@ pub mod update_presence_subscriptions { ) } - fn router_path() -> String { - "/_matrix/client/r0/presence/list/:user_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/presence/list/:user_id" + } + + fn name() -> &'static str { + "update_presence_subscriptions" + } + + fn description() -> &'static str { + "Update the presence subscriptions of the user." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -176,8 +224,25 @@ pub mod get_subscribed_presences { ) } - fn router_path() -> String { - "/_matrix/client/r0/presence/list/:user_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/presence/list/:user_id" + } + + fn name() -> &'static str { + "get_subscribed_presences" + } + + fn description() -> &'static str { + "Get the precence status from the user's subscriptions." + } + + fn requires_authentication() -> bool { + // TODO: not sure why this does not require authentication + false + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/profile.rs b/src/r0/profile.rs index db4cf0d1..a5aaff7d 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -38,8 +38,24 @@ pub mod get_display_name { ) } - fn router_path() -> String { - "/_matrix/client/r0/profile/:user_id/displayname".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/profile/:user_id/displayname" + } + + fn name() -> &'static str { + "get_display_name" + } + + fn description() -> &'static str { + "Get the display name of a user." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } @@ -83,8 +99,24 @@ pub mod set_display_name { ) } - fn router_path() -> String { - "/_matrix/client/r0/profile/:user_id/displayname".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/profile/:user_id/displayname" + } + + fn name() -> &'static str { + "set_display_name" + } + + fn description() -> &'static str { + "Set the display name of the user." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -127,8 +159,24 @@ pub mod get_avatar_url { ) } - fn router_path() -> String { - "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/profile/:user_id/avatar_url" + } + + fn name() -> &'static str { + "get_avatar_url" + } + + fn description() -> &'static str { + "Get the avatar URL of a user." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } @@ -171,8 +219,24 @@ pub mod set_avatar_url { ) } - fn router_path() -> String { - "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/profile/:user_id/avatar_url" + } + + fn name() -> &'static str { + "set_avatar_url" + } + + fn description() -> &'static str { + "Set the avatar URL of the user." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } @@ -217,8 +281,24 @@ pub mod get_profile { ) } - fn router_path() -> String { - "/_matrix/client/r0/profile/:user_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/profile/:user_id" + } + + fn name() -> &'static str { + "get_profile" + } + + fn description() -> &'static str { + "Get all profile information of an user." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index 63e6a623..f5bf20e2 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -51,8 +51,24 @@ pub mod create_receipt { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id" + } + + fn name() -> &'static str { + "create_receipt" + } + + fn description() -> &'static str { + "Send a receipt event to a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } diff --git a/src/r0/redact.rs b/src/r0/redact.rs index b1847f19..6e0de442 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -49,8 +49,24 @@ pub mod redact_event { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id" + } + + fn name() -> &'static str { + "redact_event" + } + + fn description() -> &'static str { + "Redact an event, stripping all information not critical to the event graph integrity." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/room.rs b/src/r0/room.rs index 4880d6f8..38f2f62d 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -68,11 +68,27 @@ pub mod create_room { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/createRoom".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 } } } diff --git a/src/r0/search.rs b/src/r0/search.rs index f5c14d29..c10d2919 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -222,11 +222,27 @@ pub mod search_events { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/search".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 } } } diff --git a/src/r0/send.rs b/src/r0/send.rs index 649ce531..7c7ac4dc 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -1,7 +1,7 @@ //! Endpoints for sending events. /// [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 { +pub mod send_state_event_for_empty_key { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -41,14 +41,30 @@ pub mod send_state_event { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + 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_by_state_key { +pub mod send_state_event_for_key { use ruma_identifiers::{RoomId, EventId}; use ruma_events::EventType; @@ -90,8 +106,24 @@ pub mod send_state_event_by_state_key { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + 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 } } } @@ -139,8 +171,24 @@ pub mod send_message_event { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id".to_string() + 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 } } } diff --git a/src/r0/server.rs b/src/r0/server.rs index 3abcd4cc..1e5a64ac 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -68,8 +68,24 @@ pub mod get_user_info { ) } - fn router_path() -> String { - "/_matrix/client/r0/admin/whois/:user_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/admin/whois/:user_id" + } + + fn name() -> &'static str { + "get_user_info" + } + + fn description() -> &'static str { + "Get information about a particular user." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/session.rs b/src/r0/session.rs index 4ed5c41c..7f67babb 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -6,7 +6,37 @@ pub mod login { #[derive(Clone, Copy, Debug)] pub struct Endpoint; - // TODO: missing BodyParams + /// Possible login mediums for 3rd party ID + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum LoginMedium { + #[serde(rename = "email")] + Email + } + + /// 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 { + /// Password of the user + pub password: String, + /// Medium of 3rd party login to use + #[serde(skip_serializing_if = "Option::is_none")] + pub medium: Option, + /// Type of login to do + #[serde(rename = "type")] + pub kind: LoginKind, + /// Localpart or full matrix user id of the user + pub user: String, + /// 3rd party identifier for the user + #[serde(skip_serializing_if = "Option::is_none")] + pub address: Option + } /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -29,11 +59,27 @@ pub mod login { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/login".to_string() + 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 } } } @@ -55,51 +101,27 @@ pub mod logout { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/r0/logout".to_string() - } - } -} - -/// [POST /_matrix/client/r0/tokenrefresh](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-tokenrefresh) -pub mod refresh_access_token { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub refresh_token: String, - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub access_token: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, - } - - 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() - } - - fn router_path() -> String { - "/_matrix/client/r0/tokenrefresh".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 } } } diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 951a7217..1408ca42 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -32,14 +32,30 @@ pub mod get_state_events { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state".to_string() + 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 } } } /// [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_event_by_event_type { +pub mod get_state_events_for_empty_key { use ruma_identifiers::RoomId; /// Details about this API endpoint. @@ -71,14 +87,30 @@ pub mod get_state_event_by_event_type { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + 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 } } } /// [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_event_by_state_key { +pub mod get_state_events_for_key { use ruma_identifiers::RoomId; /// Details about this API endpoint. @@ -112,8 +144,24 @@ pub mod get_state_event_by_state_key { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + 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 } } } @@ -156,8 +204,27 @@ pub mod get_member_events { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/members".to_string() + 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 { + // 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 } } } @@ -222,8 +289,24 @@ pub mod get_message_events { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/messages".to_string() + 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 } } } @@ -370,8 +453,24 @@ pub mod sync_events { "/_matrix/client/r0/sync".to_string() } - fn router_path() -> 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 } } } diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 4b067e79..57754917 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -36,8 +36,24 @@ pub mod create_tag { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" + } + + fn name() -> &'static str { + "create_tag" + } + + fn description() -> &'static str { + "Add a new tag to a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -82,8 +98,24 @@ pub mod get_tags { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags" + } + + fn name() -> &'static str { + "get_tags" + } + + fn description() -> &'static str { + "Get the tags associated with a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } @@ -123,8 +155,24 @@ pub mod delete_tag { ) } - fn router_path() -> String { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" + } + + fn name() -> &'static str { + "delete_tag" + } + + fn description() -> &'static str { + "Remove a tag from a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + false } } } diff --git a/src/r0/typing.rs b/src/r0/typing.rs index bf2afc6d..aab5d3e9 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -1,7 +1,7 @@ //! Endpoints for typing notifications. /// [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) -pub mod start_or_stop_typing { +pub mod create_typing_event { use ruma_identifiers::{UserId, RoomId}; /// Details about this API endpoint. @@ -41,8 +41,24 @@ pub mod start_or_stop_typing { ) } - fn router_path() -> String { - "/_matrix/client/r0/rooms/:room_id/invite/:user_id".to_string() + fn router_path() -> &'static str { + "/_matrix/client/r0/rooms/:room_id/typing/:user_id" + } + + fn name() -> &'static str { + "create_typing_event" + } + + fn description() -> &'static str { + "Send a typing event to a room." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 4df3f482..acb85720 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -26,11 +26,27 @@ pub mod get_turn_server_info { } fn request_path(_params: Self::PathParams) -> String { - "/_matrix/client/r0/voip/turnServer".to_string() + Self::router_path().to_string() } - fn router_path() -> String { - "_matrix/client/r0/voip/turnServer".to_string() + fn router_path() -> &'static str { + "_matrix/client/r0/voip/turnServer" + } + + fn name() -> &'static str { + "turn_server_info" + } + + fn description() -> &'static str { + "Get credentials for the client to use when initiating VoIP calls." + } + + fn requires_authentication() -> bool { + true + } + + fn rate_limited() -> bool { + true } } } diff --git a/src/unversioned.rs b/src/unversioned.rs index a8bf5f14..acc56711 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -24,11 +24,27 @@ pub mod get_supported_versions { } fn request_path(_params: Self::PathParams) -> String { - Self::router_path() + Self::router_path().to_string() } - fn router_path() -> String { - "/_matrix/client/versions".to_string() + fn router_path() -> &'static str { + "/_matrix/client/versions" + } + + fn name() -> &'static str { + "api_version" + } + + fn description() -> &'static str { + "Get the versions of the client-server API supported by this homeserver." + } + + fn requires_authentication() -> bool { + false + } + + fn rate_limited() -> bool { + false } } } From 3da855c56ecbeaea8a717d6fdacf49817255d3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Br=C3=B6nnimann?= Date: Sun, 15 Jan 2017 16:05:40 +0100 Subject: [PATCH 047/350] The member event response contains the field chunk, not chunks --- src/r0/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 1408ca42..16a5e925 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -184,7 +184,7 @@ pub mod get_member_events { /// This API endpoint's reponse. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { - pub chunks: Vec + pub chunk: Vec } impl ::Endpoint for Endpoint { @@ -268,7 +268,7 @@ pub mod get_message_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub start: String, - pub chunks: Vec, + pub chunk: Vec, pub end: String } From d28912a14844b58bb42b4a2792649b3fc3e199d4 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 May 2017 23:34:32 -0700 Subject: [PATCH 048/350] WIP --- Cargo.toml | 20 +++++++---- src/lib.rs | 62 +++++++++++++++++---------------- src/unversioned.rs | 86 +++++++++++++++++++++++++++------------------- 3 files changed, 97 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 24ab361e..2e676bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,16 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -ruma-api = "0.3.0" -ruma-events = "0.3.0" -ruma-identifiers = "0.6.0" -ruma-signatures = "0.1.0" -serde = "0.8.21" -serde_derive = "0.8.21" -serde_json = "0.8.4" +ruma-events = "0.8.0" +ruma-identifiers = "0.11.0" +ruma-signatures = "0.3.0" +serde = "1.0.2" +serde_derive = "1.0.2" +serde_json = "1.0.1" + +[dependencies.hyper] +git = "https://github.com/hyperium/hyper" +rev = "fed04dfb58e19b408322d4e5ca7474871e848a35" + +[dependencies.ruma-api] +git = "https://github.com/ruma/ruma-api" diff --git a/src/lib.rs b/src/lib.rs index c4aa85ba..93bcdb35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,43 +3,47 @@ //! shared by client and server code. #![deny(missing_debug_implementations)] +#![feature(associated_consts, try_from)] #![warn(missing_docs)] +extern crate hyper; extern crate ruma_api; extern crate ruma_events; extern crate ruma_identifiers; extern crate ruma_signatures; extern crate serde; -#[macro_use] extern crate serde_derive; extern crate serde_json; -pub use ruma_api::{Endpoint, Method}; - -/// Endpoints for the r0.x.x versions of the client API specification. -pub mod r0 { - pub mod account; - pub mod alias; - pub mod config; - pub mod contact; - pub mod context; - pub mod directory; - pub mod filter; - pub mod media; - pub mod membership; - pub mod presence; - pub mod profile; - pub mod push; - pub mod receipt; - pub mod redact; - pub mod room; - pub mod search; - pub mod send; - pub mod server; - pub mod session; - pub mod sync; - pub mod tag; - pub mod typing; - pub mod voip; -} +// /// Endpoints for the r0.x.x versions of the client API specification. +// pub mod r0 { +// pub mod account; +// pub mod alias; +// pub mod config; +// pub mod contact; +// pub mod context; +// pub mod directory; +// pub mod filter; +// pub mod media; +// pub mod membership; +// pub mod presence; +// pub mod profile; +// pub mod push; +// pub mod receipt; +// pub mod redact; +// pub mod room; +// pub mod search; +// pub mod send; +// pub mod server; +// pub mod session; +// pub mod sync; +// pub mod tag; +// pub mod typing; +// pub mod voip; +// } pub mod unversioned; + +/// An error when converting an endpoint's request into a `hyper::Request` or converting a +/// `hyper::Response` into an endpoint's response. +#[derive(Debug)] +pub struct Error; diff --git a/src/unversioned.rs b/src/unversioned.rs index acc56711..d08cb253 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -2,49 +2,65 @@ /// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) pub mod get_supported_versions { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] + use std::convert::TryFrom; + + use hyper::{Method, Request as HyperRequest, Response as HyperResponse, StatusCode}; + use ruma_api::{Endpoint as ApiEndpoint, Metadata}; + + use Error; + + /// Endpoint + #[derive(Debug)] pub struct Endpoint; - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] + impl ApiEndpoint for Endpoint { + type Request = Request; + type Response = Response; + + const METADATA: Metadata = Metadata { + description: "Get the versions of the client-server API supported by this homeserver.", + method: Method::Get, + name: "api_versions", + path: "/_matrix/client/versions", + rate_limited: false, + requires_authentication: true, + }; + } + + /// Request + #[derive(Debug, Clone)] + pub struct Request; + + impl TryFrom for HyperRequest { + type Error = Error; + fn try_from(_request: Request) -> Result { + let metadata = Endpoint::METADATA; + + let hyper_request = HyperRequest::new( + metadata.method, + metadata.path.parse().map_err(|_| Error)?, + ); + + Ok(hyper_request) + } + } + + /// Response + #[derive(Debug, Clone)] pub struct Response { /// A list of Matrix client API protocol versions supported by the homeserver. pub versions: Vec, } - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; + impl TryFrom for Response { + type Error = Error; - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } - - fn router_path() -> &'static str { - "/_matrix/client/versions" - } - - fn name() -> &'static str { - "api_version" - } - - fn description() -> &'static str { - "Get the versions of the client-server API supported by this homeserver." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + fn try_from(hyper_response: HyperResponse) -> Result { + if hyper_response.status() == StatusCode::Ok { + Ok(Response { versions: vec![] }) + } else { + Err(Error) + } } } } From 30fbb891fd83f2291e0f9dcbce6bac6b72f0b3cf Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 14 May 2017 04:19:34 -0700 Subject: [PATCH 049/350] Use ruma-api-macros for the versions endpoint. --- Cargo.toml | 6 +++++ src/lib.rs | 10 ++++----- src/unversioned.rs | 56 ++++++---------------------------------------- 3 files changed, 17 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e676bb9..b973058a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] +futures = "0.1.13" ruma-events = "0.8.0" ruma-identifiers = "0.11.0" ruma-signatures = "0.3.0" @@ -24,3 +25,8 @@ rev = "fed04dfb58e19b408322d4e5ca7474871e848a35" [dependencies.ruma-api] git = "https://github.com/ruma/ruma-api" +rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" + +[dependencies.ruma-api-macros] +git = "https://github.com/ruma/ruma-api-macros" +rev = "10f4647037c81cc3c35097f6156dd9706d38964a" diff --git a/src/lib.rs b/src/lib.rs index 93bcdb35..3bbac1ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,16 +3,19 @@ //! shared by client and server code. #![deny(missing_debug_implementations)] -#![feature(associated_consts, try_from)] +#![feature(associated_consts, proc_macro, try_from)] #![warn(missing_docs)] +extern crate futures; extern crate hyper; extern crate ruma_api; +extern crate ruma_api_macros; extern crate ruma_events; extern crate ruma_identifiers; extern crate ruma_signatures; extern crate serde; extern crate serde_json; +#[macro_use] extern crate serde_derive; // /// Endpoints for the r0.x.x versions of the client API specification. // pub mod r0 { @@ -42,8 +45,3 @@ extern crate serde_json; // } pub mod unversioned; - -/// An error when converting an endpoint's request into a `hyper::Request` or converting a -/// `hyper::Response` into an endpoint's response. -#[derive(Debug)] -pub struct Error; diff --git a/src/unversioned.rs b/src/unversioned.rs index d08cb253..0c1dc831 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -2,65 +2,23 @@ /// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) pub mod get_supported_versions { - use std::convert::TryFrom; + use ruma_api_macros::ruma_api; - use hyper::{Method, Request as HyperRequest, Response as HyperResponse, StatusCode}; - use ruma_api::{Endpoint as ApiEndpoint, Metadata}; - - use Error; - - /// Endpoint - #[derive(Debug)] - pub struct Endpoint; - - impl ApiEndpoint for Endpoint { - type Request = Request; - type Response = Response; - - const METADATA: Metadata = Metadata { + ruma_api! { + metadata { description: "Get the versions of the client-server API supported by this homeserver.", method: Method::Get, name: "api_versions", path: "/_matrix/client/versions", rate_limited: false, requires_authentication: true, - }; - } - - /// Request - #[derive(Debug, Clone)] - pub struct Request; - - impl TryFrom for HyperRequest { - type Error = Error; - fn try_from(_request: Request) -> Result { - let metadata = Endpoint::METADATA; - - let hyper_request = HyperRequest::new( - metadata.method, - metadata.path.parse().map_err(|_| Error)?, - ); - - Ok(hyper_request) } - } - /// Response - #[derive(Debug, Clone)] - pub struct Response { - /// A list of Matrix client API protocol versions supported by the homeserver. - pub versions: Vec, - } + request {} - impl TryFrom for Response { - type Error = Error; - - fn try_from(hyper_response: HyperResponse) -> Result { - if hyper_response.status() == StatusCode::Ok { - Ok(Response { versions: vec![] }) - } else { - Err(Error) - } + response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, } } } From 422043cf51080ffd2a0873594805c0baef795009 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 14 May 2017 17:58:15 -0700 Subject: [PATCH 050/350] Use ruma-api-macros for the account endpoints. --- Cargo.toml | 2 +- src/lib.rs | 8 +- src/r0/account.rs | 397 ++++++++++++++++------------------------------ 3 files changed, 139 insertions(+), 268 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b973058a..8077931a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "10f4647037c81cc3c35097f6156dd9706d38964a" +rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332" diff --git a/src/lib.rs b/src/lib.rs index 3bbac1ce..7b63fad1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,9 +17,9 @@ extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; -// /// Endpoints for the r0.x.x versions of the client API specification. -// pub mod r0 { -// pub mod account; +/// Endpoints for the r0.x.x versions of the client API specification. +pub mod r0 { + pub mod account; // pub mod alias; // pub mod config; // pub mod contact; @@ -42,6 +42,6 @@ extern crate serde_json; // pub mod tag; // pub mod typing; // pub mod voip; -// } +} pub mod unversioned; diff --git a/src/r0/account.rs b/src/r0/account.rs index d532d62c..7daac47b 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,45 +2,76 @@ /// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) pub mod register { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - /// If true, the server binds the email used for authentication - /// to the Matrix ID with the ID Server. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind_email: Option, - /// The desired password for the account. - /// - /// Should only be empty for guest accounts. - // TODO: the spec says nothing about when it is actually required. - #[serde(skip_serializing_if = "Option::is_none")] - pub password: Option, - /// local part of the desired Matrix ID. - /// - /// If omitted, the homeserver MUST generate a Matrix ID local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub username: Option, - /// ID of the client device. - /// - /// If this does not correspond to a known client device, a new device will be created. - /// The server will auto-generate a device_id if this is not specified. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option, - /// Additional authentication information for the user-interactive authentication API. - /// - /// Note that this information is not used to define how the registered user should be - /// authenticated, but is instead used to authenticate the register call itself. - /// It should be left empty, or omitted, unless an earlier call returned an response - /// with status code 401. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option + ruma_api! { + metadata { + description: "Register an account on this homeserver.", + method: Method::Post, + name: "register", + path: "/_matrix/client/r0/register", + rate_limited: true, + requires_authentication: false, + } + + request { + /// If true, the server binds the email used for authentication + /// to the Matrix ID with the ID Server. + #[serde(skip_serializing_if = "Option::is_none")] + pub bind_email: Option, + /// The desired password for the account. + /// + /// Should only be empty for guest accounts. + // TODO: the spec says nothing about when it is actually required. + #[serde(skip_serializing_if = "Option::is_none")] + pub password: Option, + /// local part of the desired Matrix ID. + /// + /// If omitted, the homeserver MUST generate a Matrix ID local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub username: Option, + /// ID of the client device. + /// + /// If this does not correspond to a known client device, a new device will be created. + /// The server will auto-generate a device_id if this is not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option, + /// Additional authentication information for the user-interactive authentication API. + /// + /// Note that this information is not used to define how the registered user should be + /// authenticated, but is instead used to authenticate the register call itself. + /// It should be left empty, or omitted, unless an earlier call returned an response + /// with status code 401. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, + /// Kind of account to register + /// + /// Defaults to `User` if ommited. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub kind: Option, + } + + response { + /// An access token for the account. + /// + /// This access token can then be used to authorize other requests. + pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. + pub home_server: String, + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, + /// ID of the registered device. + /// + /// Will be the same as the corresponding parameter in the request, if one was specified. + pub device_id: String, + } } /// Additional authentication information for the user-interactive authentication API. @@ -53,20 +84,6 @@ pub mod register { session: Option } - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's query string parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct QueryParams { - /// Kind of account to register - /// - /// Defaults to `User` if ommited. - #[serde(skip_serializing_if = "Option::is_none")] - pub kind: Option, - } - /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] pub enum RegistrationKind { @@ -79,256 +96,110 @@ pub mod register { #[serde(rename="user")] User, } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - /// An access token for the account. - /// - /// This access token can then be used to authorize other requests. - pub access_token: String, - /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, - /// ID of the registered device. - /// - /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = 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/register" - } - - fn name() -> &'static str { - "register" - } - - fn description() -> &'static str { - "Register an account on this homeserver." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - true - } - } } /// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { - // TODO: according to the spec, this does not has any params - // probably the spec's fault, as this would not make any sense. - // But the BodyParams here are probably wrong - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub client_secret: String, - pub email: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - pub send_attempt: u64, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Request that a password change token is sent to the given email address.", + method: Method::Post, + name: "request_password_change_token", + path: "/_matrix/client/r0/account/password/email/requestToken", + rate_limited: false, + requires_authentication: false, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// TODO: This parameter is not documented in the spec. + pub client_secret: String, + /// TODO: This parameter is not documented in the spec. + pub email: String, + /// TODO: This parameter is not documented in the spec. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// TODO: This parameter is not documented in the spec. + pub send_attempt: u64, } - fn router_path() -> &'static str { - "/_matrix/client/r0/account/password/email/requestToken" - } - - fn name() -> &'static str { - "request_password_change_token" - } - - fn description() -> &'static str { - "Request that a password change token is sent to the given email address." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) pub mod deactivate { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + // TODO: missing request parameters - // TODO: missing BodyParams + use ruma_api_macros::ruma_api; - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Deactivate the current user's account.", + method: Method::Post, + name: "deactivate", + path: "/_matrix/client/r0/account/deactivate", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } + request {} - fn router_path() -> &'static str { - "/_matrix/client/r0/account/deactivate" - } - - fn name() -> &'static str { - "deactivate" - } - - fn description() -> &'static str { - "Deactivate the current user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) pub mod change_password { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub new_password: String, - // TODO: missing `auth` field - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Change the password of the current user's account.", + method: Method::Post, + name: "change_password", + path: "/_matrix/client/r0/account/password", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// The new password for the account. + pub new_password: String, + // TODO: missing `auth` field } - fn router_path() -> &'static str { - "/_matrix/client/r0/account/password" - } - - fn name() -> &'static str { - "change_password" - } - - fn description() -> &'static str { - "Change the password of the current user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) pub mod request_register_token { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub client_secret: String, - pub email: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - pub send_attempt: u64, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Request a register token with a 3rd party email.", + method: Method::Post, + name: "request_register_token", + path: "/_matrix/client/r0/register/email/requestToken", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: u64, } - fn router_path() -> &'static str { - "/_matrix/client/r0/register/email/requestToken" - } - - fn name() -> &'static str { - "request_register_token" - } - - fn description() -> &'static str { - "Request a register token with a 3rd party email." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } From 11985ed3371cbf7f2166ecb8238b101ad933beef Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 04:51:31 -0700 Subject: [PATCH 051/350] Use ruma-api-macros for the alias endpoints. --- src/lib.rs | 2 +- src/r0/alias.rs | 171 +++++++++++++++--------------------------------- 2 files changed, 52 insertions(+), 121 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7b63fad1..d2991b93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ extern crate serde_json; /// Endpoints for the r0.x.x versions of the client API specification. pub mod r0 { pub mod account; -// pub mod alias; + pub mod alias; // pub mod config; // pub mod contact; // pub mod context; diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 64ceba75..66d86f59 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -1,152 +1,83 @@ //! Endpoints for room aliases. -use ruma_identifiers::RoomAliasId; - /// [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) pub mod create_alias { - use ruma_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomAliasId, RoomId}; - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub room_id: RoomId, - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = super::PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Add an alias to a room.", + method: Method::Put, + name: "create_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + request { + /// The room alias to set. + #[ruma_api(path)] + pub room_alias: RoomAliasId, + /// The room ID to set. + pub room_id: RoomId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/directory/room/:room_alias" - } - - fn name() -> &'static str { - "create_alias" - } - - fn description() -> &'static str { - "Add an alias to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) pub mod delete_alias { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; + use ruma_identifiers::RoomAliasId; - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = super::PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Delete + ruma_api! { + metadata { + description: "Remove an alias from a room.", + method: Method::Delete, + name: "delete_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + request { + /// The room alias to remove. + #[ruma_api(path)] + pub room_alias: RoomAliasId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/directory/room/:room_alias" - } - - fn name() -> &'static str { - "delete_alias" - } - - fn description() -> &'static str { - "Remove an alias from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) pub mod get_alias { - use ruma_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomAliasId, RoomId}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub room_id: RoomId, - pub servers: Vec, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = super::PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Resolve a room alias to a room ID.", + method: Method::Get, + name: "get_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!("/_matrix/client/r0/directory/room/{}", params.room_alias) + request { + /// The room alias. + #[ruma_api(path)] + pub room_alias: RoomAliasId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/directory/room/:room_alias" - } - - fn name() -> &'static str { - "get_alias" - } - - fn description() -> &'static str { - "Resolve a room alias to a room ID." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// The room ID for this room alias. + pub room_id: RoomId, + /// A list of servers that are aware of this room ID. + pub servers: Vec, } } } - -/// These API endpoints' path parameters. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct PathParams { - pub room_alias: RoomAliasId, -} From 088aed514ecbf0a25ae916710b1f3b49031170dd Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 06:02:28 -0700 Subject: [PATCH 052/350] Use ruma-api-macros for the config endpoints. --- Cargo.toml | 2 +- src/lib.rs | 2 +- src/r0/config.rs | 145 ++++++++++++++++++----------------------------- 3 files changed, 57 insertions(+), 92 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8077931a..8b6af2fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332" +rev = "58fab938b00d01aeb5e3e8c31731b4e479d5553d" diff --git a/src/lib.rs b/src/lib.rs index d2991b93..c1109550 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ extern crate serde_json; pub mod r0 { pub mod account; pub mod alias; -// pub mod config; + pub mod config; // pub mod contact; // pub mod context; // pub mod directory; diff --git a/src/r0/config.rs b/src/r0/config.rs index 1b9147da..90b467f0 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -2,112 +2,77 @@ /// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) pub mod set_room_account_data { + use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_json::Value; - /// 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 user_id: UserId, - pub room_id: RoomId, - pub event_type: String, - } - - impl ::Endpoint for Endpoint { - type BodyParams = ::serde_json::Value; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Associate account data with a room.", + method: Method::Put, + name: "set_room_account_data", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/account_data/{}", - params.user_id, - params.room_id, - params.event_type - ) + request { + /// Arbitrary JSON to store as config data. + #[ruma_api(body)] + pub data: Value, + /// The event type of the account_data to set. + /// + /// 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)] + pub room_id: RoomId, + /// The ID of the user to set account_data for. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type" - } - - fn name() -> &'static str { - "set_room_account_data" - } - - fn description() -> &'static str { - "Associate account data with a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) pub mod set_global_account_data { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_json::Value; - /// 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 user_id: UserId, - pub event_type: String, - } - - impl ::Endpoint for Endpoint { - type BodyParams = ::serde_json::Value; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Sets global account data.", + method: Method::Put, + name: "set_global_account_data", + path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/account_data/{}", - params.user_id, - params.event_type - ) + request { + /// Arbitrary JSON to store as config data. + #[ruma_api(body)] + pub data: Value, + /// The event type of the account_data to set. + /// + /// 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. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/account_data/:type" - } - - fn name() -> &'static str { - "set_global_account_data" - } - - fn description() -> &'static str { - "Sets global account data." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } From a40ec4e07fdebc6ea0b15915c2571160c58be5df Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 21:01:25 -0700 Subject: [PATCH 053/350] Use ruma-api-macros for the contact endpoints. --- src/lib.rs | 2 +- src/r0/contact.rs | 202 ++++++++++++++++------------------------------ 2 files changed, 71 insertions(+), 133 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c1109550..6ff2a6ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ pub mod r0 { pub mod account; pub mod alias; pub mod config; -// pub mod contact; + pub mod contact; // pub mod context; // pub mod directory; // pub mod filter; diff --git a/src/r0/contact.rs b/src/r0/contact.rs index e2878e7d..4a9bdcc0 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -2,173 +2,111 @@ /// [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) pub mod create_contact { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub bind: Option, - pub three_pid_creds: ThreePidCredentials, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + ruma_api! { + metadata { + description: "Adds contact information to the user's account.", + method: Method::Post, + name: "create_contact", + path: "/_matrix/client/r0/account/3pid", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Whether the homeserver should also bind this third party identifier to the account's + /// Matrix ID with the passed identity server. + /// + /// Default to `false` if not supplied. + #[serde(skip_serializing_if = "Option::is_none")] + pub bind: Option, + /// The third party credentials to associate with the account. + pub three_pid_creds: ThreePidCredentials, + } + + response {} + } /// The third party credentials to associate with the account. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThreePidCredentials { + /// The client secret used in the session with the identity server. pub client_secret: String, + /// The identity server to use. pub id_server: String, + /// The session identifier given by the identity server. pub sid: String, } - - impl ::Endpoint for Endpoint { - type BodyParams = 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/account/3pid" - } - - fn name() -> &'static str { - "create_contact" - } - - fn description() -> &'static str { - "Adds contact information to the user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } - } } /// [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) pub mod get_contacts { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; + + ruma_api! { + metadata { + description: "Get a list of 3rd party contacts associated with the user's account.", + method: Method::Get, + name: "get_contacts", + path: "/_matrix/client/r0/account/3pid", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// A list of third party identifiers the homeserver has associated with the user's + /// account. + pub threepids: Vec, + } + } /// The medium of third party identifier. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Medium { + /// An email address. #[serde(rename="email")] Email, } - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub threepids: Vec, - } - /// An identifier external to Matrix. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartyIdentifier { + /// The third party identifier address. pub address: String, + /// The medium of third party identifier. pub medium: Medium, } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/account/3pid/email/requestToken" - } - - fn name() -> &'static str { - "get_contacts" - } - - fn description() -> &'static str { - "Get a list of 3rd party contacts associated with the user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } - } } /// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub client_secret: String, - pub email: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - pub send_attempt: u64, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Ask for a verification token for a given 3rd party ID.", + method: Method::Post, + name: "request_contact_verification_token", + path: "/_matrix/client/r0/account/3pid/email/requestToken", + rate_limited: false, + requires_authentication: false, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: u64, } - fn router_path() -> &'static str { - "/_matrix/client/r0/account/3pid/email/requestToken" - } - - fn name() -> &'static str { - "request_contact_verification_token" - } - - fn description() -> &'static str { - "Ask for a verification token for a given 3rd party ID." - } - - fn requires_authentication() -> bool { - // Not sure why this don't require auth? - false - } - - fn rate_limited() -> bool { - false - } + response {} } } From 4b728514ca23200db59886a01326f3219e268bdf Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 21:09:58 -0700 Subject: [PATCH 054/350] Use ruma-api-macros for the context endpoints. --- src/lib.rs | 2 +- src/r0/context.rs | 93 ++++++++++++++++++----------------------------- 2 files changed, 37 insertions(+), 58 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6ff2a6ea..1c580537 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ pub mod r0 { pub mod alias; pub mod config; pub mod contact; -// pub mod context; + pub mod context; // pub mod directory; // pub mod filter; // pub mod media; diff --git a/src/r0/context.rs b/src/r0/context.rs index 7eebca4f..d37e2349 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -4,68 +4,47 @@ pub mod get_context { use ruma_identifiers::{EventId, RoomId}; use ruma_events::collections::only; + use ruma_api_macros::ruma_api; - - /// 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 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, - pub events_before: Vec, - pub start: String, - pub state: Vec, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = QueryParams; - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the events immediately preceding and following a given event.", + method: Method::Get, + path: "/_matrix/client/r0/rooms/:room_id/context/:event_id", + name: "get_context", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!("/_matrix/client/r0/rooms/{}/context/{}", params.room_id, params.event_id) + request { + /// 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 { - "/_matrix/client/r0/rooms/:room_id/context/:event_id" - } - - fn name() -> &'static str { - "get_context" - } - - fn description() -> &'static str { - "Get the events immediately preceding and following a given event." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// A token that can be used to paginate forwards with. + pub end: String, + /// Details of the requested event. + pub event: only::RoomEvent, + /// A list of room events that happened just after the requested event, in chronological + /// order. + pub events_after: Vec, + /// A list of room events that happened just before the requested event, in + /// reverse-chronological order. + pub events_before: Vec, + /// A token that can be used to paginate backwards with. + pub start: String, + /// The state of the room at the last event returned. + pub state: Vec, } } } From dfb45a762f7f16dce16b7ae087ab3f2a0c3b9eea Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 21:25:18 -0700 Subject: [PATCH 055/350] Use ruma-api-macros for the directory endpoints. --- src/lib.rs | 2 +- src/r0/directory.rs | 94 +++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 55 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c580537..ec0780b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub mod r0 { pub mod config; pub mod contact; pub mod context; -// pub mod directory; + pub mod directory; // pub mod filter; // pub mod media; // pub mod membership; diff --git a/src/r0/directory.rs b/src/r0/directory.rs index cd7aa498..9190d11e 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -3,67 +3,53 @@ /// [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) pub mod get_public_rooms { use ruma_identifiers::{RoomId, RoomAliasId}; + use ruma_api_macros::ruma_api; + + ruma_api! { + metadata { + description: "Get the list of rooms in this homeserver's public directory.", + method: Method::Get, + name: "get_public_rooms", + path: "/_matrix/client/r0/publicRooms", + rate_limited: false, + requires_authentication: false, + } + + request {} + + response { + /// A pagination token for the response. + pub start: String, + /// A paginated chunk of public rooms. + pub chunk: Vec, + /// A pagination token for the response. + pub end: String + } + } /// A chunk of the response, describing one room #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { - pub world_readable: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - pub num_joined_members: u64, + /// Aliases of the room. + pub aliases: Vec, + /// The URL for the room's avatar, if one is set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, - pub room_id: RoomId, + /// Whether guest users may join the room and participate in it. + /// + /// If they can, they will be subject to ordinary power level rules like any other user. pub guest_can_join: bool, - pub aliases: Vec, + /// The name of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option - } - - /// This API response type - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub start: String, - pub chunk: Vec, - pub end: String - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/publicRooms" - } - - fn name() -> &'static str { - "get_public_rooms" - } - - fn description() -> &'static str { - "Get the list of rooms in this homeserver's public directory." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false - } + pub name: Option, + /// The number of members joined to the room. + pub num_joined_members: u64, + /// The ID of the room. + pub room_id: RoomId, + /// The topic of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// Whether the room may be viewed by guest users without joining. + pub world_readable: bool, } } From 392dc69b1732c69e56ad63c1f9928c9481574f9b Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 21 May 2017 02:19:54 -0700 Subject: [PATCH 056/350] Use ruma-api-macros for the filter endpoints. --- Cargo.toml | 2 +- src/lib.rs | 2 +- src/r0/filter.rs | 224 ++++++++++++++++++++++++++--------------------- 3 files changed, 125 insertions(+), 103 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b6af2fc..62cf9ec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "58fab938b00d01aeb5e3e8c31731b4e479d5553d" +rev = "35362e78a6cfef346ad74c4b38c6e0611402231b" diff --git a/src/lib.rs b/src/lib.rs index ec0780b0..1ec0e41f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ pub mod r0 { pub mod contact; pub mod context; pub mod directory; -// pub mod filter; + pub mod filter; // pub mod media; // pub mod membership; // pub mod presence; diff --git a/src/r0/filter.rs b/src/r0/filter.rs index dac73e7e..4ee3265a 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -5,209 +5,231 @@ use ruma_identifiers::{RoomId, UserId}; /// Format to use for returned events #[derive(Copy, Clone, Debug, Deserialize, Serialize)] pub enum EventFormat { - /// Client format, as described in the Client API - #[serde(rename="client")] + /// Client format, as described in the Client API. + #[serde(rename = "client")] Client, - /// Raw events from federation - #[serde(rename="federation")] - Federation + /// Raw events from federation. + #[serde(rename = "federation")] + Federation, } /// Filters to be applied to room events #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomEventFilter { + /// A list of event types to exclude. + /// + /// If this list is absent then no event types are excluded. A matching type will be excluded + /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any + /// sequence of characters. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub not_types: Vec, + /// A list of room IDs to exclude. + /// + /// If this list is absent then no rooms are excluded. A matching room will be excluded even if + /// it is listed in the 'rooms' filter. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub not_rooms: Vec, + /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, + /// A list of room IDs to include. + /// + /// If this list is absent then all rooms are included. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub rooms: Vec, + /// A list of sender IDs to exclude. + /// + /// If this list is absent then no senders are excluded. A matching sender will be excluded even + /// if it is listed in the 'senders' filter. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub not_senders: Vec, + /// A list of senders IDs to include. + /// + /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub senders: Vec, + /// A list of event types to include. + /// + /// If this list is absent then all event types are included. A '*' can be used as a wildcard to + /// match any sequence of characters. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] - pub types: Vec + pub types: Vec, } /// Filters to be applied to room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomFilter { + /// Include rooms that the user has left in the sync. + /// + /// Defaults to false if not included. #[serde(skip_serializing_if = "Option::is_none")] pub include_leave: Option, + /// The per user account data to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + /// The message and state update events to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub timeline: Option, + /// The events that aren't recorded in the room history, e.g. typing and receipts, to include + /// for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub ephemeral: Option, + /// The state events to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, + /// A list of room IDs to exclude. + /// + /// If this list is absent then no rooms are excluded. A matching room will be excluded even if + /// it is listed in the 'rooms' filter. This filter is applied before the filters in + /// `ephemeral`, `state`, `timeline` or `account_data`. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub not_rooms: Vec, + /// A list of room IDs to include. + /// + /// If this list is absent then all rooms are included. This filter is applied before the + /// filters in `ephemeral`, `state`, `timeline` or `account_data`. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] - pub room: Vec + pub room: Vec, } /// Filter for not-room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Filter { + /// A list of event types to exclude. + /// + /// If this list is absent then no event types are excluded. A matching type will be excluded + /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any + /// sequence of characters. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub not_types: Vec, + /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, + /// A list of senders IDs to include. + /// + /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub senders: Vec, + /// A list of event types to include. + /// + /// If this list is absent then all event types are included. A '*' can be used as a wildcard to + /// match any sequence of characters. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub types: Vec, + /// A list of sender IDs to exclude. + /// + /// If this list is absent then no senders are excluded. A matching sender will be excluded even + /// if it is listed in the 'senders' filter. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] - pub not_senders: Vec + pub not_senders: Vec, } /// A filter definition #[derive(Clone, Debug, Deserialize, Serialize)] pub struct FilterDefinition { + /// List of event fields to include. + /// + /// If this list is absent then all fields are included. The entries may include '.' charaters + /// to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' + /// object. A literal '.' character in a field name may be escaped using a '\'. A server may + /// include more fields than were requested. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub event_fields: Vec, + /// The format to use for events. + /// + /// 'client' will return the events in a format suitable for clients. 'federation' will return + /// the raw event as receieved over federation. The default is 'client'. #[serde(skip_serializing_if = "Option::is_none")] pub event_format: Option, + /// The user account data that isn't associated with rooms to include. #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + /// Filters to be applied to room data. #[serde(skip_serializing_if = "Option::is_none")] pub room: Option, + /// The presence updates to include. #[serde(skip_serializing_if = "Option::is_none")] - pub presence: Option + pub presence: Option, } /// [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) pub mod create_filter { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use super::FilterDefinition; - /// 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 user_id: UserId - } - - /// This API Response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub filter_id: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = FilterDefinition; - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Create a new filter for event retrieval.", + method: Method::Post, + name: "create_filter", + path: "/_matrix/client/r0/user/:user_id/filter", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/filter", - params.user_id - ) + request { + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition, + /// The ID of the user uploading the filter. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/filter" - } - - fn name() -> &'static str { - "create_filter" - } - - fn description() -> &'static str { - "Create a new filter for event retrieval." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// The ID of the filter that was created. + pub filter_id: String, } } } /// [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) pub mod get_filter { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use super::FilterDefinition; - /// 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 user_id: UserId, - pub filter_id: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = FilterDefinition; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Retrieve a previously created filter.", + method: Method::Get, + name: "get_filter", + path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/filter/{}", - params.user_id, - params.filter_id - ) + request { + /// The ID of the filter to download. + #[ruma_api(path)] + pub filter_id: String, + /// The user ID to download a filter for. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/filter/:filter_id" - } - - fn name() -> &'static str { - "get_filter" - } - - fn description() -> &'static str { - "Retrieve a previously created filter." - } - - fn requires_authentication() -> bool { - // TODO: not sure why, as I guess you should not be able to retrieve - // other users filters? - false - } - - fn rate_limited() -> bool { - false + response { + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition, } } } From 4ef45b302214cf13060ce781152c34f86d1822f6 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 1 Jun 2017 17:55:24 -0700 Subject: [PATCH 057/350] Bump ruma-events and ruma-signatures. --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 62cf9ec1..c5c8dea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,9 @@ version = "0.1.0" [dependencies] futures = "0.1.13" -ruma-events = "0.8.0" +ruma-events = "0.9.0" ruma-identifiers = "0.11.0" -ruma-signatures = "0.3.0" +ruma-signatures = "0.4.0" serde = "1.0.2" serde_derive = "1.0.2" serde_json = "1.0.1" From f9309e652a88dd510c2002cbe21bd617fb63ac75 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 14 Jun 2017 11:57:06 +0200 Subject: [PATCH 058/350] Bump dependency versions --- Cargo.toml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5c8dea8..f1252d11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,8 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -futures = "0.1.13" +futures = "0.1.14" +hyper = "0.11" ruma-events = "0.9.0" ruma-identifiers = "0.11.0" ruma-signatures = "0.4.0" @@ -19,14 +20,10 @@ serde = "1.0.2" serde_derive = "1.0.2" serde_json = "1.0.1" -[dependencies.hyper] -git = "https://github.com/hyperium/hyper" -rev = "fed04dfb58e19b408322d4e5ca7474871e848a35" - [dependencies.ruma-api] git = "https://github.com/ruma/ruma-api" -rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" +rev = "211cf5e3531cd1862136129d5f73caaac7b4eb43" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "35362e78a6cfef346ad74c4b38c6e0611402231b" +rev = "f5a935384e36134daf86a13190318a5c50cf2c17" From 6f9cb395069f75c63f9e2485da8dc7c02bbdf389 Mon Sep 17 00:00:00 2001 From: Simon Goller Date: Sun, 18 Jun 2017 18:12:35 +0200 Subject: [PATCH 059/350] Make aliases optional for global rooms query. The server response cannot be deserialized because the aliases attribute can be missing. Wrapped the alias attribute with an Option to fix the issue. --- src/r0/directory.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 9190d11e..fc1c4c17 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -31,7 +31,8 @@ pub mod get_public_rooms { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { /// Aliases of the room. - pub aliases: Vec, + //#[serde(skip_serializing_if = "Option::is_none")] + pub aliases: Option>, /// The URL for the room's avatar, if one is set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, From 5f880dfbb18363389cdff4c765aa8524cd63ee2b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Jun 2017 03:35:41 +1000 Subject: [PATCH 060/350] Use ruma-api-macros for the send endpoints. --- src/lib.rs | 2 +- src/r0/send.rs | 221 +++++++++++++++---------------------------------- 2 files changed, 68 insertions(+), 155 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ec0e41f..11005431 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,7 +35,7 @@ pub mod r0 { // pub mod redact; // pub mod room; // pub mod search; -// pub mod send; + pub mod send; // pub mod server; // pub mod session; // pub mod sync; diff --git a/src/r0/send.rs b/src/r0/send.rs index 7c7ac4dc..cd6c7a12 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -2,193 +2,106 @@ /// [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; - /// 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, - pub event_type: EventType - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - 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 + 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, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state/{}", - params.room_id, - params.event_type - ) + 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, } - 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 + response { + /// A unique identifier for the event. + pub event_id: EventId, } } } /// [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; - /// 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, - pub event_type: EventType, - pub state_key: String - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - 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 + 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, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state/{}/{}", - params.room_id, - params.event_type, - params.state_key - ) + 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, + /// The state_key for the state to send. Defaults to the empty string. + #[ruma_api(path)] + pub state_key: String, } - 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 + response { + /// A unique identifier for the event. + pub event_id: EventId, } } } /// [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; - /// 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, - pub event_type: EventType, - pub txn_id: String - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - 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 + 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, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/send/{}/{}", - params.room_id, - params.event_type, - params.txn_id - ) + 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, + /// 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, } - 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 + response { + /// A unique identifier for the event. + pub event_id: EventId, } } } From e0bb81ad67e9f315b49c426fd86234f9f2791ccc Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Jul 2017 15:39:45 -0700 Subject: [PATCH 061/350] Use ruma-api-macros for the media endpoints. --- Cargo.toml | 6 +- src/lib.rs | 4 +- src/r0/media.rs | 227 ++++++++++++++++-------------------------------- 3 files changed, 82 insertions(+), 155 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f1252d11..153fd16d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,13 @@ ruma-signatures = "0.4.0" serde = "1.0.2" serde_derive = "1.0.2" serde_json = "1.0.1" +serde_urlencoded = "0.5.1" +url = "1.5.1" [dependencies.ruma-api] git = "https://github.com/ruma/ruma-api" -rev = "211cf5e3531cd1862136129d5f73caaac7b4eb43" +rev = "4893be93f86543f9a9e3c5d7205afba769b84aa6" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "f5a935384e36134daf86a13190318a5c50cf2c17" +rev = "84562c426044eef6b1c2f0e964e85ff9d100aa27" diff --git a/src/lib.rs b/src/lib.rs index 1ec0e41f..fe9a70e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,8 @@ extern crate ruma_signatures; extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; +extern crate serde_urlencoded; +extern crate url; /// Endpoints for the r0.x.x versions of the client API specification. pub mod r0 { @@ -26,7 +28,7 @@ pub mod r0 { pub mod context; pub mod directory; pub mod filter; -// pub mod media; + pub mod media; // pub mod membership; // pub mod presence; // pub mod profile; diff --git a/src/r0/media.rs b/src/r0/media.rs index 7978bd0e..668aabc7 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -2,117 +2,73 @@ /// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) pub mod get_content { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use hyper::header::{ContentDisposition, ContentType}; + use ruma_api_macros::ruma_api; - /// This API endpoint's path parameters. - #[derive(Clone, Debug)] - pub struct PathParams { - /// The media ID from the mxc:// URI (the path component). - pub media_id: String, - /// The server name from the mxc:// URI (the authoritory component). - pub server_name: String, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = (); // TODO: How should a file be represented as a response? - // must include HTTP headers Content-Type and Content-Disposition (filename) - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Retrieve content from the media store.", + method: Method::Get, + name: "get_media_content", + path: "/_matrix/media/r0/download/:server_name/:media_id", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/media/r0/download/{}/{}", - params.server_name, - params.media_id - ) + request { + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: String, } - fn router_path() -> &'static str { - "/_matrix/media/r0/download/:server_name/:media_id" - } - - fn name() -> &'static str { - "get_media_content" - } - - fn description() -> &'static str { - "Retrieve content from the media store." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The content that was previously uploaded. + #[ruma_api(body)] + pub file: Vec, + /// The content type of the file that was previously uploaded. + #[ruma_api(header)] + pub content_type: ContentType, + /// The name of the file that was previously uploaded, if set. + #[ruma_api(header)] + pub content_disposition: ContentDisposition, } } } /// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) pub mod create_content { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use hyper::header::ContentType; + use ruma_api_macros::ruma_api; - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - /// The MXC URI for the uploaded content. - pub content_uri: String, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); // TODO: How should a file be represented as the request body? - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Upload content to the media store.", + method: Method::Post, + name: "create_media_content", + path: "/_matrix/media/r0/upload", + rate_limited: false, + requires_authentication: false, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// The content type of the file being uploaded. + #[ruma_api(header)] + pub content_type: ContentType, } - fn router_path() -> &'static str { - "/_matrix/media/r0/upload" - } - - fn name() -> &'static str { - "create_media_content" - } - - fn description() -> &'static str { - "Upload content to the media store." - } - - fn requires_authentication() -> bool { - // TODO: How comes this does not require authentication? - false - } - - fn rate_limited() -> bool { - false + response { + /// The MXC URI for the uploaded content. + pub content_uri: String, } } } /// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) pub mod get_content_thumbnail { - use std::fmt::{Display, Error as FmtError, Formatter}; - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; /// The desired resizing method. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] @@ -125,73 +81,40 @@ pub mod get_content_thumbnail { Scale, } - /// This API endpoint's path parameters. - #[derive(Clone, Debug)] - pub struct PathParams { - /// The media ID from the mxc:// URI (the path component). - pub media_id: String, - /// The server name from the mxc:// URI (the authoritory component). - pub server_name: String, - } - - /// This API endpoint's query string parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct QueryParams { - /// The *desired* height of the thumbnail. The actual thumbnail may not match the size - /// specified. - pub height: Option, - /// The desired resizing method. - pub method: Option, - /// The *desired* width of the thumbnail. The actual thumbnail may not match the size - /// specified. - pub width: Option, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = QueryParams; - type Response = (); // TODO: How should a file be represented as a response? - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Get a thumbnail of content from the media store.", + method: Method::Get, + name: "get_content_thumbnail", + path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/media/r0/thumbnail/{}/{}", - params.server_name, - params.media_id - ) + request { + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: String, + /// The *desired* height of the thumbnail. The actual thumbnail may not match the size + /// specified. + #[ruma_api(query)] + pub height: Option, + /// The desired resizing method. + #[ruma_api(query)] + pub method: Option, + /// The *desired* width of the thumbnail. The actual thumbnail may not match the size + /// specified. + #[ruma_api(query)] + pub width: Option, } - fn router_path() -> &'static str { - "/_matrix/media/r0/thumbnail/:server_name/:media_id" - } - - fn name() -> &'static str { - "get_content_thumbnail" - } - - fn description() -> &'static str { - "Get a thumbnail of content from the media store." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false - } - } - - impl Display for Method { - fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { - match *self { - Method::Crop => write!(f, "crop"), - Method::Scale => write!(f, "scale"), - } + response { + /// A thumbnail of the requested content. + #[ruma_api(body)] + pub file: Vec, } } } From 7f78253539f2c7f303ff16bc2b5fbeb0feac2b4e Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 1 Jul 2017 17:24:00 -0700 Subject: [PATCH 062/350] Update ruma-client-macros for bug fix. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 153fd16d..79825822 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,4 @@ rev = "4893be93f86543f9a9e3c5d7205afba769b84aa6" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "84562c426044eef6b1c2f0e964e85ff9d100aa27" +rev = "0f32ca01dbf75aeab91937e421dfaa2d1f67351a" From 06ddfdd68107773509c3fbe8b281fde04862b323 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 3 Jul 2017 16:41:25 -0700 Subject: [PATCH 063/350] Use ruma-api-macros for the membership endpoints. --- src/lib.rs | 2 +- src/r0/membership.rs | 547 ++++++++++++------------------------------- 2 files changed, 146 insertions(+), 403 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe9a70e7..f36a7000 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ pub mod r0 { pub mod directory; pub mod filter; pub mod media; -// pub mod membership; + pub mod membership; // pub mod presence; // pub mod profile; // pub mod push; diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 540b96f3..ed0b1552 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -5,7 +5,8 @@ use ruma_signatures::Signatures; // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } // for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? -/// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. +/// A signature of an `m.third_party_invite` token to prove that this user owns a third party +/// identity which has been invited to the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartySigned { /// The Matrix ID of the invitee. @@ -20,490 +21,232 @@ pub struct ThirdPartySigned { /// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) pub mod invite_user { + use ruma_api_macros::ruma_api; use ruma_identifiers::{UserId, RoomId}; - /// The request body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub user_id: UserId, - } - - /// 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, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Invite a user to a room.", + method: Method::Post, + name: "invite_user", + path: "/_matrix/client/r0/rooms/:room_id/invite", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/invite", - params.room_id - ) + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to invite. + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/invite" - } - - fn name() -> &'static str { - "invite_user" - } - - fn description() -> &'static str { - "Invite a user to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) pub mod join_room_by_id_or_alias { + use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; + use super::ThirdPartySigned; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option, - } - - /// 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, - } - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id_or_alias: RoomIdOrAliasId, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Join a room using its ID or one of its aliases.", + method: Method::Post, + name: "join_room_by_id_or_alias", + path: "/_matrix/client/r0/join/:room_id_or_alias", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - match params.room_id_or_alias { - RoomIdOrAliasId::RoomId(room_id) => { - format!( - "/_matrix/client/r0/join/{}", - room_id - ) - } - RoomIdOrAliasId::RoomAliasId(room_alias_id) => { - format!( - "/_matrix/client/r0/join/{}", - room_alias_id - ) - } - } + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id_or_alias: RoomIdOrAliasId, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option, } - fn router_path() -> &'static str { - "/_matrix/client/r0/join/:room_id_or_alias" - } - - fn name() -> &'static str { - "join_room_by_id_or_alias" - } - - fn description() -> &'static str { - "Join a room using its ID or one of its aliases." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true + response { + /// The room that the user joined. + pub room_id: RoomId, } } } /// [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) pub mod join_room_by_id { + use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; + use super::ThirdPartySigned; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option, - } - - /// 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, - } - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub room_id: RoomId, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Join a room using its ID.", + method: Method::Post, + name: "join_room_by_id", + path: "/_matrix/client/r0/rooms/:room_id/join", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/join", - params.room_id - ) + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: RoomId, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/join" - } - - fn name() -> &'static str { - "join_room_by_id" - } - - fn description() -> &'static str { - "Join a room using its ID." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true + response { + /// The room that the user joined. + pub room_id: RoomId, } } } /// [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) pub mod forget_room { + 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 { - pub room_id: RoomId, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Forget a room.", + method: Method::Post, + name: "forget_room", + path: "/_matrix/client/r0/rooms/:room_id/forget", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/forget", - params.room_id - ) + request { + /// The room to forget. + #[ruma_api(path)] + pub room_id: RoomId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/forget" - } - - fn name() -> &'static str { - "forget_room" - } - - fn description() -> &'static str { - "Forget a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) pub mod leave_room { + 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 { - pub room_id: RoomId, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Leave a room.", + method: Method::Post, + name: "leave_room", + path: "/_matrix/client/r0/rooms/:room_id/leave", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/leave", - params.room_id - ) + request { + /// The room to leave. + #[ruma_api(path)] + pub room_id: RoomId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/leave" - } - - fn name() -> &'static str { - "leave_room" - } - - fn description() -> &'static str { - "Leave a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) pub mod kick_user { - use ruma_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomId, UserId}; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub user_id: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, - } - - /// 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, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Kick a user from a room.", + method: Method::Post, + name: "kick_user", + path: "/_matrix/client/r0/rooms/:room_id/kick", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/kick", - params.room_id - ) + request { + /// The reason for kicking the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to kick. + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/kick" - } - - fn name() -> &'static str { - "kick_user" - } - - fn description() -> &'static str { - "Kick a user from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) pub mod unban_user { - use ruma_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomId, UserId}; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub user_id: String, - } - - /// 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, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Unban a user from a room.", + method: Method::Post, + name: "unban_user", + path: "/_matrix/client/r0/rooms/:room_id/unban", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/unban", - params.room_id - ) + request { + /// The room to unban the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to unban. + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/unban" - } - - fn name() -> &'static str { - "unban_user" - } - - fn description() -> &'static str { - "unban a user from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) pub mod ban_user { - use ruma_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomId, UserId}; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, - pub user_id: String, - } - - /// 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, - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Ban a user from a room.", + method: Method::Post, + name: "ban_user", + path: "/_matrix/client/r0/rooms/:room_id/ban", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/ban", - params.room_id - ) + request { + /// The reason for banning the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to ban. + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/ban" - } - - fn name() -> &'static str { - "ban_user" - } - - fn description() -> &'static str { - "Ban a user from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } From f715124190cd0f42dd85921a4071d8621783f768 Mon Sep 17 00:00:00 2001 From: Ross Schulman Date: Fri, 30 Jun 2017 18:34:24 -0400 Subject: [PATCH 064/350] Implement ruma_api macro --- src/r0/sync.rs | 465 +++++++++++++++---------------------------------- 1 file changed, 145 insertions(+), 320 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 16a5e925..cfa22a5a 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -2,317 +2,164 @@ /// [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 - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Vec; - - fn method() -> ::Method { - ::Method::Get + 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, } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state", - params.room_id - ) + request { + #[ruma_api(path)] + pub room_id: RoomId, } - - 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 Vec, } } } /// [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_identifiers::RoomId; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomId, 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 { - pub room_id: RoomId, - pub event_type: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = ::serde_json::Value; - - fn method() -> ::Method { - ::Method::Get + 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, } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state/{}", - params.room_id, - params.event_type - ) + request { + /// The room to query for events + #[ruma_api(path)] + pub room_id: RoomId, + /// The type of state to look up + #[ruma_api(path)] + pub event_type: EventType, } - - 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 { - pub room_id: RoomId, - pub event_type: String, - 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 + 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, } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/state/{}/{}", - params.room_id, - params.event_type, - params.state_key - ) + 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, } - - 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 - } - - 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 } } } /// [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 { - pub room_id: RoomId, - pub event_type: String - } - - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum Direction { - #[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, - pub dir: Direction, - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option - } - - /// This API endpoint's reponse. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub start: String, - pub chunk: Vec, - pub end: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = QueryParams; - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + 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, } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/messages", - params.room_id, - ) + 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, + /// 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, + /// 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, } - - 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 + response { + pub start: String, + pub chunk: Vec, + pub end: String, } } } /// [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,6 +167,34 @@ pub mod sync_events { use r0::filter::FilterDefinition; + 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, + #[serde(skip_serializing_if = "Option::is_none")] + pub since: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub full_state: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub set_presence: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + } + response { + pub next_batch: String, + pub rooms: Rooms, + pub presence: Presence, + } + + } /// Details about this API endpoint. #[derive(Clone, Copy, Debug)] pub struct Endpoint; @@ -328,7 +203,7 @@ pub mod sync_events { #[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 +215,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, - #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub full_state: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub set_presence: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option - } - /// Updates to rooms #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Rooms { pub leave: HashMap, pub join: HashMap, - pub invite: HashMap + pub invite: HashMap, } /// 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 +237,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,43 +252,43 @@ 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 + pub events: only::Event, } /// This API endpoint's reponse. @@ -436,41 +296,6 @@ pub mod sync_events { 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 presence: Presence, } } From a097aa02f21cd0add260a4609eb9abf1d53a90ea Mon Sep 17 00:00:00 2001 From: Ross Schulman Date: Fri, 30 Jun 2017 21:53:30 -0400 Subject: [PATCH 065/350] Port session.rs to ruma_api_macro --- src/r0/session.rs | 124 ++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 91 deletions(-) diff --git a/src/r0/session.rs b/src/r0/session.rs index 7f67babb..dc8d79bb 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -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,10 +28,7 @@ pub mod login { #[serde(skip_serializing_if = "Option::is_none")] pub address: Option } - - /// 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")] @@ -48,80 +36,34 @@ pub mod login { pub user_id: String, } - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; + /// Possible login mediums for 3rd party ID + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum LoginMedium { + #[serde(rename = "email")] + Email + } - 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/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 {} } From 3a854bf64aafa2ae79d7478059b95dca5f7d0cc2 Mon Sep 17 00:00:00 2001 From: Ross Schulman Date: Sat, 1 Jul 2017 13:32:11 -0400 Subject: [PATCH 066/350] Update lib.rs with newly available calls --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 11005431..f2f6c29e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,8 +37,8 @@ pub mod r0 { // pub mod search; 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; From a1a9064d28d49e4ea7ba35cfc57736709ccb3754 Mon Sep 17 00:00:00 2001 From: Ross Schulman Date: Sat, 1 Jul 2017 15:57:21 -0400 Subject: [PATCH 067/350] Squash a bunch of bugs --- src/r0/session.rs | 82 ++++++++++++++++++++++++----------------------- src/r0/sync.rs | 40 +++++++++++------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/r0/session.rs b/src/r0/session.rs index dc8d79bb..63285be2 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -5,49 +5,50 @@ pub mod login { use ruma_api_macros::ruma_api; ruma_api! { - metadata { - description: "Login to the homeserver.", - method: ::Method::Post, - name: "login", - path: "/_matrix/client/r0/login", - rate_limited: true, - requires_authentication: false, - } - request { - /// Password of the user - pub password: String, - /// Medium of 3rd party login to use - #[serde(skip_serializing_if = "Option::is_none")] - pub medium: Option, - /// Type of login to do - #[serde(rename = "type")] - pub kind: LoginKind, - /// Localpart or full matrix user id of the user - pub user: String, - /// 3rd party identifier for the user - #[serde(skip_serializing_if = "Option::is_none")] - pub address: Option - } - response { - pub access_token: String, - pub home_server: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, - pub user_id: String, + metadata { + description: "Login to the homeserver.", + method: Method::Post, + name: "login", + path: "/_matrix/client/r0/login", + rate_limited: true, + requires_authentication: false, + } + request { + /// Password of the user + pub password: String, + /// Medium of 3rd party login to use + #[serde(skip_serializing_if = "Option::is_none")] + pub medium: Option, + /// Type of login to do + #[serde(rename = "type")] + pub kind: LoginKind, + /// Localpart or full matrix user id of the user + pub user: String, + /// 3rd party identifier for the user + #[serde(skip_serializing_if = "Option::is_none")] + pub address: Option + } + response { + pub access_token: String, + pub home_server: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub refresh_token: Option, + pub user_id: String, + } } /// Possible login mediums for 3rd party ID #[derive(Clone, Debug, Deserialize, Serialize)] pub enum LoginMedium { #[serde(rename = "email")] - Email + Email, } /// Possible kinds of login #[derive(Clone, Debug, Deserialize, Serialize)] pub enum LoginKind { #[serde(rename = "m.login.password")] - Password + Password, } } @@ -56,14 +57,15 @@ pub mod logout { use ruma_api_macros::ruma_api; 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, + 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 {} } - request {} - response {} } diff --git a/src/r0/sync.rs b/src/r0/sync.rs index cfa22a5a..87ff903a 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -20,7 +20,7 @@ pub mod get_state_events { pub room_id: RoomId, } response { - pub Vec, + pub room_state: Vec, } } } @@ -28,12 +28,13 @@ pub mod get_state_events { /// [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, EventType}; + use ruma_identifiers::RoomId; + use ruma_events::EventType; ruma_api! { metadata { description: "Get state events of a given type associated with the empty key.", - method: ::Method::Get, + method: Method::Get, name: "get_state_events_for_empty_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type", rate_limited: false, @@ -61,7 +62,7 @@ pub mod get_state_events_for_key { ruma_api! { metadata { description: "Get state events associated with a given key.", - method: ::Method::Get, + method: Method::Get, name: "get_state_events_for_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", rate_limited: false, @@ -70,7 +71,7 @@ pub mod get_state_events_for_key { request { /// The room to look up the state in. #[ruma_api(path)] - pub room_id: RoomID, + pub room_id: RoomId, /// The type of state to look up. #[ruma_api(path)] pub event_type: String, @@ -93,7 +94,7 @@ pub mod get_member_events { ruma_api! { metadata { description: "Get membership events for a room.", - method: ::Method::Get, + method: Method::Get, name: "get_member_events", path: "/_matrix/client/r0/rooms/:room_id/members", rate_limited: false, @@ -105,7 +106,7 @@ pub mod get_member_events { request { /// The room to look up the state in. #[ruma_api(path)] - pub room_id: RoomID, + pub room_id: RoomId, } response { pub chunk: Vec @@ -122,7 +123,7 @@ pub mod get_message_events { ruma_api! { metadata { description: "Get message events for a room.", - method: ::Method::Get, + method: Method::Get, name: "get_message_events", path: "/_matrix/client/r0/rooms/:room_id/messages", rate_limited: false, @@ -133,7 +134,7 @@ pub mod get_message_events { // 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 room_id: RoomId, /// 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. @@ -155,6 +156,14 @@ pub mod get_message_events { pub end: String, } } + + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum Direction { + #[serde(rename="b")] + Backward, + #[serde(rename="f")] + Forward, + } } /// [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) @@ -170,7 +179,7 @@ pub mod sync_events { ruma_api! { metadata { description: "Get all new events from all rooms since the last sync or a given point of time.", - method: ::Method::Get, + method: Method::Get, name: "sync", path: "/_matrix/client/r0/sync", rate_limited: false, @@ -195,9 +204,6 @@ pub mod sync_events { } } - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; /// Whether to set presence or not during sync. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -290,12 +296,4 @@ pub mod sync_events { 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, - } } From 0a997d28a45eb274dbd6cfb81b125eef8c891e84 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 1 Jul 2017 20:50:39 +1000 Subject: [PATCH 068/350] Remove unused serde attributes --- src/r0/config.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/r0/config.rs b/src/r0/config.rs index 90b467f0..31b5e844 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -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. /// From 5c43a32b007ccd77298136c4a9dd2ce31644f91f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 2 Jul 2017 06:01:12 +1000 Subject: [PATCH 069/350] Use ruma-api-macros for the create_room endpoint --- src/lib.rs | 2 +- src/r0/room.rs | 97 +++++++++++++++++--------------------------------- 2 files changed, 34 insertions(+), 65 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f2f6c29e..625d1a56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ 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 server; diff --git a/src/r0/room.rs b/src/r0/room.rs index 38f2f62d..de6fbf13 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -3,26 +3,40 @@ /// [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 { - #[serde(skip_serializing_if = "Option::is_none")] - pub creation_content: Option, - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub invite: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub preset: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias_name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub visibility: Option, // TODO: should be an enum ["public", "private"] - // TODO: missing `invite_3pid`, `initial_state` + 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, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub preset: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub room_alias_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub visibility: Option, // TODO: should be an enum ["public", "private"] + // TODO: missing `invite_3pid`, `initial_state` + } + + response { + pub room_id: RoomId, + } } /// Extra options to be added to the `m.room.create` event. @@ -33,16 +47,6 @@ pub mod create_room { pub federate: Option, } - /// 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 - } - } } From 351a6dbd0ceb1aedcb0af80a987dda8bdd113311 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 2 Jul 2017 06:42:48 +1000 Subject: [PATCH 070/350] Add event body to send requests --- src/r0/send.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/r0/send.rs b/src/r0/send.rs index cd6c7a12..ddf26bcc 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -5,6 +5,7 @@ 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; ruma_api! { metadata { @@ -23,6 +24,9 @@ pub mod send_state_event_for_empty_key { /// The type of event to send. #[ruma_api(path)] pub event_type: EventType, + /// The event's content. + #[ruma_api(body)] + pub data: Value, } response { @@ -37,6 +41,7 @@ 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; ruma_api! { metadata { @@ -58,6 +63,9 @@ pub mod send_state_event_for_key { /// 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, } response { @@ -72,6 +80,7 @@ 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; ruma_api! { metadata { @@ -97,6 +106,9 @@ pub mod send_message_event { /// idempotency of requests. #[ruma_api(path)] pub txn_id: String, + /// The event's content. + #[ruma_api(body)] + pub data: MessageEventContent, } response { From c447a612d342cfc10f4e9c64c1185f8897314668 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 4 Jul 2017 16:39:30 -0700 Subject: [PATCH 071/350] Use ruma-api-macros for the presence endpoints. --- src/lib.rs | 2 +- src/r0/presence.rs | 285 ++++++++++++++------------------------------- 2 files changed, 86 insertions(+), 201 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1eefe2f1..85a42828 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ pub mod r0 { pub mod filter; pub mod media; pub mod membership; -// pub mod presence; + pub mod presence; // pub mod profile; // pub mod push; // pub mod receipt; diff --git a/src/r0/presence.rs b/src/r0/presence.rs index cc6ed8e4..5b29b7e1 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -2,247 +2,132 @@ /// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) pub mod set_presence { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; use ruma_events::presence::PresenceState; - /// 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 user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, - pub presence: PresenceState - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Set presence status for this user.", + method: Method::Put, + name: "set_presence", + path: "/_matrix/client/r0/presence/:user_id/status", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/presence/{}/status", - params.user_id - ) + request { + /// The new presence state. + pub presence: PresenceState, + /// The status message to attach to this state. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, + /// The user whose presence state will be updated. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/presence/:user_id/status" - } - - fn name() -> &'static str { - "set_presence" - } - - fn description() -> &'static str { - "Set presence status for this user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) pub mod get_presence { - use ruma_identifiers::UserId; + use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; + use ruma_identifiers::UserId; - /// 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 user_id: UserId - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub currently_active: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub last_active_ago: Option, - pub presence: PresenceState - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get presence status for this user.", + method: Method::Get, + name: "get_presence", + path: "/_matrix/client/r0/presence/:user_id/status", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/presence/{}/status", - params.user_id - ) + request { + /// The user whose presence state will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/presence/:user_id/status" - } - - fn name() -> &'static str { - "get_presence" - } - - fn description() -> &'static str { - "Get presence status for this user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The state message for this user if one was set. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, + /// Whether or not the user is currently active. + #[serde(skip_serializing_if = "Option::is_none")] + pub currently_active: Option, + /// The length of time in milliseconds since an action was performed by the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub last_active_ago: Option, + /// The user's presence state. + pub presence: PresenceState, } } } /// [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) pub mod update_presence_subscriptions { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// 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 user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - drop: Vec, - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - invite: Vec - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Update the presence subscriptions of the user.", + method: Method::Post, + name: "update_presence_subscriptions", + path: "/_matrix/client/r0/presence/list/:user_id", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/presence/list/{}", - params.user_id - ) + request { + /// A list of user IDs to remove from the list. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub drop: Vec, + /// A list of user IDs to add to the list. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + /// The user whose presence state will be updated. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/presence/list/:user_id" - } - - fn name() -> &'static str { - "update_presence_subscriptions" - } - - fn description() -> &'static str { - "Update the presence subscriptions of the user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) pub mod get_subscribed_presences { - use ruma_identifiers::UserId; + use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceEvent; + use ruma_identifiers::UserId; - /// 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 user_id: UserId - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Vec; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the precence status from the user's subscriptions.", + method: Method::Get, + name: "get_subscribed_presences", + path: "/_matrix/client/r0/presence/list/:user_id", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/presence/list/{}", - params.user_id - ) + request { + /// The user whose presence state will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/presence/list/:user_id" - } - - fn name() -> &'static str { - "get_subscribed_presences" - } - - fn description() -> &'static str { - "Get the precence status from the user's subscriptions." - } - - fn requires_authentication() -> bool { - // TODO: not sure why this does not require authentication - false - } - - fn rate_limited() -> bool { - false + response { + /// A list of presence events for every user on this list. + #[ruma_api(body)] + presence_events: Vec, } } } From 6aceca259ec459c4992e8d4dba9abd2f72f03d0d Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 4 Jul 2017 22:47:14 -0700 Subject: [PATCH 072/350] Add missing docs, fix a bunch of bugs and inconsistencies. --- src/lib.rs | 3 +- src/r0/room.rs | 30 +++++++++- src/r0/session.rs | 33 +++++++---- src/r0/sync.rs | 141 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 156 insertions(+), 51 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 85a42828..d5a123f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,8 @@ //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! shared by client and server code. -#![deny(missing_debug_implementations)] +#![deny(missing_debug_implementations, missing_docs)] #![feature(associated_consts, proc_macro, try_from)] -#![warn(missing_docs)] extern crate futures; extern crate hyper; diff --git a/src/r0/room.rs b/src/r0/room.rs index de6fbf13..a7da4473 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -16,25 +16,39 @@ pub mod create_room { } request { + /// Extra keys to be added to the content of the `m.room.create`. #[serde(skip_serializing_if = "Option::is_none")] pub creation_content: Option, + /// A list of user IDs to invite to the room. + /// + /// This will tell the server to invite everyone in the list to the newly created room. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] pub invite: Vec, + /// If this is included, an `m.room.name` event will be sent into the room to indicate + /// the name of the room. #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, + /// The desired room alias local part. #[serde(skip_serializing_if = "Option::is_none")] pub room_alias_name: Option, + /// If this is included, an `m.room.topic` event will be sent into the room to indicate + /// the topic for the room. #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, + /// A public visibility indicates that the room will be shown in the published room + /// list. A private visibility will hide the room from the published room list. Rooms + /// default to private visibility if this key is not included. #[serde(skip_serializing_if = "Option::is_none")] - pub visibility: Option, // TODO: should be an enum ["public", "private"] + pub visibility: Option, // TODO: missing `invite_3pid`, `initial_state` } response { + /// The created room's ID. pub room_id: RoomId, } } @@ -42,6 +56,9 @@ pub mod create_room { /// Extra options to be added to the `m.room.create` event. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreationContent { + /// Whether users on other servers can join this room. + /// + /// Defaults to `true` if key does not exist. #[serde(rename="m.federate")] #[serde(skip_serializing_if = "Option::is_none")] pub federate: Option, @@ -60,4 +77,15 @@ pub mod create_room { #[serde(rename="trusted_private_chat")] TrustedPrivateChat, } + + /// Whether or not a newly created room will be listed in the room directory. + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] + pub enum Visibility { + /// Indicates that the room will be shown in the published room list. + #[serde(rename = "public")] + Public, + /// Indicates that the room from the published room list. + #[serde(rename = "private")] + Private, + } } diff --git a/src/r0/session.rs b/src/r0/session.rs index 63285be2..c74a850e 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -13,40 +13,49 @@ pub mod login { rate_limited: true, requires_authentication: false, } + request { - /// Password of the user + /// The user's password. pub password: String, - /// Medium of 3rd party login to use + /// When logging in using a third party identifier, the medium of the identifier. #[serde(skip_serializing_if = "Option::is_none")] - pub medium: Option, - /// Type of login to do + pub medium: Option, + /// The authentication mechanism. #[serde(rename = "type")] - pub kind: LoginKind, - /// Localpart or full matrix user id of the user + pub login_type: LoginType, + /// The fully qualified user ID or just local part of the user ID. pub user: String, - /// 3rd party identifier for the user + /// Third party identifier for the user. #[serde(skip_serializing_if = "Option::is_none")] pub address: Option } + response { + /// An access token for the account. pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. pub home_server: String, + /// A refresh token may be exchanged for a new access token using the /tokenrefresh API + /// endpoint. #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, + /// The fully-qualified Matrix ID that has been registered. pub user_id: String, } } - /// Possible login mediums for 3rd party ID + /// The medium of a third party identifier. #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum LoginMedium { + pub enum Medium { + /// An email address. #[serde(rename = "email")] Email, } - /// Possible kinds of login + /// The authentication mechanism. #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum LoginKind { + pub enum LoginType { + /// A password is supplied to authenticate. #[serde(rename = "m.login.password")] Password, } @@ -65,7 +74,9 @@ pub mod logout { rate_limited: false, requires_authentication: true, } + request {} + response {} } } diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 87ff903a..b846f99a 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -3,8 +3,8 @@ /// [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; + use ruma_identifiers::RoomId; ruma_api! { metadata { @@ -15,11 +15,18 @@ pub mod get_state_events { rate_limited: false, requires_authentication: true, } + request { + /// The room to look up the state for. #[ruma_api(path)] pub room_id: RoomId, } + response { + /// If the user is a member of the room this will be the current state of the room as a + /// list of events. If the user has left the room then this will be the state of the + /// room when they left as a list of events. + #[ruma_api(body)] pub room_state: Vec, } } @@ -28,8 +35,8 @@ pub mod get_state_events { /// [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; + use ruma_identifiers::RoomId; ruma_api! { metadata { @@ -40,15 +47,19 @@ pub mod get_state_events_for_empty_key { rate_limited: false, requires_authentication: true, } + request { - /// The room to query for events + /// The room to look up the state for. #[ruma_api(path)] pub room_id: RoomId, - /// The type of state to look up + /// The type of state to look up. #[ruma_api(path)] pub event_type: EventType, } + response { + /// The content of the state event. + #[ruma_api(body)] pub content: ::serde_json::Value, } } @@ -68,8 +79,9 @@ pub mod get_state_events_for_key { rate_limited: false, requires_authentication: true, } + request { - /// The room to look up the state in. + /// The room to look up the state for. #[ruma_api(path)] pub room_id: RoomId, /// The type of state to look up. @@ -79,7 +91,10 @@ pub mod get_state_events_for_key { #[ruma_api(path)] pub state_key: String, } + response { + /// The content of the state event. + #[ruma_api(body)] pub content: ::serde_json::Value, } } @@ -88,8 +103,8 @@ pub mod get_state_events_for_key { /// [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; + use ruma_identifiers::RoomId; ruma_api! { metadata { @@ -103,12 +118,15 @@ pub mod get_member_events { // will return a 403 error is user is not a member of the // room anyway... } + request { - /// The room to look up the state in. + /// The room to get the member events for. #[ruma_api(path)] pub room_id: RoomId, } + response { + /// A list of member events. pub chunk: Vec } } @@ -117,8 +135,8 @@ pub mod get_member_events { /// [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; + use ruma_identifiers::RoomId; ruma_api! { metadata { @@ -129,38 +147,50 @@ pub mod get_message_events { 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. + /// The room to get events from. #[ruma_api(path)] pub room_id: RoomId, - /// 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 + /// 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 + /// 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, - /// Required. The direction to return events from. One of: ["b", "f"] + /// The direction to return events from. pub dir: Direction, - /// The maximum number of events to return. Default: 10. + /// The maximum number of events to return. + /// + /// Default: 10. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, } + response { + /// The token the pagination starts from. pub start: String, + /// A list of room events. pub chunk: Vec, + /// The token the pagination ends at. pub end: String, } } + /// The direction to return events from. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum Direction { + /// Return events backwards in time from the requested `from` token. #[serde(rename="b")] Backward, + /// Return events forwards in time from the requested `from` token. #[serde(rename="f")] Forward, } @@ -168,12 +198,12 @@ pub mod get_message_events { /// [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; - use std::collections::HashMap; + use ruma_api_macros::ruma_api; + use ruma_events::collections::{all, only}; + use ruma_identifiers::RoomId; + use r0::filter::FilterDefinition; ruma_api! { @@ -185,21 +215,31 @@ pub mod sync_events { rate_limited: false, requires_authentication: true, } + request { + /// A filter represented either as its full JSON definition or the ID of a saved filter. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + /// A point in time to continue a sync from. #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, + /// Controls whether to include the full state for all rooms the user is a member of. #[serde(skip_serializing_if = "Option::is_none")] pub full_state: Option, + /// Controls whether the client is automatically marked as online by polling this API. #[serde(skip_serializing_if = "Option::is_none")] pub set_presence: Option, + /// The maximum time to poll in milliseconds before returning this request. #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option, } + response { + /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, + /// Updates to rooms. pub rooms: Rooms, + /// Updates to the presence status of other users. pub presence: Presence, } @@ -208,6 +248,7 @@ pub mod sync_events { /// Whether to set presence or not during sync. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum SetPresence { + /// Do not set the presence of the user calling this API. #[serde(rename="offline")] Offline, } @@ -221,79 +262,105 @@ pub mod sync_events { FilterId(String), } - /// Updates to rooms + /// Updates to rooms. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Rooms { + /// The rooms that the user has left or been banned from. pub leave: HashMap, + /// The rooms that the user has joined. pub join: HashMap, + /// The rooms that the user has been invited to. pub invite: HashMap, } - /// Historical updates to left rooms + /// Historical updates to left rooms. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct LeftRoom { + /// The timeline of messages and state changes in the room up to the point when the user + /// left. pub timeline: Timeline, + /// The state updates for the room up to the start of the timeline. pub state: State, } - /// Updates to joined rooms + /// Updates to joined rooms. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct JoinedRoom { + /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, + /// The timeline of messages and state changes in the room. pub timeline: Timeline, + /// Updates to the state, between the time indicated by the `since` parameter, and the start + /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not + /// given, or `full_state` is true). pub state: State, + /// The private data that this user has attached to this room. pub account_data: AccountData, + /// The ephemeral events in the room that aren't recorded in the timeline or state of the + /// room. e.g. typing. pub ephemeral: Ephemeral, } /// unread notifications count #[derive(Clone, Debug, Deserialize, Serialize)] pub struct UnreadNotificationsCount { + /// The number of unread notifications for this room with the highlight flag set. pub highlight_count: u64, + /// The total number of unread notifications for this room. pub notification_count: u64, } - /// timeline + /// Events in the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Timeline { + /// True if the number of events returned was limited by the `limit` on the filter. pub limited: bool, + /// A token that can be supplied to to the `from` parameter of the + /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, - pub events: only::RoomEvent, + /// A list of events. + pub events: Vec, } - /// state + /// State events in the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct State { - pub events: only::StateEvent, + /// A list of state events. + pub events: Vec, } - /// account data + /// The private data that this user has attached to this room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AccountData { - pub events: only::Event, + /// A list of events. + pub events: Vec, } - /// ephemeral + /// Ephemeral events not recorded in the timeline or state of the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Ephemeral { - pub events: only::Event, + /// A list of events. + pub events: Vec, } - /// invited room updates + /// Updates to the rooms that the user has been invited to. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InvitedRoom { + /// The state of a room that the user has been invited to. pub invite_state: InviteState, } - /// invite state + /// The state of a room that the user has been invited to. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InviteState { - pub events: only::StateEvent, + /// A list of state events. + pub events: Vec, } - /// presence + /// Updates to the presence status of other users. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Presence { - pub events: only::Event, + /// A list of events. + pub events: Vec, } } From a5427a5dafeedbf84a6a9d9b71add337f07a6f46 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 5 Jul 2017 20:37:57 -0700 Subject: [PATCH 073/350] Use `UserId` instead of `String` for the login endpoint. --- src/r0/session.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r0/session.rs b/src/r0/session.rs index c74a850e..b08c9b85 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -3,6 +3,7 @@ /// [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) pub mod login { use ruma_api_macros::ruma_api; + use ruma_identifiers::UserId; ruma_api! { metadata { @@ -40,7 +41,7 @@ pub mod login { #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, /// The fully-qualified Matrix ID that has been registered. - pub user_id: String, + pub user_id: UserId, } } From beacb5f2686fa4bea342f6a8370d622adcb0c60b Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 5 Jul 2017 22:45:33 -0700 Subject: [PATCH 074/350] Use ruma-api-macros for the profile endpoints. --- src/lib.rs | 2 +- src/r0/profile.rs | 332 ++++++++++++---------------------------------- 2 files changed, 88 insertions(+), 246 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d5a123f8..ca041618 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ pub mod r0 { pub mod media; pub mod membership; pub mod presence; -// pub mod profile; + pub mod profile; // pub mod push; // pub mod receipt; // pub mod redact; diff --git a/src/r0/profile.rs b/src/r0/profile.rs index a5aaff7d..5f49499c 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -2,303 +2,145 @@ /// [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) pub mod get_display_name { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the display name of a user.", + method: Method::Get, + name: "get_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/displayname", - params.user_id - ) + request { + /// The user whose display name will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/displayname" - } - - fn name() -> &'static str { - "get_display_name" - } - - fn description() -> &'static str { - "Get the display name of a user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option } } } - /// [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) pub mod set_display_name { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Set the display name of the user.", + method: Method::Put, + name: "set_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/displayname", - params.user_id - ) + request { + /// The new display name for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + /// The user whose display name will be set. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/displayname" - } - - fn name() -> &'static str { - "set_display_name" - } - - fn description() -> &'static str { - "Set the display name of the user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) pub mod get_avatar_url { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the avatar URL of a user.", + method: Method::Get, + name: "get_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/avatar_url", - params.user_id - ) + request { + /// The user whose avatar URL will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/avatar_url" - } - - fn name() -> &'static str { - "get_avatar_url" - } - - fn description() -> &'static str { - "Get the avatar URL of a user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option } } } /// [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) pub mod set_avatar_url { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Set the avatar URL of the user.", + method: Method::Put, + name: "set_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/avatar_url", - params.user_id - ) + request { + /// The new avatar URL for the user. + pub avatar_url: String, + /// The user whose avatar URL will be set. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/avatar_url" - } - - fn name() -> &'static str { - "set_avatar_url" - } - - fn description() -> &'static str { - "Set the avatar URL of the user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) pub mod get_profile { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get all profile information of an user.", + method: Method::Get, + name: "get_profile", + path: "/_matrix/client/r0/profile/:user_id", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}", - params.user_id - ) + request { + /// The user whose profile will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id" - } - - fn name() -> &'static str { - "get_profile" - } - - fn description() -> &'static str { - "Get all profile information of an user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option } } } From 651fe9b3e3df17e644f32d7fdf01cbfc4c8f96a9 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 00:57:29 -0700 Subject: [PATCH 075/350] Use ruma-api-macros for the receipt endpoints. --- src/lib.rs | 4 +-- src/r0/receipt.rs | 86 +++++++++++++++-------------------------------- 2 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ca041618..68f7e837 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,8 +31,8 @@ pub mod r0 { pub mod membership; pub mod presence; pub mod profile; -// pub mod push; -// pub mod receipt; + pub mod push; + pub mod receipt; // pub mod redact; pub mod room; // pub mod search; diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index f5bf20e2..51ec07d9 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -2,76 +2,44 @@ /// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) pub mod create_receipt { - use ruma_identifiers::{EventId, RoomId}; - use std::fmt::{Display, Error as FmtError, Formatter}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{EventId, RoomId}; - /// This endpoint's path parameters. - #[derive(Clone, Debug)] - pub struct PathParams { - /// The event ID to acknowledge up to. - pub event_id: EventId, - /// The type of receipt to send. - pub receipt_type: ReceiptType, - /// The room in which to send the event. - pub room_id: RoomId, + ruma_api! { + metadata { + description: "Send a receipt event to a room.", + method: Method::Post, + name: "create_receipt", + path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The event ID to acknowledge up to. + #[ruma_api(path)] + pub event_id: EventId, + /// The type of receipt to send. + #[ruma_api(path)] + pub receipt_type: ReceiptType, + /// The room in which to send the event. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response {} } /// The type of receipt. - #[derive(Clone, Copy, Debug)] + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum ReceiptType { /// m.read + #[serde(rename = "m.read")] Read, } - /// This API endpoint's response. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub struct Response; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post - } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/receipt/{}/{}", - params.room_id, - params.receipt_type, - params.event_id - ) - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id" - } - - fn name() -> &'static str { - "create_receipt" - } - - fn description() -> &'static str { - "Send a receipt event to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } - } - impl Display for ReceiptType { fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { match *self { From fc29d7bf40d43ab099da8671ae1d5aba52755038 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 01:11:11 -0700 Subject: [PATCH 076/350] Use ruma-api-macros for the redact endpoints. --- src/lib.rs | 2 +- src/r0/redact.rs | 86 +++++++++++++++--------------------------------- 2 files changed, 28 insertions(+), 60 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 68f7e837..67011de6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub mod r0 { pub mod profile; pub mod push; pub mod receipt; -// pub mod redact; + pub mod redact; pub mod room; // pub mod search; pub mod send; diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 6e0de442..ead9fbee 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -2,71 +2,39 @@ /// [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) pub mod redact_event { + use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, EventId}; - /// 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, - pub event_id: EventId, - pub txn_id: String - } - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub event_id: EventId, - } - - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Redact an event, stripping all information not critical to the event graph integrity.", + method: Method::Put, + name: "redact_event", + path: "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/redact/{}/{}", - params.room_id, - params.event_id, - params.txn_id - ) + request { + /// The ID of the event to redact. + #[ruma_api(path)] + pub event_id: EventId, + /// The reason for the redaction. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The ID of the room of the event to redact. + #[ruma_api(path)] + pub room_id: RoomId, + /// The transaction ID for this event. + /// + /// Clients should generate a unique ID; it will be used by the server to ensure idempotency of requests. + #[ruma_api(path)] + pub txn_id: String, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id" - } - - fn name() -> &'static str { - "redact_event" - } - - fn description() -> &'static str { - "Redact an event, stripping all information not critical to the event graph integrity." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// The ID of the redacted event. + pub event_id: EventId, } } } From e71760bb656fe1455a007f748787c82922d28fe4 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 22:50:56 -0700 Subject: [PATCH 077/350] Use ruma-api-macros for the search endpoints. --- src/lib.rs | 2 +- src/r0/profile.rs | 4 +- src/r0/search.rs | 96 +++++++++++++++++------------------------------ 3 files changed, 38 insertions(+), 64 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 67011de6..7e63f61f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,7 +35,7 @@ pub mod r0 { pub mod receipt; pub mod redact; pub mod room; -// pub mod search; + pub mod search; pub mod send; // pub mod server; pub mod session; diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 5f49499c..29769472 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -131,7 +131,7 @@ pub mod get_profile { request { /// The user whose profile will be retrieved. #[ruma_api(path)] - pub user_id: UserId + pub user_id: UserId, } response { @@ -140,7 +140,7 @@ pub mod get_profile { pub avatar_url: Option, /// The user's display name, if set. #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option + pub displayname: Option, } } } diff --git a/src/r0/search.rs b/src/r0/search.rs index c10d2919..9da4b959 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -2,19 +2,38 @@ /// [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 { + use std::collections::HashMap; + + use ruma_api_macros::ruma_api; use ruma_events::collections::all::Event; use ruma_identifiers::{EventId, RoomId, UserId}; 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. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - /// Describes which categories to search in and their criteria. - pub search_categories: Categories, + request { + /// The point to return events from. + /// + /// If given, this should be a `next_batch` result from a previous call to this endpoint. + #[ruma_api(query)] + pub next_batch: Option, + /// Describes which categories to search in and their criteria. + pub search_categories: Categories, + } + + response { + /// A grouping of search results by category. + pub search_categories: ResultCategories, + } } /// Categories of events that can be searched for. @@ -53,11 +72,6 @@ pub mod search_events { 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. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventContext { @@ -140,22 +154,6 @@ pub mod search_events { 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, - } - - /// 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. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ResultCategories { @@ -211,38 +209,14 @@ pub mod search_events { pub result: Event, } - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = 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/search" - } - - fn name() -> &'static str { - "search" - } - - fn description() -> &'static str { - "Search events." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + /// A user profile. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct UserProfile { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, } } From f94cb9d62a240a9f67d24dcec5dc323182db1a6f Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 22:59:42 -0700 Subject: [PATCH 078/350] Use ruma-api-macros for the server endpoints. --- src/lib.rs | 2 +- src/r0/server.rs | 85 +++++++++++++++--------------------------------- 2 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7e63f61f..c98becf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ pub mod r0 { pub mod room; pub mod search; pub mod send; -// pub mod server; + pub mod server; pub mod session; pub mod sync; // pub mod tag; diff --git a/src/r0/server.rs b/src/r0/server.rs index 1e5a64ac..0bf2fd95 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -2,9 +2,34 @@ /// [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid) pub mod get_user_info { + use std::collections::HashMap; + + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - use std::collections::HashMap; + ruma_api! { + metadata { + description: "Get information about a particular user.", + method: Method::Get, + name: "get_user_info", + path: "/_matrix/client/r0/admin/whois/:user_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The user to look up. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The Matrix user ID of the user. + pub user_id: UserId, + /// A map of the user's device identifiers to information about that device. + pub devices: HashMap, + } + } /// Information about a connection in a user session. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -24,68 +49,10 @@ pub mod get_user_info { pub sessions: Vec, } - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug)] - pub struct PathParams { - /// The user to look up. - pub user_id: UserId, - } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - /// The Matrix user ID of the user. - pub user_id: UserId, - /// A map of the user's device identifiers to information about that device. - pub devices: HashMap, - } - /// Information about a user session. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SessionInfo { /// A list of connections in this session. pub connections: Vec, } - - 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/admin/whois/{}", - params.user_id - ) - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/admin/whois/:user_id" - } - - fn name() -> &'static str { - "get_user_info" - } - - fn description() -> &'static str { - "Get information about a particular user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } - } } From 995fa6e1aefd3e9ac610688a64c49ee0f9086e50 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 23:26:52 -0700 Subject: [PATCH 079/350] Use ruma-api-macros for the tag endpoints. --- src/lib.rs | 2 +- src/r0/tag.rs | 207 ++++++++++++++++---------------------------------- 2 files changed, 65 insertions(+), 144 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c98becf0..7e183410 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ pub mod r0 { pub mod server; pub mod session; pub mod sync; -// pub mod tag; + pub mod tag; // pub mod typing; // pub mod voip; } diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 57754917..9f8b0370 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -2,177 +2,98 @@ /// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod create_tag { - use ruma_identifiers::{UserId, RoomId}; + use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; + use ruma_identifiers::{UserId, 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 { - pub user_id: UserId, - pub room_id: RoomId, - pub tag: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = TagInfo; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Add a new tag to a room.", + method: Method::Put, + name: "create_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", - params.user_id, - params.room_id, - params.tag - ) + request { + /// The room to tag. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to create. + #[ruma_api(path)] + pub tag: String, + /// Info about the tag. + #[ruma_api(body)] + pub tag_info: TagInfo, + /// The ID of the user creating the tag. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" - } - - fn name() -> &'static str { - "create_tag" - } - - fn description() -> &'static str { - "Add a new tag to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) pub mod get_tags { - use ruma_identifiers::{UserId, RoomId}; + use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; + use ruma_identifiers::{UserId, 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 { - pub user_id: UserId, - pub room_id: RoomId - } - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub tags: TagEventContent, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the tags associated with a room.", + method: Method::Get, + name: "get_tags", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags", - params.user_id, - params.room_id - ) + request { + /// The room from which tags will be retrieved. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user whose tags will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags" - } - - fn name() -> &'static str { - "get_tags" - } - - fn description() -> &'static str { - "Get the tags associated with a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// The user's tags for the room. + pub tags: TagEventContent, } } } /// [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod delete_tag { + use ruma_api_macros::ruma_api; use ruma_identifiers::{UserId, 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 { - pub user_id: UserId, - pub room_id: RoomId, - pub tag: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Delete + ruma_api! { + metadata { + description: "Remove a tag from a room.", + method: Method::Delete, + name: "delete_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", - params.user_id, - params.room_id, - params.tag - ) + request { + /// The tagged room. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to delete. + #[ruma_api(path)] + pub tag: String, + /// The user whose tag will be deleted. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" - } - - fn name() -> &'static str { - "delete_tag" - } - - fn description() -> &'static str { - "Remove a tag from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } From 0d9d1f811922e166b2612a164e1bb29c4278c854 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 7 Jul 2017 01:02:03 -0700 Subject: [PATCH 080/350] Use ruma-api-macros for the typing endpoints. --- src/lib.rs | 2 +- src/r0/typing.rs | 74 ++++++++++++++---------------------------------- 2 files changed, 23 insertions(+), 53 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7e183410..95e8bdca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ pub mod r0 { pub mod session; pub mod sync; pub mod tag; -// pub mod typing; + pub mod typing; // pub mod voip; } diff --git a/src/r0/typing.rs b/src/r0/typing.rs index aab5d3e9..b83a632d 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -2,63 +2,33 @@ /// [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) pub mod create_typing_event { + use ruma_api_macros::ruma_api; use ruma_identifiers::{UserId, 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 { - pub room_id: RoomId, - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub typing: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + method: Method::Put, + path: "/_matrix/client/r0/rooms/:room_id/typing/:user_id", + name: "create_typing_event", + description: "Send a typing event to a room.", + requires_authentication: true, + rate_limited: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/typing/{}", - params.room_id, - params.user_id - ) + request { + /// The room in which the user is typing. + #[ruma_api(path)] + pub room_id: RoomId, + /// The length of time in milliseconds to mark this user as typing. + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. + pub typing: bool, + /// The user who has started to type. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/typing/:user_id" - } - - fn name() -> &'static str { - "create_typing_event" - } - - fn description() -> &'static str { - "Send a typing event to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } From 863fe814efbc4b7739acc1f8ab5f17d2ee8b75c8 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 7 Jul 2017 01:08:03 -0700 Subject: [PATCH 081/350] Use ruma-api-macros for the voip endpoints. --- src/lib.rs | 2 +- src/r0/voip.rs | 60 ++++++++++++++++---------------------------------- 2 files changed, 20 insertions(+), 42 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95e8bdca..28231ced 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ pub mod r0 { pub mod sync; pub mod tag; pub mod typing; -// pub mod voip; + pub mod voip; } pub mod unversioned; diff --git a/src/r0/voip.rs b/src/r0/voip.rs index acb85720..4baa289e 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -2,51 +2,29 @@ /// [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) pub mod get_turn_server_info { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub username: String, - pub password: String, - pub uris: Vec, - pub ttl: u64 - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get credentials for the client to use when initiating VoIP calls.", + method: Method::Get, + name: "turn_server_info", + path: "_matrix/client/r0/voip/turnServer", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } + request {} - fn router_path() -> &'static str { - "_matrix/client/r0/voip/turnServer" - } - - fn name() -> &'static str { - "turn_server_info" - } - - fn description() -> &'static str { - "Get credentials for the client to use when initiating VoIP calls." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true + response { + /// The password to use. + pub password: String, + /// The time-to-live in seconds. + pub ttl: u64, + /// A list of TURN URIs. + pub uris: Vec, + /// The username to use. + pub username: String, } } } From 3cbbf10587f1dc0fe30ef4d897b51b1bb6b7a1b8 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 7 Jul 2017 01:31:15 -0700 Subject: [PATCH 082/350] Use ruma-api 0.4.0 and ruma-api-macros 0.1.0. --- Cargo.toml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79825822..285fd0d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Jimmy Cuadra "] -description = "Serializable request and response types for the Matrix client API." +description = "Types for the endpoints in the Matrix client-server API." documentation = "https://docs.rs/ruma-client-api" homepage = "https://github.com/ruma/ruma-client-api" keywords = ["matrix", "chat", "messaging", "ruma"] @@ -12,20 +12,14 @@ version = "0.1.0" [dependencies] futures = "0.1.14" -hyper = "0.11" +hyper = "0.11.1" +ruma-api = "0.4.0" +ruma-api-macros = "0.1.0" ruma-events = "0.9.0" ruma-identifiers = "0.11.0" ruma-signatures = "0.4.0" -serde = "1.0.2" -serde_derive = "1.0.2" -serde_json = "1.0.1" +serde = "1.0.9" +serde_derive = "1.0.9" +serde_json = "1.0.2" serde_urlencoded = "0.5.1" url = "1.5.1" - -[dependencies.ruma-api] -git = "https://github.com/ruma/ruma-api" -rev = "4893be93f86543f9a9e3c5d7205afba769b84aa6" - -[dependencies.ruma-api-macros] -git = "https://github.com/ruma/ruma-api-macros" -rev = "0f32ca01dbf75aeab91937e421dfaa2d1f67351a" From 46fa6d21a21b68c835c4cfd5d0538e4a79dcd1ef Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 17 Jul 2017 18:57:22 +0200 Subject: [PATCH 083/350] Fix timeline.events type in sync_events response --- src/r0/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index b846f99a..78603e65 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -319,7 +319,7 @@ pub mod sync_events { /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, /// A list of events. - pub events: Vec, + pub events: Vec, } /// State events in the room. From fcd2a50f4f78ba473b1258789c2ef123b5a31263 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 3 Aug 2017 22:42:08 +0200 Subject: [PATCH 084/350] UnreadNotificationsCount: Make fields optional --- src/r0/sync.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 78603e65..b698d6ec 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -305,9 +305,11 @@ pub mod sync_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. - pub highlight_count: u64, + #[serde(skip_serializing_if = "Option::is_none")] + pub highlight_count: Option, /// The total number of unread notifications for this room. - pub notification_count: u64, + #[serde(skip_serializing_if = "Option::is_none")] + pub notification_count: Option, } /// Events in the room. From 15bd7d2641745637fc755dede87b30461a0fe3fe Mon Sep 17 00:00:00 2001 From: tilpner Date: Thu, 28 Sep 2017 20:28:24 +0200 Subject: [PATCH 085/350] Pass sync request as query parameters instead of data Before, it would silently ignore them for defaults, so long-polling was not possible because no timeout was passed --- src/r0/sync.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index b698d6ec..5b897fdc 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -219,18 +219,23 @@ pub mod sync_events { request { /// A filter represented either as its full JSON definition or the ID of a saved filter. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub filter: Option, /// A point in time to continue a sync from. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub since: Option, /// Controls whether to include the full state for all rooms the user is a member of. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub full_state: Option, /// Controls whether the client is automatically marked as online by polling this API. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub set_presence: Option, /// The maximum time to poll in milliseconds before returning this request. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub timeout: Option, } From 478106fd427ed695db5a2c2cc7429295ce3a36e7 Mon Sep 17 00:00:00 2001 From: tilpner Date: Thu, 28 Sep 2017 20:30:28 +0200 Subject: [PATCH 086/350] Serialize sync_events::Filter untagged This is to make Filter::FilterId(String::from("0")) serialize as "0", instead of to a JSON object that cannot be passed as a query paramater --- src/r0/sync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 5b897fdc..7a45c35b 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -260,6 +260,7 @@ pub mod sync_events { /// A filter represented either as its full JSON definition or the ID of a saved filter. #[derive(Clone, Debug, Deserialize, Serialize)] + #[serde(untagged)] pub enum Filter { /// A complete filter definition serialized to JSON. FilterDefinition(FilterDefinition), From 60d0428730bc972e32c915c43f77d05bc548239c Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Tue, 17 Oct 2017 23:52:05 +1300 Subject: [PATCH 087/350] associated_consts stabilized Since rust 1.20 --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 28231ced..c69887fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ //! shared by client and server code. #![deny(missing_debug_implementations, missing_docs)] -#![feature(associated_consts, proc_macro, try_from)] +#![feature(proc_macro, try_from)] extern crate futures; extern crate hyper; From acac994a18da9044e405cff85524fc1addda4ab4 Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Thu, 25 Jan 2018 17:13:18 +1300 Subject: [PATCH 088/350] r0.3.0/login: Add device_id to request & response Version 0.3.0 of the client-server spec adds a `device_id` field to the login request and response. It is optional in the request. See https://matrix.org/docs/spec/client_server/r0.3.0.html#post-matrix-client-r0-login for details. I don't think this will be backwards compatible with ruma-client. --- src/r0/session.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/r0/session.rs b/src/r0/session.rs index b08c9b85..386878d3 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -28,7 +28,10 @@ pub mod login { pub user: String, /// Third party identifier for the user. #[serde(skip_serializing_if = "Option::is_none")] - pub address: Option + pub address: Option, + /// ID of the client device + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, } response { @@ -42,6 +45,11 @@ pub mod login { pub refresh_token: Option, /// The fully-qualified Matrix ID that has been registered. pub user_id: UserId, + /// ID of the logged-in device. + /// + /// Will be the same as the corresponging parameter in the request, if one was + /// specified. + pub device_id: String, } } From 000b4af1b25e3e4ff8e2539151d91d5abacb14fd Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Thu, 17 May 2018 17:48:09 +0200 Subject: [PATCH 089/350] RoomFilter: fix typo nevertheless a breaking change --- src/r0/filter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 4ee3265a..7e658f47 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -97,7 +97,7 @@ pub struct RoomFilter { /// filters in `ephemeral`, `state`, `timeline` or `account_data`. #[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default)] - pub room: Vec, + pub rooms: Vec, } /// Filter for not-room data From ca99939ca632e8fcf022573d3641a2ca8ba3d01f Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Thu, 17 May 2018 19:08:21 +0200 Subject: [PATCH 090/350] /rooms/{room_id}/members requires authentication it was just an omission from the spec. See https://github.com/matrix-org/matrix-doc/pull/1244 --- src/r0/sync.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 7a45c35b..b387b41a 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -113,10 +113,7 @@ pub mod get_member_events { 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... + requires_authentication: true, } request { From d042f631464050e25fda7aecd11f8981078ce00a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 19 May 2018 02:28:35 -0700 Subject: [PATCH 091/350] Update dependencies and convert to ruma-api-macros 0.2. --- Cargo.toml | 20 ++++++++++---------- src/lib.rs | 2 +- src/r0/account.rs | 10 +++++----- src/r0/alias.rs | 6 +++--- src/r0/config.rs | 4 ++-- src/r0/contact.rs | 6 +++--- src/r0/context.rs | 2 +- src/r0/directory.rs | 2 +- src/r0/filter.rs | 4 ++-- src/r0/media.rs | 20 +++++++++----------- src/r0/membership.rs | 16 ++++++++-------- src/r0/presence.rs | 8 ++++---- src/r0/profile.rs | 10 +++++----- src/r0/receipt.rs | 2 +- src/r0/redact.rs | 2 +- src/r0/room.rs | 2 +- src/r0/search.rs | 2 +- src/r0/send.rs | 6 +++--- src/r0/server.rs | 2 +- src/r0/session.rs | 4 ++-- src/r0/sync.rs | 12 ++++++------ src/r0/tag.rs | 6 +++--- src/r0/typing.rs | 2 +- src/r0/voip.rs | 2 +- src/unversioned.rs | 2 +- 25 files changed, 76 insertions(+), 78 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 285fd0d6..9c27751c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,15 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -futures = "0.1.14" -hyper = "0.11.1" -ruma-api = "0.4.0" -ruma-api-macros = "0.1.0" -ruma-events = "0.9.0" +futures = "0.1.21" +http = "0.1.5" +ruma-api = "0.5.0" +ruma-api-macros = "0.2.2" +ruma-events = "0.10.0" ruma-identifiers = "0.11.0" ruma-signatures = "0.4.0" -serde = "1.0.9" -serde_derive = "1.0.9" -serde_json = "1.0.2" -serde_urlencoded = "0.5.1" -url = "1.5.1" +serde = "1.0.57" +serde_derive = "1.0.57" +serde_json = "1.0.17" +serde_urlencoded = "0.5.2" +url = "1.7.0" diff --git a/src/lib.rs b/src/lib.rs index c69887fa..0edbb06c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ #![feature(proc_macro, try_from)] extern crate futures; -extern crate hyper; +extern crate http; extern crate ruma_api; extern crate ruma_api_macros; extern crate ruma_events; diff --git a/src/r0/account.rs b/src/r0/account.rs index 7daac47b..d60fbe12 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -8,7 +8,7 @@ pub mod register { ruma_api! { metadata { description: "Register an account on this homeserver.", - method: Method::Post, + method: POST, name: "register", path: "/_matrix/client/r0/register", rate_limited: true, @@ -105,7 +105,7 @@ pub mod request_password_change_token { ruma_api! { metadata { description: "Request that a password change token is sent to the given email address.", - method: Method::Post, + method: POST, name: "request_password_change_token", path: "/_matrix/client/r0/account/password/email/requestToken", rate_limited: false, @@ -137,7 +137,7 @@ pub mod deactivate { ruma_api! { metadata { description: "Deactivate the current user's account.", - method: Method::Post, + method: POST, name: "deactivate", path: "/_matrix/client/r0/account/deactivate", rate_limited: true, @@ -157,7 +157,7 @@ pub mod change_password { ruma_api! { metadata { description: "Change the password of the current user's account.", - method: Method::Post, + method: POST, name: "change_password", path: "/_matrix/client/r0/account/password", rate_limited: true, @@ -181,7 +181,7 @@ pub mod request_register_token { ruma_api! { metadata { description: "Request a register token with a 3rd party email.", - method: Method::Post, + method: POST, name: "request_register_token", path: "/_matrix/client/r0/register/email/requestToken", rate_limited: true, diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 66d86f59..c102f867 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -8,7 +8,7 @@ pub mod create_alias { ruma_api! { metadata { description: "Add an alias to a room.", - method: Method::Put, + method: PUT, name: "create_alias", path: "/_matrix/client/r0/directory/room/:room_alias", rate_limited: false, @@ -35,7 +35,7 @@ pub mod delete_alias { ruma_api! { metadata { description: "Remove an alias from a room.", - method: Method::Delete, + method: DELETE, name: "delete_alias", path: "/_matrix/client/r0/directory/room/:room_alias", rate_limited: false, @@ -60,7 +60,7 @@ pub mod get_alias { ruma_api! { metadata { description: "Resolve a room alias to a room ID.", - method: Method::Get, + method: GET, name: "get_alias", path: "/_matrix/client/r0/directory/room/:room_alias", rate_limited: false, diff --git a/src/r0/config.rs b/src/r0/config.rs index 31b5e844..51336a2f 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -9,7 +9,7 @@ pub mod set_room_account_data { ruma_api! { metadata { description: "Associate account data with a room.", - method: Method::Put, + method: PUT, name: "set_room_account_data", path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", rate_limited: false, @@ -48,7 +48,7 @@ pub mod set_global_account_data { ruma_api! { metadata { description: "Sets global account data.", - method: Method::Put, + method: PUT, name: "set_global_account_data", path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", rate_limited: false, diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 4a9bdcc0..896e0a26 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -7,7 +7,7 @@ pub mod create_contact { ruma_api! { metadata { description: "Adds contact information to the user's account.", - method: Method::Post, + method: POST, name: "create_contact", path: "/_matrix/client/r0/account/3pid", rate_limited: false, @@ -47,7 +47,7 @@ pub mod get_contacts { ruma_api! { metadata { description: "Get a list of 3rd party contacts associated with the user's account.", - method: Method::Get, + method: GET, name: "get_contacts", path: "/_matrix/client/r0/account/3pid", rate_limited: false, @@ -88,7 +88,7 @@ pub mod request_contact_verification_token { ruma_api! { metadata { description: "Ask for a verification token for a given 3rd party ID.", - method: Method::Post, + method: POST, name: "request_contact_verification_token", path: "/_matrix/client/r0/account/3pid/email/requestToken", rate_limited: false, diff --git a/src/r0/context.rs b/src/r0/context.rs index d37e2349..07fb825f 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -9,7 +9,7 @@ pub mod get_context { ruma_api! { metadata { description: "Get the events immediately preceding and following a given event.", - method: Method::Get, + method: GET, path: "/_matrix/client/r0/rooms/:room_id/context/:event_id", name: "get_context", rate_limited: false, diff --git a/src/r0/directory.rs b/src/r0/directory.rs index fc1c4c17..6b513fef 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -8,7 +8,7 @@ pub mod get_public_rooms { ruma_api! { metadata { description: "Get the list of rooms in this homeserver's public directory.", - method: Method::Get, + method: GET, name: "get_public_rooms", path: "/_matrix/client/r0/publicRooms", rate_limited: false, diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 7e658f47..4ee85985 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -175,7 +175,7 @@ pub mod create_filter { ruma_api! { metadata { description: "Create a new filter for event retrieval.", - method: Method::Post, + method: POST, name: "create_filter", path: "/_matrix/client/r0/user/:user_id/filter", rate_limited: false, @@ -210,7 +210,7 @@ pub mod get_filter { ruma_api! { metadata { description: "Retrieve a previously created filter.", - method: Method::Get, + method: GET, name: "get_filter", path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", rate_limited: false, diff --git a/src/r0/media.rs b/src/r0/media.rs index 668aabc7..0b51c95d 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -2,13 +2,12 @@ /// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) pub mod get_content { - use hyper::header::{ContentDisposition, ContentType}; use ruma_api_macros::ruma_api; ruma_api! { metadata { description: "Retrieve content from the media store.", - method: Method::Get, + method: GET, name: "get_media_content", path: "/_matrix/media/r0/download/:server_name/:media_id", rate_limited: false, @@ -29,24 +28,23 @@ pub mod get_content { #[ruma_api(body)] pub file: Vec, /// The content type of the file that was previously uploaded. - #[ruma_api(header)] - pub content_type: ContentType, + #[ruma_api(header = "CONTENT_TYPE")] + pub content_type: String, /// The name of the file that was previously uploaded, if set. - #[ruma_api(header)] - pub content_disposition: ContentDisposition, + #[ruma_api(header = "CONTENT_DISPOSITION")] + pub content_disposition: String, } } } /// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) pub mod create_content { - use hyper::header::ContentType; use ruma_api_macros::ruma_api; ruma_api! { metadata { description: "Upload content to the media store.", - method: Method::Post, + method: POST, name: "create_media_content", path: "/_matrix/media/r0/upload", rate_limited: false, @@ -55,8 +53,8 @@ pub mod create_content { request { /// The content type of the file being uploaded. - #[ruma_api(header)] - pub content_type: ContentType, + #[ruma_api(header = "CONTENT_TYPE")] + pub content_type: String, } response { @@ -84,7 +82,7 @@ pub mod get_content_thumbnail { ruma_api! { metadata { description: "Get a thumbnail of content from the media store.", - method: Method::Get, + method: GET, name: "get_content_thumbnail", path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", rate_limited: false, diff --git a/src/r0/membership.rs b/src/r0/membership.rs index ed0b1552..ae002046 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -27,7 +27,7 @@ pub mod invite_user { ruma_api! { metadata { description: "Invite a user to a room.", - method: Method::Post, + method: POST, name: "invite_user", path: "/_matrix/client/r0/rooms/:room_id/invite", rate_limited: true, @@ -56,7 +56,7 @@ pub mod join_room_by_id_or_alias { ruma_api! { metadata { description: "Join a room using its ID or one of its aliases.", - method: Method::Post, + method: POST, name: "join_room_by_id_or_alias", path: "/_matrix/client/r0/join/:room_id_or_alias", rate_limited: true, @@ -90,7 +90,7 @@ pub mod join_room_by_id { ruma_api! { metadata { description: "Join a room using its ID.", - method: Method::Post, + method: POST, name: "join_room_by_id", path: "/_matrix/client/r0/rooms/:room_id/join", rate_limited: true, @@ -122,7 +122,7 @@ pub mod forget_room { ruma_api! { metadata { description: "Forget a room.", - method: Method::Post, + method: POST, name: "forget_room", path: "/_matrix/client/r0/rooms/:room_id/forget", rate_limited: true, @@ -147,7 +147,7 @@ pub mod leave_room { ruma_api! { metadata { description: "Leave a room.", - method: Method::Post, + method: POST, name: "leave_room", path: "/_matrix/client/r0/rooms/:room_id/leave", rate_limited: true, @@ -172,7 +172,7 @@ pub mod kick_user { ruma_api! { metadata { description: "Kick a user from a room.", - method: Method::Post, + method: POST, name: "kick_user", path: "/_matrix/client/r0/rooms/:room_id/kick", rate_limited: false, @@ -202,7 +202,7 @@ pub mod unban_user { ruma_api! { metadata { description: "Unban a user from a room.", - method: Method::Post, + method: POST, name: "unban_user", path: "/_matrix/client/r0/rooms/:room_id/unban", rate_limited: false, @@ -229,7 +229,7 @@ pub mod ban_user { ruma_api! { metadata { description: "Ban a user from a room.", - method: Method::Post, + method: POST, name: "ban_user", path: "/_matrix/client/r0/rooms/:room_id/ban", rate_limited: false, diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 5b29b7e1..7d961e5e 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -9,7 +9,7 @@ pub mod set_presence { ruma_api! { metadata { description: "Set presence status for this user.", - method: Method::Put, + method: PUT, name: "set_presence", path: "/_matrix/client/r0/presence/:user_id/status", rate_limited: true, @@ -40,7 +40,7 @@ pub mod get_presence { ruma_api! { metadata { description: "Get presence status for this user.", - method: Method::Get, + method: GET, name: "get_presence", path: "/_matrix/client/r0/presence/:user_id/status", rate_limited: false, @@ -77,7 +77,7 @@ pub mod update_presence_subscriptions { ruma_api! { metadata { description: "Update the presence subscriptions of the user.", - method: Method::Post, + method: POST, name: "update_presence_subscriptions", path: "/_matrix/client/r0/presence/list/:user_id", rate_limited: true, @@ -111,7 +111,7 @@ pub mod get_subscribed_presences { ruma_api! { metadata { description: "Get the precence status from the user's subscriptions.", - method: Method::Get, + method: GET, name: "get_subscribed_presences", path: "/_matrix/client/r0/presence/list/:user_id", rate_limited: false, diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 29769472..83440464 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -8,7 +8,7 @@ pub mod get_display_name { ruma_api! { metadata { description: "Get the display name of a user.", - method: Method::Get, + method: GET, name: "get_display_name", path: "/_matrix/client/r0/profile/:user_id/displayname", rate_limited: false, @@ -37,7 +37,7 @@ pub mod set_display_name { ruma_api! { metadata { description: "Set the display name of the user.", - method: Method::Put, + method: PUT, name: "set_display_name", path: "/_matrix/client/r0/profile/:user_id/displayname", rate_limited: true, @@ -65,7 +65,7 @@ pub mod get_avatar_url { ruma_api! { metadata { description: "Get the avatar URL of a user.", - method: Method::Get, + method: GET, name: "get_avatar_url", path: "/_matrix/client/r0/profile/:user_id/avatar_url", rate_limited: false, @@ -94,7 +94,7 @@ pub mod set_avatar_url { ruma_api! { metadata { description: "Set the avatar URL of the user.", - method: Method::Put, + method: PUT, name: "set_avatar_url", path: "/_matrix/client/r0/profile/:user_id/avatar_url", rate_limited: true, @@ -121,7 +121,7 @@ pub mod get_profile { ruma_api! { metadata { description: "Get all profile information of an user.", - method: Method::Get, + method: GET, name: "get_profile", path: "/_matrix/client/r0/profile/:user_id", rate_limited: false, diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index 51ec07d9..fcabd686 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -10,7 +10,7 @@ pub mod create_receipt { ruma_api! { metadata { description: "Send a receipt event to a room.", - method: Method::Post, + method: POST, name: "create_receipt", path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", rate_limited: true, diff --git a/src/r0/redact.rs b/src/r0/redact.rs index ead9fbee..5d83a5a6 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -8,7 +8,7 @@ pub mod redact_event { ruma_api! { metadata { description: "Redact an event, stripping all information not critical to the event graph integrity.", - method: Method::Put, + method: PUT, name: "redact_event", path: "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", rate_limited: false, diff --git a/src/r0/room.rs b/src/r0/room.rs index a7da4473..1435497e 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -8,7 +8,7 @@ pub mod create_room { ruma_api! { metadata { description: "Create a new room.", - method: Method::Post, + method: POST, name: "create_room", path: "/_matrix/client/r0/createRoom", rate_limited: false, diff --git a/src/r0/search.rs b/src/r0/search.rs index 9da4b959..ff6f2cb6 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -13,7 +13,7 @@ pub mod search_events { ruma_api! { metadata { description: "Search events.", - method: Method::Post, + method: POST, name: "search", path: "/_matrix/client/r0/search", rate_limited: true, diff --git a/src/r0/send.rs b/src/r0/send.rs index ddf26bcc..21cd1e55 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -10,7 +10,7 @@ pub mod send_state_event_for_empty_key { ruma_api! { metadata { description: "Send a state event to a room associated with the empty state key.", - method: Method::Put, + method: PUT, name: "send_state_event_for_empty_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type", rate_limited: false, @@ -46,7 +46,7 @@ pub mod send_state_event_for_key { ruma_api! { metadata { description: "Send a state event to a room associated with a given state key.", - method: Method::Put, + method: PUT, name: "send_state_event_for_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", rate_limited: false, @@ -85,7 +85,7 @@ pub mod send_message_event { ruma_api! { metadata { description: "Send a message event to a room.", - method: Method::Put, + method: PUT, name: "send_message_event", path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", rate_limited: false, diff --git a/src/r0/server.rs b/src/r0/server.rs index 0bf2fd95..844b3263 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -10,7 +10,7 @@ pub mod get_user_info { ruma_api! { metadata { description: "Get information about a particular user.", - method: Method::Get, + method: GET, name: "get_user_info", path: "/_matrix/client/r0/admin/whois/:user_id", rate_limited: false, diff --git a/src/r0/session.rs b/src/r0/session.rs index 386878d3..e96fd77a 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -8,7 +8,7 @@ pub mod login { ruma_api! { metadata { description: "Login to the homeserver.", - method: Method::Post, + method: POST, name: "login", path: "/_matrix/client/r0/login", rate_limited: true, @@ -77,7 +77,7 @@ pub mod logout { ruma_api! { metadata { description: "Log out of the homeserver.", - method: Method::Post, + method: POST, name: "logout", path: "/_matrix/client/r0/logout", rate_limited: false, diff --git a/src/r0/sync.rs b/src/r0/sync.rs index b387b41a..975141ba 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -9,7 +9,7 @@ pub mod get_state_events { ruma_api! { metadata { description: "Get state events for a room.", - method: Method::Get, + method: GET, name: "get_state_events", path: "/_matrix/client/r0/rooms/:room_id/state", rate_limited: false, @@ -41,7 +41,7 @@ pub mod get_state_events_for_empty_key { ruma_api! { metadata { description: "Get state events of a given type associated with the empty key.", - method: Method::Get, + method: GET, name: "get_state_events_for_empty_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type", rate_limited: false, @@ -73,7 +73,7 @@ pub mod get_state_events_for_key { ruma_api! { metadata { description: "Get state events associated with a given key.", - method: Method::Get, + method: GET, name: "get_state_events_for_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", rate_limited: false, @@ -109,7 +109,7 @@ pub mod get_member_events { ruma_api! { metadata { description: "Get membership events for a room.", - method: Method::Get, + method: GET, name: "get_member_events", path: "/_matrix/client/r0/rooms/:room_id/members", rate_limited: false, @@ -138,7 +138,7 @@ pub mod get_message_events { ruma_api! { metadata { description: "Get message events for a room.", - method: Method::Get, + method: GET, name: "get_message_events", path: "/_matrix/client/r0/rooms/:room_id/messages", rate_limited: false, @@ -206,7 +206,7 @@ pub mod sync_events { ruma_api! { metadata { description: "Get all new events from all rooms since the last sync or a given point of time.", - method: Method::Get, + method: GET, name: "sync", path: "/_matrix/client/r0/sync", rate_limited: false, diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 9f8b0370..f6e5e333 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -9,7 +9,7 @@ pub mod create_tag { ruma_api! { metadata { description: "Add a new tag to a room.", - method: Method::Put, + method: PUT, name: "create_tag", path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", rate_limited: false, @@ -44,7 +44,7 @@ pub mod get_tags { ruma_api! { metadata { description: "Get the tags associated with a room.", - method: Method::Get, + method: GET, name: "get_tags", path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", rate_limited: false, @@ -75,7 +75,7 @@ pub mod delete_tag { ruma_api! { metadata { description: "Remove a tag from a room.", - method: Method::Delete, + method: DELETE, name: "delete_tag", path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", rate_limited: false, diff --git a/src/r0/typing.rs b/src/r0/typing.rs index b83a632d..eac4f8e8 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -7,7 +7,7 @@ pub mod create_typing_event { ruma_api! { metadata { - method: Method::Put, + method: PUT, path: "/_matrix/client/r0/rooms/:room_id/typing/:user_id", name: "create_typing_event", description: "Send a typing event to a room.", diff --git a/src/r0/voip.rs b/src/r0/voip.rs index 4baa289e..a83ed694 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -7,7 +7,7 @@ pub mod get_turn_server_info { ruma_api! { metadata { description: "Get credentials for the client to use when initiating VoIP calls.", - method: Method::Get, + method: GET, name: "turn_server_info", path: "_matrix/client/r0/voip/turnServer", rate_limited: true, diff --git a/src/unversioned.rs b/src/unversioned.rs index 0c1dc831..7c4be014 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -7,7 +7,7 @@ pub mod get_supported_versions { ruma_api! { metadata { description: "Get the versions of the client-server API supported by this homeserver.", - method: Method::Get, + method: GET, name: "api_versions", path: "/_matrix/client/versions", rate_limited: false, From 7112b79859854cce351df2ae13ce8de99ff2d58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Sat, 25 Aug 2018 16:07:12 +0200 Subject: [PATCH 092/350] Add hyper for new version of ruma-api --- Cargo.toml | 1 + src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9c27751c..0431d930 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ version = "0.1.0" [dependencies] futures = "0.1.21" http = "0.1.5" +hyper = "0.12" ruma-api = "0.5.0" ruma-api-macros = "0.2.2" ruma-events = "0.10.0" diff --git a/src/lib.rs b/src/lib.rs index 0edbb06c..7a62c6f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ extern crate futures; extern crate http; +extern crate hyper; extern crate ruma_api; extern crate ruma_api_macros; extern crate ruma_events; From 58d06f82a2ee2d062c6c17b292bde520c088ca65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Fri, 31 Aug 2018 14:04:42 +0200 Subject: [PATCH 093/350] Fix Rust's hint about proc_macro The feature `proc_macro` has been stable since 1.29.0 and no longer requires an attribute to enable --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7a62c6f9..746f2bfa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ //! shared by client and server code. #![deny(missing_debug_implementations, missing_docs)] -#![feature(proc_macro, try_from)] +#![feature(try_from)] extern crate futures; extern crate http; From 07e079bb8decd4b41a26013d23855c34aee83cb7 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 8 Sep 2018 13:25:16 +0200 Subject: [PATCH 094/350] get_subscribed_presences::Response::presence_events should be public --- src/r0/presence.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 7d961e5e..c9d03344 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -127,7 +127,7 @@ pub mod get_subscribed_presences { response { /// A list of presence events for every user on this list. #[ruma_api(body)] - presence_events: Vec, + pub presence_events: Vec, } } } From ec8198964a821f3c092823152ad931bfd9bdc132 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Tue, 11 Sep 2018 14:10:31 +0200 Subject: [PATCH 095/350] get_state_events_for_key::Request::event_type should be of type EventType --- src/r0/sync.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 975141ba..1952d55d 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -68,6 +68,7 @@ pub mod get_state_events_for_empty_key { /// [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_events::EventType; use ruma_identifiers::RoomId; ruma_api! { @@ -86,7 +87,7 @@ pub mod get_state_events_for_key { pub room_id: RoomId, /// The type of state to look up. #[ruma_api(path)] - pub event_type: String, + pub event_type: EventType, /// The key of the state to look up. #[ruma_api(path)] pub state_key: String, From eb6f2518efda9bc3b274efb02577a344e7bfd4a4 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Tue, 11 Sep 2018 14:12:11 +0200 Subject: [PATCH 096/350] get_supported_versions does not require authentication --- src/unversioned.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unversioned.rs b/src/unversioned.rs index 7c4be014..cb152fb0 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -11,7 +11,7 @@ pub mod get_supported_versions { name: "api_versions", path: "/_matrix/client/versions", rate_limited: false, - requires_authentication: true, + requires_authentication: false, } request {} From c281dc662c5351b213c427f6bd2c6903102db076 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 3 Dec 2018 19:22:52 -0800 Subject: [PATCH 097/350] Update dependencies. --- Cargo.toml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0431d930..d35dd124 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,16 @@ repository = "https://github.com/ruma/ruma-client-api" version = "0.1.0" [dependencies] -futures = "0.1.21" -http = "0.1.5" -hyper = "0.12" -ruma-api = "0.5.0" -ruma-api-macros = "0.2.2" -ruma-events = "0.10.0" +futures = "0.1.25" +http = "0.1.14" +hyper = "0.12.16" +ruma-api = "0.6.0" +ruma-api-macros = "0.3.0" +ruma-events = "0.11.0" ruma-identifiers = "0.11.0" -ruma-signatures = "0.4.0" -serde = "1.0.57" -serde_derive = "1.0.57" -serde_json = "1.0.17" -serde_urlencoded = "0.5.2" -url = "1.7.0" +ruma-signatures = "0.4.1" +serde = "1.0.80" +serde_derive = "1.0.80" +serde_json = "1.0.33" +serde_urlencoded = "0.5.4" +url = "1.7.2" From 8bf2f2a024d1b200317b6e3f1776e8dae29d25d7 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 3 Dec 2018 20:35:33 -0800 Subject: [PATCH 098/350] Bump version to 0.2.0. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d35dd124..6a26e87e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.1.0" +version = "0.2.0" [dependencies] futures = "0.1.25" From 7a7697e9e25fd54c6c116d0db44c69cbc3f96b1e Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 8 Jan 2019 16:12:10 +0100 Subject: [PATCH 099/350] InviteState in Sync response is stripped events --- src/r0/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 1952d55d..8a4e66de 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -199,7 +199,7 @@ pub mod sync_events { use std::collections::HashMap; use ruma_api_macros::ruma_api; - use ruma_events::collections::{all, only}; + use ruma_events::{collections::{all, only}, stripped}; use ruma_identifiers::RoomId; use r0::filter::FilterDefinition; @@ -360,7 +360,7 @@ pub mod sync_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InviteState { /// A list of state events. - pub events: Vec, + pub events: Vec, } /// Updates to the presence status of other users. From 586bca680db489ccafa4a07ec7f8ad41a2dc4ea0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 13 Jan 2019 21:12:33 +0100 Subject: [PATCH 100/350] Re-run 'cargo fmt' --- src/lib.rs | 3 ++- src/r0/account.rs | 6 +++--- src/r0/config.rs | 2 +- src/r0/contact.rs | 2 +- src/r0/context.rs | 4 ++-- src/r0/directory.rs | 2 +- src/r0/membership.rs | 2 +- src/r0/presence.rs | 2 +- src/r0/redact.rs | 2 +- src/r0/room.rs | 10 +++++----- src/r0/search.rs | 18 +++++++++--------- src/r0/send.rs | 8 ++++---- src/r0/sync.rs | 11 +++++++---- src/r0/tag.rs | 6 +++--- src/r0/typing.rs | 2 +- 15 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 746f2bfa..3695492f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,8 @@ extern crate ruma_identifiers; extern crate ruma_signatures; extern crate serde; extern crate serde_json; -#[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_derive; extern crate serde_urlencoded; extern crate url; diff --git a/src/r0/account.rs b/src/r0/account.rs index d60fbe12..32aba8de 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -81,7 +81,7 @@ pub mod register { #[serde(rename = "type")] kind: String, /// The value of the session key given by the homeserver. - session: Option + session: Option, } /// The kind of account being registered. @@ -90,10 +90,10 @@ pub mod register { /// A guest account /// /// These accounts may have limited permissions and may not be supported by all servers. - #[serde(rename="guest")] + #[serde(rename = "guest")] Guest, /// A regular user account - #[serde(rename="user")] + #[serde(rename = "user")] User, } } diff --git a/src/r0/config.rs b/src/r0/config.rs index 51336a2f..975b3ea0 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -40,7 +40,7 @@ pub mod set_room_account_data { } /// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) -pub mod set_global_account_data { +pub mod set_global_account_data { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; use serde_json::Value; diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 896e0a26..2f646be2 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -67,7 +67,7 @@ pub mod get_contacts { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Medium { /// An email address. - #[serde(rename="email")] + #[serde(rename = "email")] Email, } diff --git a/src/r0/context.rs b/src/r0/context.rs index 07fb825f..261f0b3b 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -2,9 +2,9 @@ /// [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) pub mod get_context { - use ruma_identifiers::{EventId, RoomId}; - use ruma_events::collections::only; use ruma_api_macros::ruma_api; + use ruma_events::collections::only; + use ruma_identifiers::{EventId, RoomId}; ruma_api! { metadata { diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 6b513fef..7a00037b 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -2,8 +2,8 @@ /// [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) pub mod get_public_rooms { - use ruma_identifiers::{RoomId, RoomAliasId}; use ruma_api_macros::ruma_api; + use ruma_identifiers::{RoomAliasId, RoomId}; ruma_api! { metadata { diff --git a/src/r0/membership.rs b/src/r0/membership.rs index ae002046..a8dc7503 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -22,7 +22,7 @@ pub struct ThirdPartySigned { /// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) pub mod invite_user { use ruma_api_macros::ruma_api; - use ruma_identifiers::{UserId, RoomId}; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { diff --git a/src/r0/presence.rs b/src/r0/presence.rs index c9d03344..c39cf7e7 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -3,8 +3,8 @@ /// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) pub mod set_presence { use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; use ruma_events::presence::PresenceState; + use ruma_identifiers::UserId; ruma_api! { metadata { diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 5d83a5a6..cf014d25 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -3,7 +3,7 @@ /// [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) pub mod redact_event { use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, EventId}; + use ruma_identifiers::{EventId, RoomId}; ruma_api! { metadata { diff --git a/src/r0/room.rs b/src/r0/room.rs index 1435497e..ccf37b18 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -2,8 +2,8 @@ /// [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; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { @@ -59,7 +59,7 @@ pub mod create_room { /// Whether users on other servers can join this room. /// /// Defaults to `true` if key does not exist. - #[serde(rename="m.federate")] + #[serde(rename = "m.federate")] #[serde(skip_serializing_if = "Option::is_none")] pub federate: Option, } @@ -68,13 +68,13 @@ pub mod create_room { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum RoomPreset { /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. - #[serde(rename="private_chat")] + #[serde(rename = "private_chat")] PrivateChat, /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. - #[serde(rename="public_chat")] + #[serde(rename = "public_chat")] PublicChat, /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. - #[serde(rename="trusted_private_chat")] + #[serde(rename = "trusted_private_chat")] TrustedPrivateChat, } diff --git a/src/r0/search.rs b/src/r0/search.rs index ff6f2cb6..c11460d8 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -41,7 +41,7 @@ pub mod search_events { pub struct Categories { /// Criteria for searching a category of events. #[serde(skip_serializing_if = "Option::is_none")] - pub room_events: Option + pub room_events: Option, } /// Criteria for searching a category of events. @@ -107,17 +107,17 @@ pub mod search_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Grouping { /// The key within events to use for this grouping. - pub key: GroupingKey + pub key: GroupingKey, } /// The key within events to use for this grouping. #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub enum GroupingKey { /// `room_id` - #[serde(rename="room_id")] + #[serde(rename = "room_id")] RoomId, /// `sender` - #[serde(rename="sender")] + #[serde(rename = "sender")] Sender, } @@ -132,13 +132,13 @@ pub mod search_events { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum SearchKeys { /// content.body - #[serde(rename="content.body")] + #[serde(rename = "content.body")] ContentBody, /// content.name - #[serde(rename="content.name")] + #[serde(rename = "content.name")] ContentName, /// content.topic - #[serde(rename="content.topic")] + #[serde(rename = "content.topic")] ContentTopic, } @@ -147,10 +147,10 @@ pub mod search_events { pub enum OrderBy { /// Prioritize events by a numerical ranking of how closely they matched the search /// criteria. - #[serde(rename="rank")] + #[serde(rename = "rank")] Rank, /// Prioritize recent events. - #[serde(rename="recent")] + #[serde(rename = "recent")] Recent, } diff --git a/src/r0/send.rs b/src/r0/send.rs index 21cd1e55..70269810 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -3,8 +3,8 @@ /// [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 ruma_identifiers::{EventId, RoomId}; use serde_json::Value; ruma_api! { @@ -39,8 +39,8 @@ pub mod send_state_event_for_empty_key { /// [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 ruma_identifiers::{EventId, RoomId}; use serde_json::Value; ruma_api! { @@ -78,9 +78,9 @@ pub mod send_state_event_for_key { /// [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; + use ruma_events::EventType; + use ruma_identifiers::{EventId, RoomId}; ruma_api! { metadata { diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 8a4e66de..66710a8b 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -186,10 +186,10 @@ pub mod get_message_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub enum Direction { /// Return events backwards in time from the requested `from` token. - #[serde(rename="b")] + #[serde(rename = "b")] Backward, /// Return events forwards in time from the requested `from` token. - #[serde(rename="f")] + #[serde(rename = "f")] Forward, } } @@ -199,7 +199,10 @@ pub mod sync_events { use std::collections::HashMap; use ruma_api_macros::ruma_api; - use ruma_events::{collections::{all, only}, stripped}; + use ruma_events::{ + collections::{all, only}, + stripped, + }; use ruma_identifiers::RoomId; use r0::filter::FilterDefinition; @@ -252,7 +255,7 @@ pub mod sync_events { #[derive(Clone, Debug, Deserialize, Serialize)] pub enum SetPresence { /// Do not set the presence of the user calling this API. - #[serde(rename="offline")] + #[serde(rename = "offline")] Offline, } diff --git a/src/r0/tag.rs b/src/r0/tag.rs index f6e5e333..1d3a893e 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -4,7 +4,7 @@ pub mod create_tag { use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; - use ruma_identifiers::{UserId, RoomId}; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { @@ -39,7 +39,7 @@ pub mod create_tag { pub mod get_tags { use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; - use ruma_identifiers::{UserId, RoomId}; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { @@ -70,7 +70,7 @@ pub mod get_tags { /// [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod delete_tag { use ruma_api_macros::ruma_api; - use ruma_identifiers::{UserId, RoomId}; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { diff --git a/src/r0/typing.rs b/src/r0/typing.rs index eac4f8e8..9b8c2929 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -3,7 +3,7 @@ /// [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) pub mod create_typing_event { use ruma_api_macros::ruma_api; - use ruma_identifiers::{UserId, RoomId}; + use ruma_identifiers::{RoomId, UserId}; ruma_api! { metadata { From f95b4b05bbf3dfc536adf85f818f28486ddc63ce Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 13 Jan 2019 21:13:18 +0100 Subject: [PATCH 101/350] Use nested imports --- .rustfmt.toml | 1 + src/r0/send.rs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..7d2cf549 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +merge_imports = true diff --git a/src/r0/send.rs b/src/r0/send.rs index 70269810..6177e702 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -78,8 +78,7 @@ pub mod send_state_event_for_key { /// [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_events::room::message::MessageEventContent; - use ruma_events::EventType; + use ruma_events::{room::message::MessageEventContent, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { From bc968c8e14faed05909980e6cf5b4d0b73726569 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 13 Jan 2019 21:22:37 +0100 Subject: [PATCH 102/350] Update to Rust 2018 --- Cargo.toml | 1 + src/lib.rs | 22 ++++++++-------------- src/r0/account.rs | 4 ++++ src/r0/alias.rs | 3 +++ src/r0/config.rs | 2 ++ src/r0/contact.rs | 3 +++ src/r0/context.rs | 1 + src/r0/directory.rs | 1 + src/r0/filter.rs | 3 +++ src/r0/media.rs | 3 +++ src/r0/membership.rs | 9 +++++++++ src/r0/presence.rs | 4 ++++ src/r0/profile.rs | 5 +++++ src/r0/receipt.rs | 3 ++- src/r0/redact.rs | 1 + src/r0/room.rs | 1 + src/r0/search.rs | 3 ++- src/r0/send.rs | 3 +++ src/r0/server.rs | 1 + src/r0/session.rs | 1 + src/r0/sync.rs | 8 +++++++- src/r0/tag.rs | 3 +++ src/r0/typing.rs | 1 + src/r0/voip.rs | 1 + src/unversioned.rs | 1 + 25 files changed, 71 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6a26e87e..2a0f07b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" version = "0.2.0" +edition = "2018" [dependencies] futures = "0.1.25" diff --git a/src/lib.rs b/src/lib.rs index 3695492f..2cd92263 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,20 +5,14 @@ #![deny(missing_debug_implementations, missing_docs)] #![feature(try_from)] -extern crate futures; -extern crate http; -extern crate hyper; -extern crate ruma_api; -extern crate ruma_api_macros; -extern crate ruma_events; -extern crate ruma_identifiers; -extern crate ruma_signatures; -extern crate serde; -extern crate serde_json; -#[macro_use] -extern crate serde_derive; -extern crate serde_urlencoded; -extern crate url; +use futures; +use http; +use hyper; +use ruma_api; +use serde; +use serde_json; +use serde_urlencoded; +use url; /// Endpoints for the r0.x.x versions of the client API specification. pub mod r0 { diff --git a/src/r0/account.rs b/src/r0/account.rs index 32aba8de..8c59d07e 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -4,6 +4,7 @@ pub mod register { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -101,6 +102,7 @@ pub mod register { /// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -153,6 +155,7 @@ pub mod deactivate { /// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) pub mod change_password { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -177,6 +180,7 @@ pub mod change_password { /// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) pub mod request_register_token { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/alias.rs b/src/r0/alias.rs index c102f867..2df745ff 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -4,6 +4,7 @@ pub mod create_alias { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -31,6 +32,7 @@ pub mod create_alias { pub mod delete_alias { use ruma_api_macros::ruma_api; use ruma_identifiers::RoomAliasId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -56,6 +58,7 @@ pub mod delete_alias { pub mod get_alias { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/config.rs b/src/r0/config.rs index 975b3ea0..3bccf359 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -4,6 +4,7 @@ pub mod set_room_account_data { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { @@ -43,6 +44,7 @@ pub mod set_room_account_data { pub mod set_global_account_data { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 2f646be2..378c7363 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -3,6 +3,7 @@ /// [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) pub mod create_contact { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -43,6 +44,7 @@ pub mod create_contact { /// [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) pub mod get_contacts { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -84,6 +86,7 @@ pub mod get_contacts { /// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) pub mod request_contact_verification_token { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/context.rs b/src/r0/context.rs index 261f0b3b..b3219613 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -5,6 +5,7 @@ pub mod get_context { use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 7a00037b..ee020703 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -4,6 +4,7 @@ pub mod get_public_rooms { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 4ee85985..22278416 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -1,6 +1,7 @@ //! Endpoints for event filters. use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; /// Format to use for returned events #[derive(Copy, Clone, Debug, Deserialize, Serialize)] @@ -169,6 +170,7 @@ pub struct FilterDefinition { pub mod create_filter { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; use super::FilterDefinition; @@ -204,6 +206,7 @@ pub mod create_filter { pub mod get_filter { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; use super::FilterDefinition; diff --git a/src/r0/media.rs b/src/r0/media.rs index 0b51c95d..dbcda746 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -3,6 +3,7 @@ /// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) pub mod get_content { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -40,6 +41,7 @@ pub mod get_content { /// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) pub mod create_content { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -67,6 +69,7 @@ pub mod create_content { /// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) pub mod get_content_thumbnail { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; /// The desired resizing method. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] diff --git a/src/r0/membership.rs b/src/r0/membership.rs index a8dc7503..11b9f1d1 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -1,6 +1,7 @@ //! Endpoints for room membership. use ruma_signatures::Signatures; +use serde_derive::{Deserialize, Serialize}; // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } // for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? @@ -23,6 +24,7 @@ pub struct ThirdPartySigned { pub mod invite_user { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -50,6 +52,7 @@ pub mod invite_user { pub mod join_room_by_id_or_alias { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; + use serde_derive::{Deserialize, Serialize}; use super::ThirdPartySigned; @@ -84,6 +87,7 @@ pub mod join_room_by_id_or_alias { pub mod join_room_by_id { use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; use super::ThirdPartySigned; @@ -118,6 +122,7 @@ pub mod join_room_by_id { pub mod forget_room { use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -143,6 +148,7 @@ pub mod forget_room { pub mod leave_room { use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -168,6 +174,7 @@ pub mod leave_room { pub mod kick_user { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -198,6 +205,7 @@ pub mod kick_user { pub mod unban_user { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -225,6 +233,7 @@ pub mod unban_user { pub mod ban_user { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence.rs b/src/r0/presence.rs index c39cf7e7..caaad7f0 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -5,6 +5,7 @@ pub mod set_presence { use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -36,6 +37,7 @@ pub mod get_presence { use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -73,6 +75,7 @@ pub mod get_presence { pub mod update_presence_subscriptions { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -107,6 +110,7 @@ pub mod get_subscribed_presences { use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceEvent; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 83440464..7e6e881d 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -4,6 +4,7 @@ pub mod get_display_name { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -33,6 +34,7 @@ pub mod get_display_name { pub mod set_display_name { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -61,6 +63,7 @@ pub mod set_display_name { pub mod get_avatar_url { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -90,6 +93,7 @@ pub mod get_avatar_url { pub mod set_avatar_url { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -117,6 +121,7 @@ pub mod set_avatar_url { pub mod get_profile { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index fcabd686..b883d437 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -6,6 +6,7 @@ pub mod create_receipt { use ruma_api_macros::ruma_api; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -41,7 +42,7 @@ pub mod create_receipt { } impl Display for ReceiptType { - fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { match *self { ReceiptType::Read => write!(f, "m.read"), } diff --git a/src/r0/redact.rs b/src/r0/redact.rs index cf014d25..3ec4bb7c 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -4,6 +4,7 @@ pub mod redact_event { use ruma_api_macros::ruma_api; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/room.rs b/src/r0/room.rs index ccf37b18..f01084cb 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -4,6 +4,7 @@ pub mod create_room { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/search.rs b/src/r0/search.rs index c11460d8..a1e5f9e9 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -7,8 +7,9 @@ pub mod search_events { use ruma_api_macros::ruma_api; use ruma_events::collections::all::Event; use ruma_identifiers::{EventId, RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; - use r0::filter::RoomEventFilter; + use crate::r0::filter::RoomEventFilter; ruma_api! { metadata { diff --git a/src/r0/send.rs b/src/r0/send.rs index 6177e702..7a0df786 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -5,6 +5,7 @@ pub mod send_state_event_for_empty_key { use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { @@ -41,6 +42,7 @@ pub mod send_state_event_for_key { use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { @@ -80,6 +82,7 @@ pub mod send_message_event { use ruma_api_macros::ruma_api; use ruma_events::{room::message::MessageEventContent, EventType}; use ruma_identifiers::{EventId, RoomId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/server.rs b/src/r0/server.rs index 844b3263..569a8f01 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -6,6 +6,7 @@ pub mod get_user_info { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/session.rs b/src/r0/session.rs index e96fd77a..ee3bb9e1 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -4,6 +4,7 @@ pub mod login { use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 66710a8b..26f46e71 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -5,6 +5,7 @@ pub mod get_state_events { use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -37,6 +38,7 @@ pub mod get_state_events_for_empty_key { use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -70,6 +72,7 @@ pub mod get_state_events_for_key { use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -106,6 +109,7 @@ pub mod get_member_events { use ruma_api_macros::ruma_api; use ruma_events::room::member::MemberEvent; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -135,6 +139,7 @@ pub mod get_message_events { use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -204,8 +209,9 @@ pub mod sync_events { stripped, }; use ruma_identifiers::RoomId; + use serde_derive::{Deserialize, Serialize}; - use r0::filter::FilterDefinition; + use crate::r0::filter::FilterDefinition; ruma_api! { metadata { diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 1d3a893e..f1d9dad1 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -5,6 +5,7 @@ pub mod create_tag { use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -40,6 +41,7 @@ pub mod get_tags { use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { @@ -71,6 +73,7 @@ pub mod get_tags { pub mod delete_tag { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/typing.rs b/src/r0/typing.rs index 9b8c2929..bb49835c 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -4,6 +4,7 @@ pub mod create_typing_event { use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/voip.rs b/src/r0/voip.rs index a83ed694..c06f3c2a 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -3,6 +3,7 @@ /// [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) pub mod get_turn_server_info { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/unversioned.rs b/src/unversioned.rs index cb152fb0..bbbb6196 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -3,6 +3,7 @@ /// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) pub mod get_supported_versions { use ruma_api_macros::ruma_api; + use serde_derive::{Deserialize, Serialize}; ruma_api! { metadata { From d48fc54c96d6b801ca5400d892eaa0a6574a70d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Dom=C3=ADnguez?= Date: Wed, 19 Dec 2018 15:51:24 +0100 Subject: [PATCH 103/350] Use folders instead of mods --- src/lib.rs | 28 +- src/r0.rs | 25 ++ src/r0/account.rs | 212 +--------- src/r0/account/change_password.rs | 23 ++ src/r0/account/deactivate.rs | 19 + src/r0/account/register.rs | 97 +++++ .../account/request_password_change_token.rs | 29 ++ src/r0/account/request_register_token.rs | 29 ++ src/r0/alias.rs | 87 +--- src/r0/alias/create_alias.rs | 26 ++ src/r0/alias/delete_alias.rs | 24 ++ src/r0/alias/get_alias.rs | 29 ++ src/r0/config.rs | 78 +--- src/r0/config/set_global_account_data.rs | 35 ++ src/r0/config/set_room_account_data.rs | 38 ++ src/r0/contact.rs | 116 +----- src/r0/contact/create_contact.rs | 39 ++ src/r0/contact/get_contacts.rs | 40 ++ .../request_contact_verification_token.rs | 29 ++ src/r0/context.rs | 50 +-- src/r0/context/get_context.rs | 48 +++ src/r0/directory.rs | 56 +-- src/r0/directory/get_public_rooms.rs | 54 +++ src/r0/filter.rs | 74 +--- src/r0/filter/create_filter.rs | 34 ++ src/r0/filter/get_filter.rs | 33 ++ src/r0/media.rs | 122 +----- src/r0/media/create_content.rs | 26 ++ src/r0/media/get_content.rs | 38 ++ src/r0/media/get_content_thumbnail.rs | 52 +++ src/r0/membership.rs | 249 +---------- src/r0/membership/ban_user.rs | 29 ++ src/r0/membership/forget_room.rs | 24 ++ src/r0/membership/invite_user.rs | 26 ++ src/r0/membership/join_room_by_id.rs | 33 ++ src/r0/membership/join_room_by_id_or_alias.rs | 33 ++ src/r0/membership/kick_user.rs | 29 ++ src/r0/membership/leave_room.rs | 24 ++ src/r0/membership/unban_user.rs | 26 ++ src/r0/presence.rs | 139 +------ src/r0/presence/get_presence.rs | 37 ++ src/r0/presence/get_subscribed_presences.rs | 29 ++ src/r0/presence/set_presence.rs | 30 ++ .../presence/update_presence_subscriptions.rs | 32 ++ src/r0/profile.rs | 154 +------ src/r0/profile/get_avatar_url.rs | 28 ++ src/r0/profile/get_display_name.rs | 28 ++ src/r0/profile/get_profile.rs | 31 ++ src/r0/profile/set_avatar_url.rs | 26 ++ src/r0/profile/set_display_name.rs | 27 ++ src/r0/receipt.rs | 50 +-- src/r0/receipt/create_receipt.rs | 48 +++ src/r0/redact.rs | 40 +- src/r0/redact/redact_event.rs | 38 ++ src/r0/room.rs | 91 +---- src/r0/room/create_room.rs | 89 ++++ src/r0/search.rs | 222 +--------- src/r0/search/search_events.rs | 220 ++++++++++ src/r0/send.rs | 122 +----- src/r0/send/send_message_event.rs | 41 ++ src/r0/send/send_state_event_for_empty_key.rs | 35 ++ src/r0/send/send_state_event_for_key.rs | 38 ++ src/r0/server.rs | 58 +-- src/r0/server/get_user_info.rs | 56 +++ src/r0/session.rs | 92 +---- src/r0/session/login.rs | 69 ++++ src/r0/session/logout.rs | 18 + src/r0/sync.rs | 385 +----------------- src/r0/sync/get_member_events.rs | 28 ++ src/r0/sync/get_message_events.rs | 63 +++ src/r0/sync/get_state_events.rs | 31 ++ src/r0/sync/get_state_events_for_empty_key.rs | 32 ++ src/r0/sync/get_state_events_for_key.rs | 35 ++ src/r0/sync/sync_events.rs | 179 ++++++++ src/r0/tag.rs | 103 +---- src/r0/tag/create_tag.rs | 34 ++ src/r0/tag/delete_tag.rs | 30 ++ src/r0/tag/get_tags.rs | 31 ++ src/r0/typing.rs | 34 +- src/r0/typing/create_typing_event.rs | 32 ++ src/r0/voip.rs | 30 +- src/r0/voip/get_turn_server_info.rs | 28 ++ src/unversioned.rs | 24 +- src/unversioned/get_supported_versions.rs | 22 + 84 files changed, 2518 insertions(+), 2554 deletions(-) create mode 100644 src/r0.rs create mode 100644 src/r0/account/change_password.rs create mode 100644 src/r0/account/deactivate.rs create mode 100644 src/r0/account/register.rs create mode 100644 src/r0/account/request_password_change_token.rs create mode 100644 src/r0/account/request_register_token.rs create mode 100644 src/r0/alias/create_alias.rs create mode 100644 src/r0/alias/delete_alias.rs create mode 100644 src/r0/alias/get_alias.rs create mode 100644 src/r0/config/set_global_account_data.rs create mode 100644 src/r0/config/set_room_account_data.rs create mode 100644 src/r0/contact/create_contact.rs create mode 100644 src/r0/contact/get_contacts.rs create mode 100644 src/r0/contact/request_contact_verification_token.rs create mode 100644 src/r0/context/get_context.rs create mode 100644 src/r0/directory/get_public_rooms.rs create mode 100644 src/r0/filter/create_filter.rs create mode 100644 src/r0/filter/get_filter.rs create mode 100644 src/r0/media/create_content.rs create mode 100644 src/r0/media/get_content.rs create mode 100644 src/r0/media/get_content_thumbnail.rs create mode 100644 src/r0/membership/ban_user.rs create mode 100644 src/r0/membership/forget_room.rs create mode 100644 src/r0/membership/invite_user.rs create mode 100644 src/r0/membership/join_room_by_id.rs create mode 100644 src/r0/membership/join_room_by_id_or_alias.rs create mode 100644 src/r0/membership/kick_user.rs create mode 100644 src/r0/membership/leave_room.rs create mode 100644 src/r0/membership/unban_user.rs create mode 100644 src/r0/presence/get_presence.rs create mode 100644 src/r0/presence/get_subscribed_presences.rs create mode 100644 src/r0/presence/set_presence.rs create mode 100644 src/r0/presence/update_presence_subscriptions.rs create mode 100644 src/r0/profile/get_avatar_url.rs create mode 100644 src/r0/profile/get_display_name.rs create mode 100644 src/r0/profile/get_profile.rs create mode 100644 src/r0/profile/set_avatar_url.rs create mode 100644 src/r0/profile/set_display_name.rs create mode 100644 src/r0/receipt/create_receipt.rs create mode 100644 src/r0/redact/redact_event.rs create mode 100644 src/r0/room/create_room.rs create mode 100644 src/r0/search/search_events.rs create mode 100644 src/r0/send/send_message_event.rs create mode 100644 src/r0/send/send_state_event_for_empty_key.rs create mode 100644 src/r0/send/send_state_event_for_key.rs create mode 100644 src/r0/server/get_user_info.rs create mode 100644 src/r0/session/login.rs create mode 100644 src/r0/session/logout.rs create mode 100644 src/r0/sync/get_member_events.rs create mode 100644 src/r0/sync/get_message_events.rs create mode 100644 src/r0/sync/get_state_events.rs create mode 100644 src/r0/sync/get_state_events_for_empty_key.rs create mode 100644 src/r0/sync/get_state_events_for_key.rs create mode 100644 src/r0/sync/sync_events.rs create mode 100644 src/r0/tag/create_tag.rs create mode 100644 src/r0/tag/delete_tag.rs create mode 100644 src/r0/tag/get_tags.rs create mode 100644 src/r0/typing/create_typing_event.rs create mode 100644 src/r0/voip/get_turn_server_info.rs create mode 100644 src/unversioned/get_supported_versions.rs diff --git a/src/lib.rs b/src/lib.rs index 2cd92263..50c057c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,31 +14,5 @@ use serde_json; use serde_urlencoded; use url; -/// Endpoints for the r0.x.x versions of the client API specification. -pub mod r0 { - pub mod account; - pub mod alias; - pub mod config; - pub mod contact; - pub mod context; - pub mod directory; - pub mod filter; - pub mod media; - pub mod membership; - pub mod presence; - pub mod profile; - pub mod push; - pub mod receipt; - pub mod redact; - pub mod room; - pub mod search; - pub mod send; - pub mod server; - pub mod session; - pub mod sync; - pub mod tag; - pub mod typing; - pub mod voip; -} - +pub mod r0; pub mod unversioned; diff --git a/src/r0.rs b/src/r0.rs new file mode 100644 index 00000000..275100a5 --- /dev/null +++ b/src/r0.rs @@ -0,0 +1,25 @@ +//! Endpoints for the r0.x.x versions of the client API specification. + +pub mod account; +pub mod alias; +pub mod config; +pub mod contact; +pub mod context; +pub mod directory; +pub mod filter; +pub mod media; +pub mod membership; +pub mod presence; +pub mod profile; +pub mod push; +pub mod receipt; +pub mod redact; +pub mod room; +pub mod search; +pub mod send; +pub mod server; +pub mod session; +pub mod sync; +pub mod tag; +pub mod typing; +pub mod voip; diff --git a/src/r0/account.rs b/src/r0/account.rs index 8c59d07e..7bc88a7c 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -1,209 +1,7 @@ //! Endpoints for account registration and management. -/// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) -pub mod register { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Register an account on this homeserver.", - method: POST, - name: "register", - path: "/_matrix/client/r0/register", - rate_limited: true, - requires_authentication: false, - } - - request { - /// If true, the server binds the email used for authentication - /// to the Matrix ID with the ID Server. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind_email: Option, - /// The desired password for the account. - /// - /// Should only be empty for guest accounts. - // TODO: the spec says nothing about when it is actually required. - #[serde(skip_serializing_if = "Option::is_none")] - pub password: Option, - /// local part of the desired Matrix ID. - /// - /// If omitted, the homeserver MUST generate a Matrix ID local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub username: Option, - /// ID of the client device. - /// - /// If this does not correspond to a known client device, a new device will be created. - /// The server will auto-generate a device_id if this is not specified. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option, - /// Additional authentication information for the user-interactive authentication API. - /// - /// Note that this information is not used to define how the registered user should be - /// authenticated, but is instead used to authenticate the register call itself. - /// It should be left empty, or omitted, unless an earlier call returned an response - /// with status code 401. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option, - /// Kind of account to register - /// - /// Defaults to `User` if ommited. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub kind: Option, - } - - response { - /// An access token for the account. - /// - /// This access token can then be used to authorize other requests. - pub access_token: String, - /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, - /// ID of the registered device. - /// - /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: String, - } - } - - /// Additional authentication information for the user-interactive authentication API. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct AuthenticationData { - /// The login type that the client is attempting to complete. - #[serde(rename = "type")] - kind: String, - /// The value of the session key given by the homeserver. - session: Option, - } - - /// The kind of account being registered. - #[derive(Copy, Clone, Debug, Deserialize, Serialize)] - pub enum RegistrationKind { - /// A guest account - /// - /// These accounts may have limited permissions and may not be supported by all servers. - #[serde(rename = "guest")] - Guest, - /// A regular user account - #[serde(rename = "user")] - User, - } -} - -/// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) -pub mod request_password_change_token { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Request that a password change token is sent to the given email address.", - method: POST, - name: "request_password_change_token", - path: "/_matrix/client/r0/account/password/email/requestToken", - rate_limited: false, - requires_authentication: false, - } - - request { - /// TODO: This parameter is not documented in the spec. - pub client_secret: String, - /// TODO: This parameter is not documented in the spec. - pub email: String, - /// TODO: This parameter is not documented in the spec. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// TODO: This parameter is not documented in the spec. - pub send_attempt: u64, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) -pub mod deactivate { - // TODO: missing request parameters - - use ruma_api_macros::ruma_api; - - ruma_api! { - metadata { - description: "Deactivate the current user's account.", - method: POST, - name: "deactivate", - path: "/_matrix/client/r0/account/deactivate", - rate_limited: true, - requires_authentication: true, - } - - request {} - - response {} - } -} - -/// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) -pub mod change_password { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Change the password of the current user's account.", - method: POST, - name: "change_password", - path: "/_matrix/client/r0/account/password", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The new password for the account. - pub new_password: String, - // TODO: missing `auth` field - } - - response {} - } -} - -/// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) -pub mod request_register_token { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Request a register token with a 3rd party email.", - method: POST, - name: "request_register_token", - path: "/_matrix/client/r0/register/email/requestToken", - rate_limited: true, - requires_authentication: true, - } - - request { - /// Client-generated secret string used to protect this session. - pub client_secret: String, - /// The email address. - pub email: String, - /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: u64, - } - - response {} - } -} +pub mod change_password; +pub mod deactivate; +pub mod register; +pub mod request_password_change_token; +pub mod request_register_token; diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs new file mode 100644 index 00000000..727ca075 --- /dev/null +++ b/src/r0/account/change_password.rs @@ -0,0 +1,23 @@ +//! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Change the password of the current user's account.", + method: POST, + name: "change_password", + path: "/_matrix/client/r0/account/password", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The new password for the account. + pub new_password: String, + // TODO: missing `auth` field + } + + response {} +} diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs new file mode 100644 index 00000000..b32dbdbc --- /dev/null +++ b/src/r0/account/deactivate.rs @@ -0,0 +1,19 @@ +//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) +// TODO: missing request parameters + +use ruma_api_macros::ruma_api; + +ruma_api! { + metadata { + description: "Deactivate the current user's account.", + method: POST, + name: "deactivate", + path: "/_matrix/client/r0/account/deactivate", + rate_limited: true, + requires_authentication: true, + } + + request {} + + response {} +} diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs new file mode 100644 index 00000000..4fef1d71 --- /dev/null +++ b/src/r0/account/register.rs @@ -0,0 +1,97 @@ +//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Register an account on this homeserver.", + method: POST, + name: "register", + path: "/_matrix/client/r0/register", + rate_limited: true, + requires_authentication: false, + } + + request { + /// If true, the server binds the email used for authentication + /// to the Matrix ID with the ID Server. + #[serde(skip_serializing_if = "Option::is_none")] + pub bind_email: Option, + /// The desired password for the account. + /// + /// Should only be empty for guest accounts. + // TODO: the spec says nothing about when it is actually required. + #[serde(skip_serializing_if = "Option::is_none")] + pub password: Option, + /// local part of the desired Matrix ID. + /// + /// If omitted, the homeserver MUST generate a Matrix ID local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub username: Option, + /// ID of the client device. + /// + /// If this does not correspond to a known client device, a new device will be created. + /// The server will auto-generate a device_id if this is not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option, + /// Additional authentication information for the user-interactive authentication API. + /// + /// Note that this information is not used to define how the registered user should be + /// authenticated, but is instead used to authenticate the register call itself. + /// It should be left empty, or omitted, unless an earlier call returned an response + /// with status code 401. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, + /// Kind of account to register + /// + /// Defaults to `User` if ommited. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub kind: Option, + } + + response { + /// An access token for the account. + /// + /// This access token can then be used to authorize other requests. + pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. + pub home_server: String, + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, + /// ID of the registered device. + /// + /// Will be the same as the corresponding parameter in the request, if one was specified. + pub device_id: String, + } +} + +/// Additional authentication information for the user-interactive authentication API. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct AuthenticationData { + /// The login type that the client is attempting to complete. + #[serde(rename = "type")] + kind: String, + /// The value of the session key given by the homeserver. + session: Option, +} + +/// The kind of account being registered. +#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +pub enum RegistrationKind { + /// A guest account + /// + /// These accounts may have limited permissions and may not be supported by all servers. + #[serde(rename = "guest")] + Guest, + /// A regular user account + #[serde(rename = "user")] + User, +} diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs new file mode 100644 index 00000000..aa844c7d --- /dev/null +++ b/src/r0/account/request_password_change_token.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Request that a password change token is sent to the given email address.", + method: POST, + name: "request_password_change_token", + path: "/_matrix/client/r0/account/password/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// TODO: This parameter is not documented in the spec. + pub client_secret: String, + /// TODO: This parameter is not documented in the spec. + pub email: String, + /// TODO: This parameter is not documented in the spec. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// TODO: This parameter is not documented in the spec. + pub send_attempt: u64, + } + + response {} +} diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs new file mode 100644 index 00000000..b2176cd3 --- /dev/null +++ b/src/r0/account/request_register_token.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Request a register token with a 3rd party email.", + method: POST, + name: "request_register_token", + path: "/_matrix/client/r0/register/email/requestToken", + rate_limited: true, + requires_authentication: true, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: u64, + } + + response {} +} diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 2df745ff..574c62c9 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -1,86 +1,5 @@ //! Endpoints for room aliases. -/// [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) -pub mod create_alias { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomAliasId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Add an alias to a room.", - method: PUT, - name: "create_alias", - path: "/_matrix/client/r0/directory/room/:room_alias", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room alias to set. - #[ruma_api(path)] - pub room_alias: RoomAliasId, - /// The room ID to set. - pub room_id: RoomId, - } - - response {} - } -} - -/// [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) -pub mod delete_alias { - use ruma_api_macros::ruma_api; - use ruma_identifiers::RoomAliasId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Remove an alias from a room.", - method: DELETE, - name: "delete_alias", - path: "/_matrix/client/r0/directory/room/:room_alias", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room alias to remove. - #[ruma_api(path)] - pub room_alias: RoomAliasId, - } - - response {} - } -} - -/// [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) -pub mod get_alias { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomAliasId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Resolve a room alias to a room ID.", - method: GET, - name: "get_alias", - path: "/_matrix/client/r0/directory/room/:room_alias", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room alias. - #[ruma_api(path)] - pub room_alias: RoomAliasId, - } - - response { - /// The room ID for this room alias. - pub room_id: RoomId, - /// A list of servers that are aware of this room ID. - pub servers: Vec, - } - } -} +pub mod create_alias; +pub mod delete_alias; +pub mod get_alias; diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs new file mode 100644 index 00000000..2d1d95a9 --- /dev/null +++ b/src/r0/alias/create_alias.rs @@ -0,0 +1,26 @@ +//! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomAliasId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room alias to set. + #[ruma_api(path)] + pub room_alias: RoomAliasId, + /// The room ID to set. + pub room_id: RoomId, + } + + response {} +} diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs new file mode 100644 index 00000000..f79c89ae --- /dev/null +++ b/src/r0/alias/delete_alias.rs @@ -0,0 +1,24 @@ +//! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::RoomAliasId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Remove an alias from a room.", + method: DELETE, + name: "delete_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room alias to remove. + #[ruma_api(path)] + pub room_alias: RoomAliasId, + } + + response {} +} diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs new file mode 100644 index 00000000..764cd941 --- /dev/null +++ b/src/r0/alias/get_alias.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomAliasId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Resolve a room alias to a room ID.", + method: GET, + name: "get_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room alias. + #[ruma_api(path)] + pub room_alias: RoomAliasId, + } + + response { + /// The room ID for this room alias. + pub room_id: RoomId, + /// A list of servers that are aware of this room ID. + pub servers: Vec, + } +} diff --git a/src/r0/config.rs b/src/r0/config.rs index 3bccf359..82b2df26 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1,78 +1,4 @@ //! Endpoints for client configuration. -/// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) -pub mod set_room_account_data { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - use serde_json::Value; - - ruma_api! { - metadata { - description: "Associate account data with a room.", - method: PUT, - name: "set_room_account_data", - path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", - rate_limited: false, - requires_authentication: true, - } - - request { - /// Arbitrary JSON to store as config data. - #[ruma_api(body)] - pub data: Value, - /// The event type of the account_data to set. - /// - /// Custom types should be namespaced to avoid clashes. - #[ruma_api(path)] - pub event_type: String, - /// The ID of the room to set account_data on. - #[ruma_api(path)] - pub room_id: RoomId, - /// The ID of the user to set account_data for. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} - -/// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) -pub mod set_global_account_data { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - use serde_json::Value; - - ruma_api! { - metadata { - description: "Sets global account data.", - method: PUT, - name: "set_global_account_data", - path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", - rate_limited: false, - requires_authentication: true, - } - - request { - /// Arbitrary JSON to store as config data. - #[ruma_api(body)] - pub data: Value, - /// The event type of the account_data to set. - /// - /// Custom types should be namespaced to avoid clashes. - #[ruma_api(path)] - pub event_type: String, - /// The ID of the user to set account_data for. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} +pub mod set_global_account_data; +pub mod set_room_account_data; diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs new file mode 100644 index 00000000..6ae42124 --- /dev/null +++ b/src/r0/config/set_global_account_data.rs @@ -0,0 +1,35 @@ +//! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; + +ruma_api! { + metadata { + description: "Sets global account data.", + method: PUT, + name: "set_global_account_data", + path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Arbitrary JSON to store as config data. + #[ruma_api(body)] + pub data: Value, + /// The event type of the account_data to set. + /// + /// Custom types should be namespaced to avoid clashes. + #[ruma_api(path)] + pub event_type: String, + /// The ID of the user to set account_data for. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs new file mode 100644 index 00000000..261af7a9 --- /dev/null +++ b/src/r0/config/set_room_account_data.rs @@ -0,0 +1,38 @@ +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; + +ruma_api! { + metadata { + description: "Associate account data with a room.", + method: PUT, + name: "set_room_account_data", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Arbitrary JSON to store as config data. + #[ruma_api(body)] + pub data: Value, + /// The event type of the account_data to set. + /// + /// Custom types should be namespaced to avoid clashes. + #[ruma_api(path)] + pub event_type: String, + /// The ID of the room to set account_data on. + #[ruma_api(path)] + pub room_id: RoomId, + /// The ID of the user to set account_data for. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 378c7363..39bb1d10 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -1,115 +1,5 @@ //! Endpoints for account contact information. -/// [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) -pub mod create_contact { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Adds contact information to the user's account.", - method: POST, - name: "create_contact", - path: "/_matrix/client/r0/account/3pid", - rate_limited: false, - requires_authentication: true, - } - - request { - /// Whether the homeserver should also bind this third party identifier to the account's - /// Matrix ID with the passed identity server. - /// - /// Default to `false` if not supplied. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind: Option, - /// The third party credentials to associate with the account. - pub three_pid_creds: ThreePidCredentials, - } - - response {} - } - - /// The third party credentials to associate with the account. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ThreePidCredentials { - /// The client secret used in the session with the identity server. - pub client_secret: String, - /// The identity server to use. - pub id_server: String, - /// The session identifier given by the identity server. - pub sid: String, - } -} - -/// [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) -pub mod get_contacts { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get a list of 3rd party contacts associated with the user's account.", - method: GET, - name: "get_contacts", - path: "/_matrix/client/r0/account/3pid", - rate_limited: false, - requires_authentication: true, - } - - request {} - - response { - /// A list of third party identifiers the homeserver has associated with the user's - /// account. - pub threepids: Vec, - } - } - - /// The medium of third party identifier. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, - } - - /// An identifier external to Matrix. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ThirdPartyIdentifier { - /// The third party identifier address. - pub address: String, - /// The medium of third party identifier. - pub medium: Medium, - } -} - -/// [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) -pub mod request_contact_verification_token { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Ask for a verification token for a given 3rd party ID.", - method: POST, - name: "request_contact_verification_token", - path: "/_matrix/client/r0/account/3pid/email/requestToken", - rate_limited: false, - requires_authentication: false, - } - - request { - /// Client-generated secret string used to protect this session. - pub client_secret: String, - /// The email address. - pub email: String, - /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: u64, - } - - response {} - } -} +pub mod create_contact; +pub mod get_contacts; +pub mod request_contact_verification_token; diff --git a/src/r0/contact/create_contact.rs b/src/r0/contact/create_contact.rs new file mode 100644 index 00000000..a6956828 --- /dev/null +++ b/src/r0/contact/create_contact.rs @@ -0,0 +1,39 @@ +//! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Adds contact information to the user's account.", + method: POST, + name: "create_contact", + path: "/_matrix/client/r0/account/3pid", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Whether the homeserver should also bind this third party identifier to the account's + /// Matrix ID with the passed identity server. + /// + /// Default to `false` if not supplied. + #[serde(skip_serializing_if = "Option::is_none")] + pub bind: Option, + /// The third party credentials to associate with the account. + pub three_pid_creds: ThreePidCredentials, + } + + response {} +} + +/// The third party credentials to associate with the account. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ThreePidCredentials { + /// The client secret used in the session with the identity server. + pub client_secret: String, + /// The identity server to use. + pub id_server: String, + /// The session identifier given by the identity server. + pub sid: String, +} diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs new file mode 100644 index 00000000..5b64e712 --- /dev/null +++ b/src/r0/contact/get_contacts.rs @@ -0,0 +1,40 @@ +//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get a list of 3rd party contacts associated with the user's account.", + method: GET, + name: "get_contacts", + path: "/_matrix/client/r0/account/3pid", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// A list of third party identifiers the homeserver has associated with the user's + /// account. + pub threepids: Vec, + } +} + +/// The medium of third party identifier. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum Medium { + /// An email address. + #[serde(rename = "email")] + Email, +} + +/// An identifier external to Matrix. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ThirdPartyIdentifier { + /// The third party identifier address. + pub address: String, + /// The medium of third party identifier. + pub medium: Medium, +} diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs new file mode 100644 index 00000000..9b9c818b --- /dev/null +++ b/src/r0/contact/request_contact_verification_token.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Ask for a verification token for a given 3rd party ID.", + method: POST, + name: "request_contact_verification_token", + path: "/_matrix/client/r0/account/3pid/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: u64, + } + + response {} +} diff --git a/src/r0/context.rs b/src/r0/context.rs index b3219613..dc9b03e7 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -1,51 +1,3 @@ //! Endpoints for event context. -/// [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) -pub mod get_context { - use ruma_api_macros::ruma_api; - use ruma_events::collections::only; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the events immediately preceding and following a given event.", - method: GET, - path: "/_matrix/client/r0/rooms/:room_id/context/:event_id", - name: "get_context", - rate_limited: false, - requires_authentication: true, - } - - request { - /// 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, - } - - response { - /// A token that can be used to paginate forwards with. - pub end: String, - /// Details of the requested event. - pub event: only::RoomEvent, - /// A list of room events that happened just after the requested event, in chronological - /// order. - pub events_after: Vec, - /// A list of room events that happened just before the requested event, in - /// reverse-chronological order. - pub events_before: Vec, - /// A token that can be used to paginate backwards with. - pub start: String, - /// The state of the room at the last event returned. - pub state: Vec, - } - } -} +pub mod get_context; diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs new file mode 100644 index 00000000..e515bb9c --- /dev/null +++ b/src/r0/context/get_context.rs @@ -0,0 +1,48 @@ +//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) + +use ruma_api_macros::ruma_api; +use ruma_events::collections::only; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the events immediately preceding and following a given event.", + method: GET, + path: "/_matrix/client/r0/rooms/:room_id/context/:event_id", + name: "get_context", + rate_limited: false, + requires_authentication: true, + } + + request { + /// 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, + } + + response { + /// A token that can be used to paginate forwards with. + pub end: String, + /// Details of the requested event. + pub event: only::RoomEvent, + /// A list of room events that happened just after the requested event, in chronological + /// order. + pub events_after: Vec, + /// A list of room events that happened just before the requested event, in + /// reverse-chronological order. + pub events_before: Vec, + /// A token that can be used to paginate backwards with. + pub start: String, + /// The state of the room at the last event returned. + pub state: Vec, + } +} diff --git a/src/r0/directory.rs b/src/r0/directory.rs index ee020703..7108a7ca 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1,57 +1,3 @@ //! Endpoints for the public room directory. -/// [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) -pub mod get_public_rooms { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomAliasId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the list of rooms in this homeserver's public directory.", - method: GET, - name: "get_public_rooms", - path: "/_matrix/client/r0/publicRooms", - rate_limited: false, - requires_authentication: false, - } - - request {} - - response { - /// A pagination token for the response. - pub start: String, - /// A paginated chunk of public rooms. - pub chunk: Vec, - /// A pagination token for the response. - pub end: String - } - } - - /// A chunk of the response, describing one room - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PublicRoomsChunk { - /// Aliases of the room. - //#[serde(skip_serializing_if = "Option::is_none")] - pub aliases: Option>, - /// The URL for the room's avatar, if one is set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - /// Whether guest users may join the room and participate in it. - /// - /// If they can, they will be subject to ordinary power level rules like any other user. - pub guest_can_join: bool, - /// The name of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - /// The number of members joined to the room. - pub num_joined_members: u64, - /// The ID of the room. - pub room_id: RoomId, - /// The topic of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - /// Whether the room may be viewed by guest users without joining. - pub world_readable: bool, - } -} +pub mod get_public_rooms; diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs new file mode 100644 index 00000000..858002c2 --- /dev/null +++ b/src/r0/directory/get_public_rooms.rs @@ -0,0 +1,54 @@ +//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomAliasId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the list of rooms in this homeserver's public directory.", + method: GET, + name: "get_public_rooms", + path: "/_matrix/client/r0/publicRooms", + rate_limited: false, + requires_authentication: false, + } + + request {} + + response { + /// A pagination token for the response. + pub start: String, + /// A paginated chunk of public rooms. + pub chunk: Vec, + /// A pagination token for the response. + pub end: String + } +} + +/// A chunk of the response, describing one room +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct PublicRoomsChunk { + /// Aliases of the room. + //#[serde(skip_serializing_if = "Option::is_none")] + pub aliases: Option>, + /// The URL for the room's avatar, if one is set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// Whether guest users may join the room and participate in it. + /// + /// If they can, they will be subject to ordinary power level rules like any other user. + pub guest_can_join: bool, + /// The name of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// The number of members joined to the room. + pub num_joined_members: u64, + /// The ID of the room. + pub room_id: RoomId, + /// The topic of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// Whether the room may be viewed by guest users without joining. + pub world_readable: bool, +} diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 22278416..1ec49ab3 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -1,5 +1,8 @@ //! Endpoints for event filters. +pub mod create_filter; +pub mod get_filter; + use ruma_identifiers::{RoomId, UserId}; use serde_derive::{Deserialize, Serialize}; @@ -165,74 +168,3 @@ pub struct FilterDefinition { #[serde(skip_serializing_if = "Option::is_none")] pub presence: Option, } - -/// [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) -pub mod create_filter { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - use super::FilterDefinition; - - ruma_api! { - metadata { - description: "Create a new filter for event retrieval.", - method: POST, - name: "create_filter", - path: "/_matrix/client/r0/user/:user_id/filter", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The filter definition. - #[ruma_api(body)] - pub filter: FilterDefinition, - /// The ID of the user uploading the filter. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The ID of the filter that was created. - pub filter_id: String, - } - } -} - -/// [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) -pub mod get_filter { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - use super::FilterDefinition; - - ruma_api! { - metadata { - description: "Retrieve a previously created filter.", - method: GET, - name: "get_filter", - path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The ID of the filter to download. - #[ruma_api(path)] - pub filter_id: String, - /// The user ID to download a filter for. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The filter definition. - #[ruma_api(body)] - pub filter: FilterDefinition, - } - } -} diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs new file mode 100644 index 00000000..315cd50f --- /dev/null +++ b/src/r0/filter/create_filter.rs @@ -0,0 +1,34 @@ +//! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +use super::FilterDefinition; + +ruma_api! { + metadata { + description: "Create a new filter for event retrieval.", + method: POST, + name: "create_filter", + path: "/_matrix/client/r0/user/:user_id/filter", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition, + /// The ID of the user uploading the filter. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The ID of the filter that was created. + pub filter_id: String, + } +} diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs new file mode 100644 index 00000000..0426fccc --- /dev/null +++ b/src/r0/filter/get_filter.rs @@ -0,0 +1,33 @@ +//! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +use super::FilterDefinition; + +ruma_api! { + metadata { + description: "Retrieve a previously created filter.", + method: GET, + name: "get_filter", + path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The ID of the filter to download. + #[ruma_api(path)] + pub filter_id: String, + /// The user ID to download a filter for. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition, + } +} diff --git a/src/r0/media.rs b/src/r0/media.rs index dbcda746..6fc18507 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -1,121 +1,5 @@ //! Endpoints for the media repository. -/// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) -pub mod get_content { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Retrieve content from the media store.", - method: GET, - name: "get_media_content", - path: "/_matrix/media/r0/download/:server_name/:media_id", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: String, - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: String, - } - - response { - /// The content that was previously uploaded. - #[ruma_api(body)] - pub file: Vec, - /// The content type of the file that was previously uploaded. - #[ruma_api(header = "CONTENT_TYPE")] - pub content_type: String, - /// The name of the file that was previously uploaded, if set. - #[ruma_api(header = "CONTENT_DISPOSITION")] - pub content_disposition: String, - } - } -} - -/// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) -pub mod create_content { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Upload content to the media store.", - method: POST, - name: "create_media_content", - path: "/_matrix/media/r0/upload", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The content type of the file being uploaded. - #[ruma_api(header = "CONTENT_TYPE")] - pub content_type: String, - } - - response { - /// The MXC URI for the uploaded content. - pub content_uri: String, - } - } -} - -/// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) -pub mod get_content_thumbnail { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - /// The desired resizing method. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum Method { - /// Crop the original to produce the requested image dimensions. - #[serde(rename = "crop")] - Crop, - /// Maintain the original aspect ratio of the source image. - #[serde(rename = "scale")] - Scale, - } - - ruma_api! { - metadata { - description: "Get a thumbnail of content from the media store.", - method: GET, - name: "get_content_thumbnail", - path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: String, - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: String, - /// The *desired* height of the thumbnail. The actual thumbnail may not match the size - /// specified. - #[ruma_api(query)] - pub height: Option, - /// The desired resizing method. - #[ruma_api(query)] - pub method: Option, - /// The *desired* width of the thumbnail. The actual thumbnail may not match the size - /// specified. - #[ruma_api(query)] - pub width: Option, - } - - response { - /// A thumbnail of the requested content. - #[ruma_api(body)] - pub file: Vec, - } - } -} +pub mod create_content; +pub mod get_content; +pub mod get_content_thumbnail; diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs new file mode 100644 index 00000000..a3558613 --- /dev/null +++ b/src/r0/media/create_content.rs @@ -0,0 +1,26 @@ +//! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Upload content to the media store.", + method: POST, + name: "create_media_content", + path: "/_matrix/media/r0/upload", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The content type of the file being uploaded. + #[ruma_api(header = "CONTENT_TYPE")] + pub content_type: String, + } + + response { + /// The MXC URI for the uploaded content. + pub content_uri: String, + } +} diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs new file mode 100644 index 00000000..5b7ea625 --- /dev/null +++ b/src/r0/media/get_content.rs @@ -0,0 +1,38 @@ +//! Endpoints for the media repository. + +//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Retrieve content from the media store.", + method: GET, + name: "get_media_content", + path: "/_matrix/media/r0/download/:server_name/:media_id", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: String, + } + + response { + /// The content that was previously uploaded. + #[ruma_api(body)] + pub file: Vec, + /// The content type of the file that was previously uploaded. + #[ruma_api(header = "CONTENT_TYPE")] + pub content_type: String, + /// The name of the file that was previously uploaded, if set. + #[ruma_api(header = "CONTENT_DISPOSITION")] + pub content_disposition: String, + } +} diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs new file mode 100644 index 00000000..d11dfaa7 --- /dev/null +++ b/src/r0/media/get_content_thumbnail.rs @@ -0,0 +1,52 @@ +//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +/// The desired resizing method. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum Method { + /// Crop the original to produce the requested image dimensions. + #[serde(rename = "crop")] + Crop, + /// Maintain the original aspect ratio of the source image. + #[serde(rename = "scale")] + Scale, +} + +ruma_api! { + metadata { + description: "Get a thumbnail of content from the media store.", + method: GET, + name: "get_content_thumbnail", + path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: String, + /// The *desired* height of the thumbnail. The actual thumbnail may not match the size + /// specified. + #[ruma_api(query)] + pub height: Option, + /// The desired resizing method. + #[ruma_api(query)] + pub method: Option, + /// The *desired* width of the thumbnail. The actual thumbnail may not match the size + /// specified. + #[ruma_api(query)] + pub width: Option, + } + + response { + /// A thumbnail of the requested content. + #[ruma_api(body)] + pub file: Vec, + } +} diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 11b9f1d1..03224f36 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -1,5 +1,14 @@ //! Endpoints for room membership. +pub mod ban_user; +pub mod forget_room; +pub mod invite_user; +pub mod join_room_by_id; +pub mod join_room_by_id_or_alias; +pub mod kick_user; +pub mod leave_room; +pub mod unban_user; + use ruma_signatures::Signatures; use serde_derive::{Deserialize, Serialize}; @@ -19,243 +28,3 @@ pub struct ThirdPartySigned { /// The state key of the m.third_party_invite event. pub token: String, } - -/// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) -pub mod invite_user { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Invite a user to a room.", - method: POST, - name: "invite_user", - path: "/_matrix/client/r0/rooms/:room_id/invite", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id: RoomId, - /// The user to invite. - pub user_id: UserId, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) -pub mod join_room_by_id_or_alias { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, RoomIdOrAliasId}; - use serde_derive::{Deserialize, Serialize}; - - use super::ThirdPartySigned; - - ruma_api! { - metadata { - description: "Join a room using its ID or one of its aliases.", - method: POST, - name: "join_room_by_id_or_alias", - path: "/_matrix/client/r0/join/:room_id_or_alias", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id_or_alias: RoomIdOrAliasId, - /// The signature of a `m.third_party_invite` token to prove that this user owns a third - /// party identity which has been invited to the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option, - } - - response { - /// The room that the user joined. - pub room_id: RoomId, - } - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) -pub mod join_room_by_id { - use ruma_api_macros::ruma_api; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - use super::ThirdPartySigned; - - ruma_api! { - metadata { - description: "Join a room using its ID.", - method: POST, - name: "join_room_by_id", - path: "/_matrix/client/r0/rooms/:room_id/join", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id: RoomId, - /// The signature of a `m.third_party_invite` token to prove that this user owns a third - /// party identity which has been invited to the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option, - } - - response { - /// The room that the user joined. - pub room_id: RoomId, - } - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) -pub mod forget_room { - use ruma_api_macros::ruma_api; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Forget a room.", - method: POST, - name: "forget_room", - path: "/_matrix/client/r0/rooms/:room_id/forget", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The room to forget. - #[ruma_api(path)] - pub room_id: RoomId, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) -pub mod leave_room { - use ruma_api_macros::ruma_api; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Leave a room.", - method: POST, - name: "leave_room", - path: "/_matrix/client/r0/rooms/:room_id/leave", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The room to leave. - #[ruma_api(path)] - pub room_id: RoomId, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) -pub mod kick_user { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Kick a user from a room.", - method: POST, - name: "kick_user", - path: "/_matrix/client/r0/rooms/:room_id/kick", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The reason for kicking the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, - /// The room to kick the user from. - #[ruma_api(path)] - pub room_id: RoomId, - /// The user to kick. - pub user_id: UserId, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) -pub mod unban_user { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Unban a user from a room.", - method: POST, - name: "unban_user", - path: "/_matrix/client/r0/rooms/:room_id/unban", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room to unban the user from. - #[ruma_api(path)] - pub room_id: RoomId, - /// The user to unban. - pub user_id: UserId, - } - - response {} - } -} - -/// [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) -pub mod ban_user { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Ban a user from a room.", - method: POST, - name: "ban_user", - path: "/_matrix/client/r0/rooms/:room_id/ban", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The reason for banning the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, - /// The room to kick the user from. - #[ruma_api(path)] - pub room_id: RoomId, - /// The user to ban. - pub user_id: UserId, - } - - response {} - } -} diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs new file mode 100644 index 00000000..80c57d35 --- /dev/null +++ b/src/r0/membership/ban_user.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Ban a user from a room.", + method: POST, + name: "ban_user", + path: "/_matrix/client/r0/rooms/:room_id/ban", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The reason for banning the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to ban. + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs new file mode 100644 index 00000000..f86d8d1e --- /dev/null +++ b/src/r0/membership/forget_room.rs @@ -0,0 +1,24 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Forget a room.", + method: POST, + name: "forget_room", + path: "/_matrix/client/r0/rooms/:room_id/forget", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room to forget. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response {} +} diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs new file mode 100644 index 00000000..0a52943e --- /dev/null +++ b/src/r0/membership/invite_user.rs @@ -0,0 +1,26 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Invite a user to a room.", + method: POST, + name: "invite_user", + path: "/_matrix/client/r0/rooms/:room_id/invite", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to invite. + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs new file mode 100644 index 00000000..9b99866a --- /dev/null +++ b/src/r0/membership/join_room_by_id.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +use super::ThirdPartySigned; + +ruma_api! { + metadata { + description: "Join a room using its ID.", + method: POST, + name: "join_room_by_id", + path: "/_matrix/client/r0/rooms/:room_id/join", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: RoomId, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option, + } + + response { + /// The room that the user joined. + pub room_id: RoomId, + } +} diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs new file mode 100644 index 00000000..7e39e233 --- /dev/null +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, RoomIdOrAliasId}; +use serde_derive::{Deserialize, Serialize}; + +use super::ThirdPartySigned; + +ruma_api! { + metadata { + description: "Join a room using its ID or one of its aliases.", + method: POST, + name: "join_room_by_id_or_alias", + path: "/_matrix/client/r0/join/:room_id_or_alias", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id_or_alias: RoomIdOrAliasId, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option, + } + + response { + /// The room that the user joined. + pub room_id: RoomId, + } +} diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs new file mode 100644 index 00000000..54729193 --- /dev/null +++ b/src/r0/membership/kick_user.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Kick a user from a room.", + method: POST, + name: "kick_user", + path: "/_matrix/client/r0/rooms/:room_id/kick", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The reason for kicking the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to kick. + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs new file mode 100644 index 00000000..c03b8729 --- /dev/null +++ b/src/r0/membership/leave_room.rs @@ -0,0 +1,24 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Leave a room.", + method: POST, + name: "leave_room", + path: "/_matrix/client/r0/rooms/:room_id/leave", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room to leave. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response {} +} diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs new file mode 100644 index 00000000..8511df83 --- /dev/null +++ b/src/r0/membership/unban_user.rs @@ -0,0 +1,26 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Unban a user from a room.", + method: POST, + name: "unban_user", + path: "/_matrix/client/r0/rooms/:room_id/unban", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to unban the user from. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user to unban. + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/presence.rs b/src/r0/presence.rs index caaad7f0..47bb1eb6 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -1,137 +1,6 @@ //! Endpoints for user presence. -/// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) -pub mod set_presence { - use ruma_api_macros::ruma_api; - use ruma_events::presence::PresenceState; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Set presence status for this user.", - method: PUT, - name: "set_presence", - path: "/_matrix/client/r0/presence/:user_id/status", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The new presence state. - pub presence: PresenceState, - /// The status message to attach to this state. - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, - /// The user whose presence state will be updated. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} - -/// [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) -pub mod get_presence { - use ruma_api_macros::ruma_api; - use ruma_events::presence::PresenceState; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get presence status for this user.", - method: GET, - name: "get_presence", - path: "/_matrix/client/r0/presence/:user_id/status", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The user whose presence state will be retrieved. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The state message for this user if one was set. - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, - /// Whether or not the user is currently active. - #[serde(skip_serializing_if = "Option::is_none")] - pub currently_active: Option, - /// The length of time in milliseconds since an action was performed by the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub last_active_ago: Option, - /// The user's presence state. - pub presence: PresenceState, - } - } -} - -/// [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) -pub mod update_presence_subscriptions { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Update the presence subscriptions of the user.", - method: POST, - name: "update_presence_subscriptions", - path: "/_matrix/client/r0/presence/list/:user_id", - rate_limited: true, - requires_authentication: true, - } - - request { - /// A list of user IDs to remove from the list. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub drop: Vec, - /// A list of user IDs to add to the list. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub invite: Vec, - /// The user whose presence state will be updated. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} - -/// [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) -pub mod get_subscribed_presences { - use ruma_api_macros::ruma_api; - use ruma_events::presence::PresenceEvent; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the precence status from the user's subscriptions.", - method: GET, - name: "get_subscribed_presences", - path: "/_matrix/client/r0/presence/list/:user_id", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The user whose presence state will be retrieved. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// A list of presence events for every user on this list. - #[ruma_api(body)] - pub presence_events: Vec, - } - } -} +pub mod get_presence; +pub mod get_subscribed_presences; +pub mod set_presence; +pub mod update_presence_subscriptions; diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs new file mode 100644 index 00000000..a4ecf0a1 --- /dev/null +++ b/src/r0/presence/get_presence.rs @@ -0,0 +1,37 @@ +//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) + +use ruma_api_macros::ruma_api; +use ruma_events::presence::PresenceState; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get presence status for this user.", + method: GET, + name: "get_presence", + path: "/_matrix/client/r0/presence/:user_id/status", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The user whose presence state will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The state message for this user if one was set. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, + /// Whether or not the user is currently active. + #[serde(skip_serializing_if = "Option::is_none")] + pub currently_active: Option, + /// The length of time in milliseconds since an action was performed by the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub last_active_ago: Option, + /// The user's presence state. + pub presence: PresenceState, + } +} diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs new file mode 100644 index 00000000..40cae333 --- /dev/null +++ b/src/r0/presence/get_subscribed_presences.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) + +use ruma_api_macros::ruma_api; +use ruma_events::presence::PresenceEvent; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the precence status from the user's subscriptions.", + method: GET, + name: "get_subscribed_presences", + path: "/_matrix/client/r0/presence/list/:user_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The user whose presence state will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// A list of presence events for every user on this list. + #[ruma_api(body)] + pub presence_events: Vec, + } +} diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs new file mode 100644 index 00000000..d0c4d872 --- /dev/null +++ b/src/r0/presence/set_presence.rs @@ -0,0 +1,30 @@ +//! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) + +use ruma_api_macros::ruma_api; +use ruma_events::presence::PresenceState; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Set presence status for this user.", + method: PUT, + name: "set_presence", + path: "/_matrix/client/r0/presence/:user_id/status", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The new presence state. + pub presence: PresenceState, + /// The status message to attach to this state. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, + /// The user whose presence state will be updated. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs new file mode 100644 index 00000000..4164272e --- /dev/null +++ b/src/r0/presence/update_presence_subscriptions.rs @@ -0,0 +1,32 @@ +//! [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Update the presence subscriptions of the user.", + method: POST, + name: "update_presence_subscriptions", + path: "/_matrix/client/r0/presence/list/:user_id", + rate_limited: true, + requires_authentication: true, + } + + request { + /// A list of user IDs to remove from the list. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub drop: Vec, + /// A list of user IDs to add to the list. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + /// The user whose presence state will be updated. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 7e6e881d..f87c1437 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -1,151 +1,7 @@ //! Endpoints for user profiles. -/// [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) -pub mod get_display_name { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the display name of a user.", - method: GET, - name: "get_display_name", - path: "/_matrix/client/r0/profile/:user_id/displayname", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The user whose display name will be retrieved. - #[ruma_api(path)] - pub user_id: UserId - } - - response { - /// The user's display name, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - } -} - -/// [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) -pub mod set_display_name { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Set the display name of the user.", - method: PUT, - name: "set_display_name", - path: "/_matrix/client/r0/profile/:user_id/displayname", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The new display name for the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, - /// The user whose display name will be set. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} - -/// [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) -pub mod get_avatar_url { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the avatar URL of a user.", - method: GET, - name: "get_avatar_url", - path: "/_matrix/client/r0/profile/:user_id/avatar_url", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The user whose avatar URL will be retrieved. - #[ruma_api(path)] - pub user_id: UserId - } - - response { - /// The user's avatar URL, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option - } - } -} - -/// [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) -pub mod set_avatar_url { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Set the avatar URL of the user.", - method: PUT, - name: "set_avatar_url", - path: "/_matrix/client/r0/profile/:user_id/avatar_url", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The new avatar URL for the user. - pub avatar_url: String, - /// The user whose avatar URL will be set. - #[ruma_api(path)] - pub user_id: UserId - } - - response {} - } -} - -/// [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) -pub mod get_profile { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get all profile information of an user.", - method: GET, - name: "get_profile", - path: "/_matrix/client/r0/profile/:user_id", - rate_limited: false, - requires_authentication: false, - } - - request { - /// The user whose profile will be retrieved. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The user's avatar URL, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - /// The user's display name, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, - } - } -} +pub mod get_avatar_url; +pub mod get_display_name; +pub mod get_profile; +pub mod set_avatar_url; +pub mod set_display_name; diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs new file mode 100644 index 00000000..ef79761d --- /dev/null +++ b/src/r0/profile/get_avatar_url.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the avatar URL of a user.", + method: GET, + name: "get_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The user whose avatar URL will be retrieved. + #[ruma_api(path)] + pub user_id: UserId + } + + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option + } +} diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs new file mode 100644 index 00000000..ef65e3b5 --- /dev/null +++ b/src/r0/profile/get_display_name.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the display name of a user.", + method: GET, + name: "get_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The user whose display name will be retrieved. + #[ruma_api(path)] + pub user_id: UserId + } + + response { + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option + } +} diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs new file mode 100644 index 00000000..6608948a --- /dev/null +++ b/src/r0/profile/get_profile.rs @@ -0,0 +1,31 @@ +//! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get all profile information of an user.", + method: GET, + name: "get_profile", + path: "/_matrix/client/r0/profile/:user_id", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The user whose profile will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + } +} diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs new file mode 100644 index 00000000..10c6e527 --- /dev/null +++ b/src/r0/profile/set_avatar_url.rs @@ -0,0 +1,26 @@ +//! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Set the avatar URL of the user.", + method: PUT, + name: "set_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The new avatar URL for the user. + pub avatar_url: String, + /// The user whose avatar URL will be set. + #[ruma_api(path)] + pub user_id: UserId + } + + response {} +} diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs new file mode 100644 index 00000000..7a409513 --- /dev/null +++ b/src/r0/profile/set_display_name.rs @@ -0,0 +1,27 @@ +//! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Set the display name of the user.", + method: PUT, + name: "set_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The new display name for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + /// The user whose display name will be set. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index b883d437..ccb1edc3 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -1,51 +1,3 @@ //! Endpoints for event receipts. -/// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) -pub mod create_receipt { - use std::fmt::{Display, Error as FmtError, Formatter}; - - use ruma_api_macros::ruma_api; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Send a receipt event to a room.", - method: POST, - name: "create_receipt", - path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The event ID to acknowledge up to. - #[ruma_api(path)] - pub event_id: EventId, - /// The type of receipt to send. - #[ruma_api(path)] - pub receipt_type: ReceiptType, - /// The room in which to send the event. - #[ruma_api(path)] - pub room_id: RoomId, - } - - response {} - } - - /// The type of receipt. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum ReceiptType { - /// m.read - #[serde(rename = "m.read")] - Read, - } - - impl Display for ReceiptType { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match *self { - ReceiptType::Read => write!(f, "m.read"), - } - } - } -} +pub mod create_receipt; diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs new file mode 100644 index 00000000..74af32bd --- /dev/null +++ b/src/r0/receipt/create_receipt.rs @@ -0,0 +1,48 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) + +use std::fmt::{Display, Error as FmtError, Formatter}; + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Send a receipt event to a room.", + method: POST, + name: "create_receipt", + path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The event ID to acknowledge up to. + #[ruma_api(path)] + pub event_id: EventId, + /// The type of receipt to send. + #[ruma_api(path)] + pub receipt_type: ReceiptType, + /// The room in which to send the event. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response {} +} + +/// The type of receipt. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum ReceiptType { + /// m.read + #[serde(rename = "m.read")] + Read, +} + +impl Display for ReceiptType { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + match *self { + ReceiptType::Read => write!(f, "m.read"), + } + } +} diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 3ec4bb7c..e43d631f 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -1,41 +1,3 @@ //! Endpoints for event redaction. -/// [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) -pub mod redact_event { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Redact an event, stripping all information not critical to the event graph integrity.", - method: PUT, - name: "redact_event", - path: "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The ID of the event to redact. - #[ruma_api(path)] - pub event_id: EventId, - /// The reason for the redaction. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, - /// The ID of the room of the event to redact. - #[ruma_api(path)] - pub room_id: RoomId, - /// The transaction ID for this event. - /// - /// Clients should generate a unique ID; it will be used by the server to ensure idempotency of requests. - #[ruma_api(path)] - pub txn_id: String, - } - - response { - /// The ID of the redacted event. - pub event_id: EventId, - } - } -} +pub mod redact_event; diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs new file mode 100644 index 00000000..b7889d26 --- /dev/null +++ b/src/r0/redact/redact_event.rs @@ -0,0 +1,38 @@ +//! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Redact an event, stripping all information not critical to the event graph integrity.", + method: PUT, + name: "redact_event", + path: "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The ID of the event to redact. + #[ruma_api(path)] + pub event_id: EventId, + /// The reason for the redaction. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + /// The ID of the room of the event to redact. + #[ruma_api(path)] + pub room_id: RoomId, + /// The transaction ID for this event. + /// + /// Clients should generate a unique ID; it will be used by the server to ensure idempotency of requests. + #[ruma_api(path)] + pub txn_id: String, + } + + response { + /// The ID of the redacted event. + pub event_id: EventId, + } +} diff --git a/src/r0/room.rs b/src/r0/room.rs index f01084cb..abee7187 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,92 +1,3 @@ //! Endpoints for room creation. -/// [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_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Create a new room.", - method: POST, - name: "create_room", - path: "/_matrix/client/r0/createRoom", - rate_limited: false, - requires_authentication: true, - } - - request { - /// Extra keys to be added to the content of the `m.room.create`. - #[serde(skip_serializing_if = "Option::is_none")] - pub creation_content: Option, - /// A list of user IDs to invite to the room. - /// - /// This will tell the server to invite everyone in the list to the newly created room. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub invite: Vec, - /// If this is included, an `m.room.name` event will be sent into the room to indicate - /// the name of the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - /// Convenience parameter for setting various default state events based on a preset. - #[serde(skip_serializing_if = "Option::is_none")] - pub preset: Option, - /// The desired room alias local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias_name: Option, - /// If this is included, an `m.room.topic` event will be sent into the room to indicate - /// the topic for the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - /// A public visibility indicates that the room will be shown in the published room - /// list. A private visibility will hide the room from the published room list. Rooms - /// default to private visibility if this key is not included. - #[serde(skip_serializing_if = "Option::is_none")] - pub visibility: Option, - // TODO: missing `invite_3pid`, `initial_state` - } - - response { - /// The created room's ID. - pub room_id: RoomId, - } - } - - /// Extra options to be added to the `m.room.create` event. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct CreationContent { - /// Whether users on other servers can join this room. - /// - /// Defaults to `true` if key does not exist. - #[serde(rename = "m.federate")] - #[serde(skip_serializing_if = "Option::is_none")] - pub federate: Option, - } - - /// A convenience parameter for setting a few default state events. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum RoomPreset { - /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. - #[serde(rename = "private_chat")] - PrivateChat, - /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. - #[serde(rename = "public_chat")] - PublicChat, - /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. - #[serde(rename = "trusted_private_chat")] - TrustedPrivateChat, - } - - /// Whether or not a newly created room will be listed in the room directory. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum Visibility { - /// Indicates that the room will be shown in the published room list. - #[serde(rename = "public")] - Public, - /// Indicates that the room from the published room list. - #[serde(rename = "private")] - Private, - } -} +pub mod create_room; diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs new file mode 100644 index 00000000..55bb0eda --- /dev/null +++ b/src/r0/room/create_room.rs @@ -0,0 +1,89 @@ +//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Create a new room.", + method: POST, + name: "create_room", + path: "/_matrix/client/r0/createRoom", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Extra keys to be added to the content of the `m.room.create`. + #[serde(skip_serializing_if = "Option::is_none")] + pub creation_content: Option, + /// A list of user IDs to invite to the room. + /// + /// This will tell the server to invite everyone in the list to the newly created room. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + /// If this is included, an `m.room.name` event will be sent into the room to indicate + /// the name of the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// Convenience parameter for setting various default state events based on a preset. + #[serde(skip_serializing_if = "Option::is_none")] + pub preset: Option, + /// The desired room alias local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_alias_name: Option, + /// If this is included, an `m.room.topic` event will be sent into the room to indicate + /// the topic for the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// A public visibility indicates that the room will be shown in the published room + /// list. A private visibility will hide the room from the published room list. Rooms + /// default to private visibility if this key is not included. + #[serde(skip_serializing_if = "Option::is_none")] + pub visibility: Option, + // TODO: missing `invite_3pid`, `initial_state` + } + + response { + /// The created room's ID. + pub room_id: RoomId, + } +} + +/// Extra options to be added to the `m.room.create` event. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct CreationContent { + /// Whether users on other servers can join this room. + /// + /// Defaults to `true` if key does not exist. + #[serde(rename = "m.federate")] + #[serde(skip_serializing_if = "Option::is_none")] + pub federate: Option, +} + +/// A convenience parameter for setting a few default state events. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum RoomPreset { + /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. + #[serde(rename = "private_chat")] + PrivateChat, + /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. + #[serde(rename = "public_chat")] + PublicChat, + /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. + #[serde(rename = "trusted_private_chat")] + TrustedPrivateChat, +} + +/// Whether or not a newly created room will be listed in the room directory. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum Visibility { + /// Indicates that the room will be shown in the published room list. + #[serde(rename = "public")] + Public, + /// Indicates that the room from the published room list. + #[serde(rename = "private")] + Private, +} diff --git a/src/r0/search.rs b/src/r0/search.rs index a1e5f9e9..88ced6cc 100644 --- a/src/r0/search.rs +++ b/src/r0/search.rs @@ -1,223 +1,3 @@ //! Endpoints for event searches. -/// [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 { - use std::collections::HashMap; - - use ruma_api_macros::ruma_api; - use ruma_events::collections::all::Event; - use ruma_identifiers::{EventId, RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - use crate::r0::filter::RoomEventFilter; - - ruma_api! { - metadata { - description: "Search events.", - method: POST, - name: "search", - path: "/_matrix/client/r0/search", - rate_limited: true, - requires_authentication: true, - } - - request { - /// The point to return events from. - /// - /// If given, this should be a `next_batch` result from a previous call to this endpoint. - #[ruma_api(query)] - pub next_batch: Option, - /// Describes which categories to search in and their criteria. - pub search_categories: Categories, - } - - response { - /// A grouping of search results by category. - pub search_categories: ResultCategories, - } - } - - /// Categories of events that can be searched for. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Categories { - /// Criteria for searching a category of events. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_events: Option, - } - - /// Criteria for searching a category of events. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Criteria { - /// Configures whether any context for the events returned are included in the response. - #[serde(skip_serializing_if = "Option::is_none")] - pub event_context: Option, - /// A `Filter` to apply to the search. - // TODO: "timeline" key might need to be included. - // See https://github.com/matrix-org/matrix-doc/issues/598. - #[serde(skip_serializing_if = "Option::is_none")] - pub filter: Option, - /// Requests that the server partitions the result set based on the provided list of keys. - #[serde(skip_serializing_if = "Option::is_none")] - pub groupings: Option, - /// Requests the server return the current state for each room returned. - #[serde(skip_serializing_if = "Option::is_none")] - pub include_state: Option, - /// The keys to search for. Defaults to all keys. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub keys: Vec, - /// The order in which to search for results. - #[serde(skip_serializing_if = "Option::is_none")] - pub order_by: Option, - /// The string to search events for. - pub search_term: String, - } - - /// Configures whether any context for the events returned are included in the response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct EventContext { - /// How many events after the result are returned. - pub after_limit: u64, - /// How many events before the result are returned. - pub before_limit: u64, - /// Requests that the server returns the historic profile information for the users that - /// sent the events that were returned. - pub include_profile: bool, - } - - /// Context for search results, if requested. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct EventContextResult { - /// Pagination token for the end of the chunk. - pub end: String, - /// Events just after the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>, - /// Events just before the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>, - /// The historic profile information of the users that sent the events returned. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - #[serde(skip_serializing_if = "Option::is_none")] - pub profile_info: Option>, - /// Pagination token for the start of the chunk. - pub start: String, - } - - /// A grouping for partioning the result set. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Grouping { - /// The key within events to use for this grouping. - pub key: GroupingKey, - } - - /// The key within events to use for this grouping. - #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] - pub enum GroupingKey { - /// `room_id` - #[serde(rename = "room_id")] - RoomId, - /// `sender` - #[serde(rename = "sender")] - Sender, - } - - /// Requests that the server partitions the result set based on the provided list of keys. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Groupings { - /// List of groups to request. - pub group_by: Vec, - } - - /// The keys to search for. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum SearchKeys { - /// content.body - #[serde(rename = "content.body")] - ContentBody, - /// content.name - #[serde(rename = "content.name")] - ContentName, - /// content.topic - #[serde(rename = "content.topic")] - ContentTopic, - } - - /// The order in which to search for results. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub enum OrderBy { - /// Prioritize events by a numerical ranking of how closely they matched the search - /// criteria. - #[serde(rename = "rank")] - Rank, - /// Prioritize recent events. - #[serde(rename = "recent")] - Recent, - } - - /// Categories of events that can be searched for. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ResultCategories { - /// Room event results. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_events: Option, - } - - /// Categories of events that can be searched for. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct RoomEventResults { - /// An approximate count of the total number of results found. - pub count: u64, - /// Any groups that were requested. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - pub groups: HashMap>, - /// Token that can be used to get the next batch of results, by passing as the `next_batch` - /// parameter to the next call. If this field is absent, there are no more results. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, - /// List of results in the requested order. - pub results: Vec, - /// The current state for every room in the results. This is included if the request had the - /// `include_state` key set with a value of `true`. - #[serde(skip_serializing_if = "Option::is_none")] - // TODO: Major WTF here. https://github.com/matrix-org/matrix-doc/issues/773 - pub state: Option<()>, - } - - /// A grouping of results, if requested. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ResultGroup { - /// Token that can be used to get the next batch of results in the group, by passing as the - /// `next_batch` parameter to the next call. If this field is absent, there are no more - /// results in this group. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, - /// Key that can be used to order different groups. - pub order: u64, - /// Which results are in this group. - pub results: Vec, - } - - /// A search result. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct SearchResult { - /// Context for result, if requested. - #[serde(skip_serializing_if = "Option::is_none")] - pub context: Option, - /// A number that describes how closely this result matches the search. Higher is closer. - pub rank: f64, - /// The event that matched. - pub result: Event, - } - - /// A user profile. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct UserProfile { - /// The user's avatar URL, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - /// The user's display name, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, - } -} +pub mod search_events; diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs new file mode 100644 index 00000000..3511e4c6 --- /dev/null +++ b/src/r0/search/search_events.rs @@ -0,0 +1,220 @@ +//! [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-search) + +use std::collections::HashMap; + +use ruma_api_macros::ruma_api; +use ruma_events::collections::all::Event; +use ruma_identifiers::{EventId, RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +use crate::r0::filter::RoomEventFilter; + +ruma_api! { + metadata { + description: "Search events.", + method: POST, + name: "search", + path: "/_matrix/client/r0/search", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The point to return events from. + /// + /// If given, this should be a `next_batch` result from a previous call to this endpoint. + #[ruma_api(query)] + pub next_batch: Option, + /// Describes which categories to search in and their criteria. + pub search_categories: Categories, + } + + response { + /// A grouping of search results by category. + pub search_categories: ResultCategories, + } +} + +/// Categories of events that can be searched for. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Categories { + /// Criteria for searching a category of events. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_events: Option, +} + +/// Criteria for searching a category of events. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Criteria { + /// Configures whether any context for the events returned are included in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub event_context: Option, + /// A `Filter` to apply to the search. + // TODO: "timeline" key might need to be included. + // See https://github.com/matrix-org/matrix-doc/issues/598. + #[serde(skip_serializing_if = "Option::is_none")] + pub filter: Option, + /// Requests that the server partitions the result set based on the provided list of keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub groupings: Option, + /// Requests the server return the current state for each room returned. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_state: Option, + /// The keys to search for. Defaults to all keys. + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub keys: Vec, + /// The order in which to search for results. + #[serde(skip_serializing_if = "Option::is_none")] + pub order_by: Option, + /// The string to search events for. + pub search_term: String, +} + +/// Configures whether any context for the events returned are included in the response. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct EventContext { + /// How many events after the result are returned. + pub after_limit: u64, + /// How many events before the result are returned. + pub before_limit: u64, + /// Requests that the server returns the historic profile information for the users that + /// sent the events that were returned. + pub include_profile: bool, +} + +/// Context for search results, if requested. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct EventContextResult { + /// Pagination token for the end of the chunk. + pub end: String, + /// Events just after the result. + #[serde(skip_serializing_if = "Option::is_none")] + pub events_after: Option>, + /// Events just before the result. + #[serde(skip_serializing_if = "Option::is_none")] + pub events_before: Option>, + /// The historic profile information of the users that sent the events returned. + // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 + #[serde(skip_serializing_if = "Option::is_none")] + pub profile_info: Option>, + /// Pagination token for the start of the chunk. + pub start: String, +} + +/// A grouping for partioning the result set. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Grouping { + /// The key within events to use for this grouping. + pub key: GroupingKey, +} + +/// The key within events to use for this grouping. +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +pub enum GroupingKey { + /// `room_id` + #[serde(rename = "room_id")] + RoomId, + /// `sender` + #[serde(rename = "sender")] + Sender, +} + +/// Requests that the server partitions the result set based on the provided list of keys. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Groupings { + /// List of groups to request. + pub group_by: Vec, +} + +/// The keys to search for. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum SearchKeys { + /// content.body + #[serde(rename = "content.body")] + ContentBody, + /// content.name + #[serde(rename = "content.name")] + ContentName, + /// content.topic + #[serde(rename = "content.topic")] + ContentTopic, +} + +/// The order in which to search for results. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum OrderBy { + /// Prioritize events by a numerical ranking of how closely they matched the search + /// criteria. + #[serde(rename = "rank")] + Rank, + /// Prioritize recent events. + #[serde(rename = "recent")] + Recent, +} + +/// Categories of events that can be searched for. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ResultCategories { + /// Room event results. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_events: Option, +} + +/// Categories of events that can be searched for. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomEventResults { + /// An approximate count of the total number of results found. + pub count: u64, + /// Any groups that were requested. + // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 + pub groups: HashMap>, + /// Token that can be used to get the next batch of results, by passing as the `next_batch` + /// parameter to the next call. If this field is absent, there are no more results. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, + /// List of results in the requested order. + pub results: Vec, + /// The current state for every room in the results. This is included if the request had the + /// `include_state` key set with a value of `true`. + #[serde(skip_serializing_if = "Option::is_none")] + // TODO: Major WTF here. https://github.com/matrix-org/matrix-doc/issues/773 + pub state: Option<()>, +} + +/// A grouping of results, if requested. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ResultGroup { + /// Token that can be used to get the next batch of results in the group, by passing as the + /// `next_batch` parameter to the next call. If this field is absent, there are no more + /// results in this group. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, + /// Key that can be used to order different groups. + pub order: u64, + /// Which results are in this group. + pub results: Vec, +} + +/// A search result. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct SearchResult { + /// Context for result, if requested. + #[serde(skip_serializing_if = "Option::is_none")] + pub context: Option, + /// A number that describes how closely this result matches the search. Higher is closer. + pub rank: f64, + /// The event that matched. + pub result: Event, +} + +/// A user profile. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct UserProfile { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, +} diff --git a/src/r0/send.rs b/src/r0/send.rs index 7a0df786..03445f54 100644 --- a/src/r0/send.rs +++ b/src/r0/send.rs @@ -1,121 +1,5 @@ //! Endpoints for sending events. -/// [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_events::EventType; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - use serde_json::Value; - - ruma_api! { - metadata { - description: "Send a state event to a room associated with the empty state key.", - 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, - } - - 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, - /// The event's content. - #[ruma_api(body)] - pub data: Value, - } - - response { - /// A unique identifier for the event. - pub event_id: EventId, - } - } -} - -/// [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_events::EventType; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - use serde_json::Value; - - ruma_api! { - metadata { - description: "Send a state event to a room associated with a given state key.", - 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, - } - - 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, - /// 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, - } - - response { - /// A unique identifier for the event. - pub event_id: EventId, - } - } -} - -/// [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_events::{room::message::MessageEventContent, EventType}; - use ruma_identifiers::{EventId, RoomId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Send a message event to a room.", - method: PUT, - name: "send_message_event", - path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", - rate_limited: false, - requires_authentication: true, - } - - 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, - /// 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, - } - - response { - /// A unique identifier for the event. - pub event_id: EventId, - } - } -} +pub mod send_message_event; +pub mod send_state_event_for_empty_key; +pub mod send_state_event_for_key; diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs new file mode 100644 index 00000000..267912c6 --- /dev/null +++ b/src/r0/send/send_message_event.rs @@ -0,0 +1,41 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::{room::message::MessageEventContent, EventType}; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Send a message event to a room.", + method: PUT, + name: "send_message_event", + path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", + rate_limited: false, + requires_authentication: true, + } + + 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, + /// 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, + } + + response { + /// A unique identifier for the event. + pub event_id: EventId, + } +} diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/send/send_state_event_for_empty_key.rs new file mode 100644 index 00000000..599ba80b --- /dev/null +++ b/src/r0/send/send_state_event_for_empty_key.rs @@ -0,0 +1,35 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::EventType; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; + +ruma_api! { + metadata { + description: "Send a state event to a room associated with the empty state key.", + 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, + } + + 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, + /// The event's content. + #[ruma_api(body)] + pub data: Value, + } + + response { + /// A unique identifier for the event. + pub event_id: EventId, + } +} diff --git a/src/r0/send/send_state_event_for_key.rs b/src/r0/send/send_state_event_for_key.rs new file mode 100644 index 00000000..7b2e6ad5 --- /dev/null +++ b/src/r0/send/send_state_event_for_key.rs @@ -0,0 +1,38 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::EventType; +use ruma_identifiers::{EventId, RoomId}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; + +ruma_api! { + metadata { + description: "Send a state event to a room associated with a given state key.", + 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, + } + + 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, + /// 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, + } + + response { + /// A unique identifier for the event. + pub event_id: EventId, + } +} diff --git a/src/r0/server.rs b/src/r0/server.rs index 569a8f01..9d523d0a 100644 --- a/src/r0/server.rs +++ b/src/r0/server.rs @@ -1,59 +1,3 @@ //! Endpoints for server administration. -/// [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid) -pub mod get_user_info { - use std::collections::HashMap; - - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get information about a particular user.", - method: GET, - name: "get_user_info", - path: "/_matrix/client/r0/admin/whois/:user_id", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The user to look up. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The Matrix user ID of the user. - pub user_id: UserId, - /// A map of the user's device identifiers to information about that device. - pub devices: HashMap, - } - } - - /// Information about a connection in a user session. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct ConnectionInfo { - /// Most recently seen IP address of the session. - pub ip: String, - /// Unix timestamp that the session was last active. - pub last_seen: u64, - /// User agent string last seen in the session. - pub user_agent: String, - } - - /// Information about a user's device. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct DeviceInfo { - /// A list of user sessions on this device. - pub sessions: Vec, - } - - /// Information about a user session. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct SessionInfo { - /// A list of connections in this session. - pub connections: Vec, - } -} +pub mod get_user_info; diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs new file mode 100644 index 00000000..ca25bb72 --- /dev/null +++ b/src/r0/server/get_user_info.rs @@ -0,0 +1,56 @@ +//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid) + +use std::collections::HashMap; + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get information about a particular user.", + method: GET, + name: "get_user_info", + path: "/_matrix/client/r0/admin/whois/:user_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The user to look up. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The Matrix user ID of the user. + pub user_id: UserId, + /// A map of the user's device identifiers to information about that device. + pub devices: HashMap, + } +} + +/// Information about a connection in a user session. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ConnectionInfo { + /// Most recently seen IP address of the session. + pub ip: String, + /// Unix timestamp that the session was last active. + pub last_seen: u64, + /// User agent string last seen in the session. + pub user_agent: String, +} + +/// Information about a user's device. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct DeviceInfo { + /// A list of user sessions on this device. + pub sessions: Vec, +} + +/// Information about a user session. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct SessionInfo { + /// A list of connections in this session. + pub connections: Vec, +} diff --git a/src/r0/session.rs b/src/r0/session.rs index ee3bb9e1..21ad699a 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -1,92 +1,4 @@ //! Endpoints for user session management. -/// [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) -pub mod login { - use ruma_api_macros::ruma_api; - use ruma_identifiers::UserId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Login to the homeserver.", - method: POST, - name: "login", - path: "/_matrix/client/r0/login", - rate_limited: true, - requires_authentication: false, - } - - request { - /// The user's password. - pub password: String, - /// When logging in using a third party identifier, the medium of the identifier. - #[serde(skip_serializing_if = "Option::is_none")] - pub medium: Option, - /// The authentication mechanism. - #[serde(rename = "type")] - pub login_type: LoginType, - /// The fully qualified user ID or just local part of the user ID. - pub user: String, - /// Third party identifier for the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub address: Option, - /// ID of the client device - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, - } - - response { - /// An access token for the account. - pub access_token: String, - /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, - /// A refresh token may be exchanged for a new access token using the /tokenrefresh API - /// endpoint. - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, - /// ID of the logged-in device. - /// - /// Will be the same as the corresponging parameter in the request, if one was - /// specified. - pub device_id: String, - } - } - - /// The medium of a third party identifier. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, - } - - /// The authentication mechanism. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum LoginType { - /// A password is supplied to authenticate. - #[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 { - use ruma_api_macros::ruma_api; - - ruma_api! { - metadata { - description: "Log out of the homeserver.", - method: POST, - name: "logout", - path: "/_matrix/client/r0/logout", - rate_limited: false, - requires_authentication: true, - } - - request {} - - response {} - } -} +pub mod login; +pub mod logout; diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs new file mode 100644 index 00000000..a80273e2 --- /dev/null +++ b/src/r0/session/login.rs @@ -0,0 +1,69 @@ +//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::UserId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Login to the homeserver.", + method: POST, + name: "login", + path: "/_matrix/client/r0/login", + rate_limited: true, + requires_authentication: false, + } + + request { + /// The user's password. + pub password: String, + /// When logging in using a third party identifier, the medium of the identifier. + #[serde(skip_serializing_if = "Option::is_none")] + pub medium: Option, + /// The authentication mechanism. + #[serde(rename = "type")] + pub login_type: LoginType, + /// The fully qualified user ID or just local part of the user ID. + pub user: String, + /// Third party identifier for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub address: Option, + /// ID of the client device + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, + } + + response { + /// An access token for the account. + pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. + pub home_server: String, + /// A refresh token may be exchanged for a new access token using the /tokenrefresh API + /// endpoint. + #[serde(skip_serializing_if = "Option::is_none")] + pub refresh_token: Option, + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, + /// ID of the logged-in device. + /// + /// Will be the same as the corresponging parameter in the request, if one was + /// specified. + pub device_id: String, + } +} + +/// The medium of a third party identifier. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum Medium { + /// An email address. + #[serde(rename = "email")] + Email, +} + +/// The authentication mechanism. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum LoginType { + /// A password is supplied to authenticate. + #[serde(rename = "m.login.password")] + Password, +} diff --git a/src/r0/session/logout.rs b/src/r0/session/logout.rs new file mode 100644 index 00000000..b4b9f02b --- /dev/null +++ b/src/r0/session/logout.rs @@ -0,0 +1,18 @@ +//! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout) + +use ruma_api_macros::ruma_api; + +ruma_api! { + metadata { + description: "Log out of the homeserver.", + method: POST, + name: "logout", + path: "/_matrix/client/r0/logout", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response {} +} diff --git a/src/r0/sync.rs b/src/r0/sync.rs index 26f46e71..fd6b4679 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -1,381 +1,8 @@ //! Endpoints for getting and synchronizing events. -/// [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_events::collections::only; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get state events for a room.", - method: GET, - name: "get_state_events", - path: "/_matrix/client/r0/rooms/:room_id/state", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room to look up the state for. - #[ruma_api(path)] - pub room_id: RoomId, - } - - response { - /// If the user is a member of the room this will be the current state of the room as a - /// list of events. If the user has left the room then this will be the state of the - /// room when they left as a list of events. - #[ruma_api(body)] - pub room_state: Vec, - } - } -} - -/// [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_events::EventType; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get state events of a given type associated with the empty key.", - 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 look up the state for. - #[ruma_api(path)] - pub room_id: RoomId, - /// The type of state to look up. - #[ruma_api(path)] - pub event_type: EventType, - } - - response { - /// The content of the state event. - #[ruma_api(body)] - 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_events::EventType; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get state events associated with a given key.", - 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 for. - #[ruma_api(path)] - pub room_id: RoomId, - /// The type of state to look up. - #[ruma_api(path)] - pub event_type: EventType, - /// The key of the state to look up. - #[ruma_api(path)] - pub state_key: String, - } - - response { - /// The content of the state event. - #[ruma_api(body)] - 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_events::room::member::MemberEvent; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get membership events for a room.", - method: GET, - name: "get_member_events", - path: "/_matrix/client/r0/rooms/:room_id/members", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room to get the member events for. - #[ruma_api(path)] - pub room_id: RoomId, - } - - response { - /// A list of member events. - pub chunk: Vec - } - } -} - -/// [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_events::collections::only; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get message events for a room.", - method: GET, - name: "get_message_events", - path: "/_matrix/client/r0/rooms/:room_id/messages", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room to get events from. - #[ruma_api(path)] - pub room_id: RoomId, - /// 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, - /// The direction to return events from. - pub dir: Direction, - /// The maximum number of events to return. - /// - /// Default: 10. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - } - - response { - /// The token the pagination starts from. - pub start: String, - /// A list of room events. - pub chunk: Vec, - /// The token the pagination ends at. - pub end: String, - } - } - - /// The direction to return events from. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum Direction { - /// Return events backwards in time from the requested `from` token. - #[serde(rename = "b")] - Backward, - /// Return events forwards in time from the requested `from` token. - #[serde(rename = "f")] - 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 std::collections::HashMap; - - use ruma_api_macros::ruma_api; - use ruma_events::{ - collections::{all, only}, - stripped, - }; - use ruma_identifiers::RoomId; - use serde_derive::{Deserialize, Serialize}; - - use crate::r0::filter::FilterDefinition; - - ruma_api! { - metadata { - description: "Get all new events from all rooms since the last sync or a given point of time.", - method: GET, - name: "sync", - path: "/_matrix/client/r0/sync", - rate_limited: false, - requires_authentication: true, - } - - request { - /// A filter represented either as its full JSON definition or the ID of a saved filter. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub filter: Option, - /// A point in time to continue a sync from. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option, - /// Controls whether to include the full state for all rooms the user is a member of. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub full_state: Option, - /// Controls whether the client is automatically marked as online by polling this API. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub set_presence: Option, - /// The maximum time to poll in milliseconds before returning this request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub timeout: Option, - } - - response { - /// The batch token to supply in the `since` param of the next `/sync` request. - pub next_batch: String, - /// Updates to rooms. - pub rooms: Rooms, - /// Updates to the presence status of other users. - pub presence: Presence, - } - - } - - /// Whether to set presence or not during sync. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub enum SetPresence { - /// Do not set the presence of the user calling this API. - #[serde(rename = "offline")] - Offline, - } - - /// A filter represented either as its full JSON definition or the ID of a saved filter. - #[derive(Clone, Debug, Deserialize, Serialize)] - #[serde(untagged)] - pub enum Filter { - /// A complete filter definition serialized to JSON. - FilterDefinition(FilterDefinition), - /// The ID of a filter saved on the server. - FilterId(String), - } - - /// Updates to rooms. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Rooms { - /// The rooms that the user has left or been banned from. - pub leave: HashMap, - /// The rooms that the user has joined. - pub join: HashMap, - /// The rooms that the user has been invited to. - pub invite: HashMap, - } - - /// Historical updates to left rooms. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct LeftRoom { - /// The timeline of messages and state changes in the room up to the point when the user - /// left. - pub timeline: Timeline, - /// The state updates for the room up to the start of the timeline. - pub state: State, - } - - /// Updates to joined rooms. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct JoinedRoom { - /// Counts of unread notifications for this room. - pub unread_notifications: UnreadNotificationsCount, - /// The timeline of messages and state changes in the room. - pub timeline: Timeline, - /// Updates to the state, between the time indicated by the `since` parameter, and the start - /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not - /// given, or `full_state` is true). - pub state: State, - /// The private data that this user has attached to this room. - pub account_data: AccountData, - /// The ephemeral events in the room that aren't recorded in the timeline or state of the - /// room. e.g. typing. - pub ephemeral: Ephemeral, - } - - /// unread notifications count - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct UnreadNotificationsCount { - /// The number of unread notifications for this room with the highlight flag set. - #[serde(skip_serializing_if = "Option::is_none")] - pub highlight_count: Option, - /// The total number of unread notifications for this room. - #[serde(skip_serializing_if = "Option::is_none")] - pub notification_count: Option, - } - - /// Events in the room. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Timeline { - /// True if the number of events returned was limited by the `limit` on the filter. - pub limited: bool, - /// A token that can be supplied to to the `from` parameter of the - /// `/rooms/{roomId}/messages` endpoint. - pub prev_batch: String, - /// A list of events. - pub events: Vec, - } - - /// State events in the room. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct State { - /// A list of state events. - pub events: Vec, - } - - /// The private data that this user has attached to this room. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct AccountData { - /// A list of events. - pub events: Vec, - } - - /// Ephemeral events not recorded in the timeline or state of the room. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Ephemeral { - /// A list of events. - pub events: Vec, - } - - /// Updates to the rooms that the user has been invited to. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct InvitedRoom { - /// The state of a room that the user has been invited to. - pub invite_state: InviteState, - } - - /// The state of a room that the user has been invited to. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct InviteState { - /// A list of state events. - pub events: Vec, - } - - /// Updates to the presence status of other users. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Presence { - /// A list of events. - pub events: Vec, - } -} +pub mod get_member_events; +pub mod get_message_events; +pub mod get_state_events; +pub mod get_state_events_for_empty_key; +pub mod get_state_events_for_key; +pub mod sync_events; diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs new file mode 100644 index 00000000..104ffc39 --- /dev/null +++ b/src/r0/sync/get_member_events.rs @@ -0,0 +1,28 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::room::member::MemberEvent; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get membership events for a room.", + method: GET, + name: "get_member_events", + path: "/_matrix/client/r0/rooms/:room_id/members", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to get the member events for. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response { + /// A list of member events. + pub chunk: Vec + } +} diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs new file mode 100644 index 00000000..430b23cc --- /dev/null +++ b/src/r0/sync/get_message_events.rs @@ -0,0 +1,63 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::collections::only; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get message events for a room.", + method: GET, + name: "get_message_events", + path: "/_matrix/client/r0/rooms/:room_id/messages", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to get events from. + #[ruma_api(path)] + pub room_id: RoomId, + /// 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, + /// The direction to return events from. + pub dir: Direction, + /// The maximum number of events to return. + /// + /// Default: 10. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + } + + response { + /// The token the pagination starts from. + pub start: String, + /// A list of room events. + pub chunk: Vec, + /// The token the pagination ends at. + pub end: String, + } +} + +/// The direction to return events from. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum Direction { + /// Return events backwards in time from the requested `from` token. + #[serde(rename = "b")] + Backward, + /// Return events forwards in time from the requested `from` token. + #[serde(rename = "f")] + Forward, +} diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs new file mode 100644 index 00000000..67dd151c --- /dev/null +++ b/src/r0/sync/get_state_events.rs @@ -0,0 +1,31 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::collections::only; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get state events for a room.", + method: GET, + name: "get_state_events", + path: "/_matrix/client/r0/rooms/:room_id/state", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to look up the state for. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response { + /// If the user is a member of the room this will be the current state of the room as a + /// list of events. If the user has left the room then this will be the state of the + /// room when they left as a list of events. + #[ruma_api(body)] + pub room_state: Vec, + } +} diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/sync/get_state_events_for_empty_key.rs new file mode 100644 index 00000000..d8642c72 --- /dev/null +++ b/src/r0/sync/get_state_events_for_empty_key.rs @@ -0,0 +1,32 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::EventType; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get state events of a given type associated with the empty key.", + 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 look up the state for. + #[ruma_api(path)] + pub room_id: RoomId, + /// The type of state to look up. + #[ruma_api(path)] + pub event_type: EventType, + } + + response { + /// The content of the state event. + #[ruma_api(body)] + pub content: ::serde_json::Value, + } +} diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/sync/get_state_events_for_key.rs new file mode 100644 index 00000000..b28131c0 --- /dev/null +++ b/src/r0/sync/get_state_events_for_key.rs @@ -0,0 +1,35 @@ +//! [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) + +use ruma_api_macros::ruma_api; +use ruma_events::EventType; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get state events associated with a given key.", + 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 for. + #[ruma_api(path)] + pub room_id: RoomId, + /// The type of state to look up. + #[ruma_api(path)] + pub event_type: EventType, + /// The key of the state to look up. + #[ruma_api(path)] + pub state_key: String, + } + + response { + /// The content of the state event. + #[ruma_api(body)] + pub content: ::serde_json::Value, + } +} diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs new file mode 100644 index 00000000..efacb9b2 --- /dev/null +++ b/src/r0/sync/sync_events.rs @@ -0,0 +1,179 @@ +//! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) + +use std::collections::HashMap; + +use ruma_api_macros::ruma_api; +use ruma_events::{ + collections::{all, only}, + stripped, +}; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +use crate::r0::filter::FilterDefinition; + +ruma_api! { + metadata { + description: "Get all new events from all rooms since the last sync or a given point of time.", + method: GET, + name: "sync", + path: "/_matrix/client/r0/sync", + rate_limited: false, + requires_authentication: true, + } + + request { + /// A filter represented either as its full JSON definition or the ID of a saved filter. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub filter: Option, + /// A point in time to continue a sync from. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option, + /// Controls whether to include the full state for all rooms the user is a member of. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub full_state: Option, + /// Controls whether the client is automatically marked as online by polling this API. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub set_presence: Option, + /// The maximum time to poll in milliseconds before returning this request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub timeout: Option, + } + + response { + /// The batch token to supply in the `since` param of the next `/sync` request. + pub next_batch: String, + /// Updates to rooms. + pub rooms: Rooms, + /// Updates to the presence status of other users. + pub presence: Presence, + } + +} + +/// Whether to set presence or not during sync. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum SetPresence { + /// Do not set the presence of the user calling this API. + #[serde(rename = "offline")] + Offline, +} + +/// A filter represented either as its full JSON definition or the ID of a saved filter. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(untagged)] +pub enum Filter { + /// A complete filter definition serialized to JSON. + FilterDefinition(FilterDefinition), + /// The ID of a filter saved on the server. + FilterId(String), +} + +/// Updates to rooms. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Rooms { + /// The rooms that the user has left or been banned from. + pub leave: HashMap, + /// The rooms that the user has joined. + pub join: HashMap, + /// The rooms that the user has been invited to. + pub invite: HashMap, +} + +/// Historical updates to left rooms. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct LeftRoom { + /// The timeline of messages and state changes in the room up to the point when the user + /// left. + pub timeline: Timeline, + /// The state updates for the room up to the start of the timeline. + pub state: State, +} + +/// Updates to joined rooms. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct JoinedRoom { + /// Counts of unread notifications for this room. + pub unread_notifications: UnreadNotificationsCount, + /// The timeline of messages and state changes in the room. + pub timeline: Timeline, + /// Updates to the state, between the time indicated by the `since` parameter, and the start + /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not + /// given, or `full_state` is true). + pub state: State, + /// The private data that this user has attached to this room. + pub account_data: AccountData, + /// The ephemeral events in the room that aren't recorded in the timeline or state of the + /// room. e.g. typing. + pub ephemeral: Ephemeral, +} + +/// unread notifications count +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct UnreadNotificationsCount { + /// The number of unread notifications for this room with the highlight flag set. + #[serde(skip_serializing_if = "Option::is_none")] + pub highlight_count: Option, + /// The total number of unread notifications for this room. + #[serde(skip_serializing_if = "Option::is_none")] + pub notification_count: Option, +} + +/// Events in the room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Timeline { + /// True if the number of events returned was limited by the `limit` on the filter. + pub limited: bool, + /// A token that can be supplied to to the `from` parameter of the + /// `/rooms/{roomId}/messages` endpoint. + pub prev_batch: String, + /// A list of events. + pub events: Vec, +} + +/// State events in the room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct State { + /// A list of state events. + pub events: Vec, +} + +/// The private data that this user has attached to this room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct AccountData { + /// A list of events. + pub events: Vec, +} + +/// Ephemeral events not recorded in the timeline or state of the room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Ephemeral { + /// A list of events. + pub events: Vec, +} + +/// Updates to the rooms that the user has been invited to. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct InvitedRoom { + /// The state of a room that the user has been invited to. + pub invite_state: InviteState, +} + +/// The state of a room that the user has been invited to. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct InviteState { + /// A list of state events. + pub events: Vec, +} + +/// Updates to the presence status of other users. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Presence { + /// A list of events. + pub events: Vec, +} diff --git a/src/r0/tag.rs b/src/r0/tag.rs index f1d9dad1..7f0d9d2e 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -1,102 +1,5 @@ //! Endpoints for tagging rooms. -/// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -pub mod create_tag { - use ruma_api_macros::ruma_api; - use ruma_events::tag::TagInfo; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Add a new tag to a room.", - method: PUT, - name: "create_tag", - path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room to tag. - #[ruma_api(path)] - pub room_id: RoomId, - /// The name of the tag to create. - #[ruma_api(path)] - pub tag: String, - /// Info about the tag. - #[ruma_api(body)] - pub tag_info: TagInfo, - /// The ID of the user creating the tag. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} - -/// [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) -pub mod get_tags { - use ruma_api_macros::ruma_api; - use ruma_events::tag::TagEventContent; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the tags associated with a room.", - method: GET, - name: "get_tags", - path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The room from which tags will be retrieved. - #[ruma_api(path)] - pub room_id: RoomId, - /// The user whose tags will be retrieved. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// The user's tags for the room. - pub tags: TagEventContent, - } - } -} - -/// [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -pub mod delete_tag { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Remove a tag from a room.", - method: DELETE, - name: "delete_tag", - path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The tagged room. - #[ruma_api(path)] - pub room_id: RoomId, - /// The name of the tag to delete. - #[ruma_api(path)] - pub tag: String, - /// The user whose tag will be deleted. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} +pub mod create_tag; +pub mod delete_tag; +pub mod get_tags; diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs new file mode 100644 index 00000000..1dadeb12 --- /dev/null +++ b/src/r0/tag/create_tag.rs @@ -0,0 +1,34 @@ +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) + +use ruma_api_macros::ruma_api; +use ruma_events::tag::TagInfo; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Add a new tag to a room.", + method: PUT, + name: "create_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to tag. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to create. + #[ruma_api(path)] + pub tag: String, + /// Info about the tag. + #[ruma_api(body)] + pub tag_info: TagInfo, + /// The ID of the user creating the tag. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs new file mode 100644 index 00000000..0db67d25 --- /dev/null +++ b/src/r0/tag/delete_tag.rs @@ -0,0 +1,30 @@ +//! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Remove a tag from a room.", + method: DELETE, + name: "delete_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The tagged room. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to delete. + #[ruma_api(path)] + pub tag: String, + /// The user whose tag will be deleted. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs new file mode 100644 index 00000000..dcf02617 --- /dev/null +++ b/src/r0/tag/get_tags.rs @@ -0,0 +1,31 @@ +//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) + +use ruma_api_macros::ruma_api; +use ruma_events::tag::TagEventContent; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the tags associated with a room.", + method: GET, + name: "get_tags", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room from which tags will be retrieved. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user whose tags will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, + } + + response { + /// The user's tags for the room. + pub tags: TagEventContent, + } +} diff --git a/src/r0/typing.rs b/src/r0/typing.rs index bb49835c..446155e3 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -1,35 +1,3 @@ //! Endpoints for typing notifications. -/// [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) -pub mod create_typing_event { - use ruma_api_macros::ruma_api; - use ruma_identifiers::{RoomId, UserId}; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - method: PUT, - path: "/_matrix/client/r0/rooms/:room_id/typing/:user_id", - name: "create_typing_event", - description: "Send a typing event to a room.", - requires_authentication: true, - rate_limited: true, - } - - request { - /// The room in which the user is typing. - #[ruma_api(path)] - pub room_id: RoomId, - /// The length of time in milliseconds to mark this user as typing. - #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, - /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. - pub typing: bool, - /// The user who has started to type. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} - } -} +pub mod create_typing_event; diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs new file mode 100644 index 00000000..49939327 --- /dev/null +++ b/src/r0/typing/create_typing_event.rs @@ -0,0 +1,32 @@ +//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + method: PUT, + path: "/_matrix/client/r0/rooms/:room_id/typing/:user_id", + name: "create_typing_event", + description: "Send a typing event to a room.", + requires_authentication: true, + rate_limited: true, + } + + request { + /// The room in which the user is typing. + #[ruma_api(path)] + pub room_id: RoomId, + /// The length of time in milliseconds to mark this user as typing. + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. + pub typing: bool, + /// The user who has started to type. + #[ruma_api(path)] + pub user_id: UserId, + } + + response {} +} diff --git a/src/r0/voip.rs b/src/r0/voip.rs index c06f3c2a..878b59ac 100644 --- a/src/r0/voip.rs +++ b/src/r0/voip.rs @@ -1,31 +1,3 @@ //! Endpoints for Voice over IP. -/// [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) -pub mod get_turn_server_info { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get credentials for the client to use when initiating VoIP calls.", - method: GET, - name: "turn_server_info", - path: "_matrix/client/r0/voip/turnServer", - rate_limited: true, - requires_authentication: true, - } - - request {} - - response { - /// The password to use. - pub password: String, - /// The time-to-live in seconds. - pub ttl: u64, - /// A list of TURN URIs. - pub uris: Vec, - /// The username to use. - pub username: String, - } - } -} +pub mod get_turn_server_info; diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs new file mode 100644 index 00000000..5d782893 --- /dev/null +++ b/src/r0/voip/get_turn_server_info.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get credentials for the client to use when initiating VoIP calls.", + method: GET, + name: "turn_server_info", + path: "_matrix/client/r0/voip/turnServer", + rate_limited: true, + requires_authentication: true, + } + + request {} + + response { + /// The password to use. + pub password: String, + /// The time-to-live in seconds. + pub ttl: u64, + /// A list of TURN URIs. + pub uris: Vec, + /// The username to use. + pub username: String, + } +} diff --git a/src/unversioned.rs b/src/unversioned.rs index bbbb6196..6e13882c 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -1,25 +1,3 @@ //! Endpoints that cannot change with new versions of the Matrix specification. -/// [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) -pub mod get_supported_versions { - use ruma_api_macros::ruma_api; - use serde_derive::{Deserialize, Serialize}; - - ruma_api! { - metadata { - description: "Get the versions of the client-server API supported by this homeserver.", - method: GET, - name: "api_versions", - path: "/_matrix/client/versions", - rate_limited: false, - requires_authentication: false, - } - - request {} - - response { - /// A list of Matrix client API protocol versions supported by the homeserver. - pub versions: Vec, - } - } -} +pub mod get_supported_versions; diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs new file mode 100644 index 00000000..6b48904c --- /dev/null +++ b/src/unversioned/get_supported_versions.rs @@ -0,0 +1,22 @@ +//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) + +use ruma_api_macros::ruma_api; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get the versions of the client-server API supported by this homeserver.", + method: GET, + name: "api_versions", + path: "/_matrix/client/versions", + rate_limited: false, + requires_authentication: false, + } + + request {} + + response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, + } +} From 14fbaf698fca10d0c096365c80267d6d956fe196 Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Thu, 26 Apr 2018 23:34:43 +0200 Subject: [PATCH 104/350] joined_rooms: new API call that was added in r0.3.0 --- src/r0/membership.rs | 1 + src/r0/membership/joined_rooms.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/r0/membership/joined_rooms.rs diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 03224f36..86ffb6f7 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -5,6 +5,7 @@ pub mod forget_room; pub mod invite_user; pub mod join_room_by_id; pub mod join_room_by_id_or_alias; +pub mod joined_rooms; pub mod kick_user; pub mod leave_room; pub mod unban_user; diff --git a/src/r0/membership/joined_rooms.rs b/src/r0/membership/joined_rooms.rs new file mode 100644 index 00000000..93da4aa6 --- /dev/null +++ b/src/r0/membership/joined_rooms.rs @@ -0,0 +1,24 @@ +//! [GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms) + +use ruma_api_macros::ruma_api; +use ruma_identifiers::RoomId; +use serde_derive::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get a list of the user's current rooms.", + method: GET, + name: "joined_rooms", + path: "/_matrix/client/r0/joined_rooms", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// A list of the rooms the user is in, i.e. + /// the ID of each room in which the user has joined membership. + pub joined_rooms: Vec, + } +} From 71f6a93d76f9d262c7ae5e2f40e42f08a337884f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 2 Feb 2019 22:11:59 +0100 Subject: [PATCH 105/350] r0::sync::sync_events: Fix (de)serialization of filter argument --- src/r0/sync/sync_events.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index efacb9b2..2055173b 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -68,12 +68,45 @@ pub enum SetPresence { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum Filter { + // The filter definition needs to be (de)serialized twice because it is a URL-encoded JSON + // string. Since #[ruma_api(query)] only does the latter and this is a very uncommon + // setup, we implement it through custom serde logic for this specific enum variant rather than + // adding another ruma_api attribute. + // + // On the deserialization side, because this is an enum with #[serde(untagged)], serde will + // try the variants in order (https://serde.rs/enum-representations.html). That means because + // FilterDefinition is the first variant, JSON decoding is attempted first which is almost + // functionally equivalent to looking at whether the first symbol is a '{' as the spec says. + // (there are probably some corner cases like leading whitespace) + #[serde(with = "filter_def_serde")] /// A complete filter definition serialized to JSON. FilterDefinition(FilterDefinition), /// The ID of a filter saved on the server. FilterId(String), } +mod filter_def_serde { + use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer}; + + use crate::r0::filter::FilterDefinition; + + pub fn serialize(filter_def: &FilterDefinition, serializer: S) -> Result + where + S: Serializer, + { + let string = serde_json::to_string(filter_def).map_err(S::Error::custom)?; + serializer.serialize_str(&string) + } + + pub fn deserialize<'de, D>(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let filter_str = <&str>::deserialize(deserializer)?; + serde_json::from_str(filter_str).map_err(D::Error::custom) + } +} + /// Updates to rooms. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Rooms { From af954220bdb85438fa0b1174969718bf0f29a210 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 6 Feb 2019 20:36:39 +0100 Subject: [PATCH 106/350] Replace serde_derive by re-exports in serde --- Cargo.toml | 8 +++++--- src/r0/account/change_password.rs | 2 +- src/r0/account/register.rs | 2 +- src/r0/account/request_password_change_token.rs | 2 +- src/r0/account/request_register_token.rs | 2 +- src/r0/alias/create_alias.rs | 2 +- src/r0/alias/delete_alias.rs | 2 +- src/r0/alias/get_alias.rs | 2 +- src/r0/config/set_global_account_data.rs | 2 +- src/r0/config/set_room_account_data.rs | 2 +- src/r0/contact/create_contact.rs | 2 +- src/r0/contact/get_contacts.rs | 2 +- src/r0/contact/request_contact_verification_token.rs | 2 +- src/r0/context/get_context.rs | 2 +- src/r0/directory/get_public_rooms.rs | 2 +- src/r0/filter.rs | 2 +- src/r0/filter/create_filter.rs | 2 +- src/r0/filter/get_filter.rs | 2 +- src/r0/media/create_content.rs | 2 +- src/r0/media/get_content.rs | 2 +- src/r0/media/get_content_thumbnail.rs | 2 +- src/r0/membership.rs | 2 +- src/r0/membership/ban_user.rs | 2 +- src/r0/membership/forget_room.rs | 2 +- src/r0/membership/invite_user.rs | 2 +- src/r0/membership/join_room_by_id.rs | 2 +- src/r0/membership/join_room_by_id_or_alias.rs | 2 +- src/r0/membership/joined_rooms.rs | 2 +- src/r0/membership/kick_user.rs | 2 +- src/r0/membership/leave_room.rs | 2 +- src/r0/membership/unban_user.rs | 2 +- src/r0/presence/get_presence.rs | 2 +- src/r0/presence/get_subscribed_presences.rs | 2 +- src/r0/presence/set_presence.rs | 2 +- src/r0/presence/update_presence_subscriptions.rs | 2 +- src/r0/profile/get_avatar_url.rs | 2 +- src/r0/profile/get_display_name.rs | 2 +- src/r0/profile/get_profile.rs | 2 +- src/r0/profile/set_avatar_url.rs | 2 +- src/r0/profile/set_display_name.rs | 2 +- src/r0/receipt/create_receipt.rs | 2 +- src/r0/redact/redact_event.rs | 2 +- src/r0/room/create_room.rs | 2 +- src/r0/search/search_events.rs | 2 +- src/r0/send/send_message_event.rs | 2 +- src/r0/send/send_state_event_for_empty_key.rs | 2 +- src/r0/send/send_state_event_for_key.rs | 2 +- src/r0/server/get_user_info.rs | 2 +- src/r0/session/login.rs | 2 +- src/r0/sync/get_member_events.rs | 2 +- src/r0/sync/get_message_events.rs | 2 +- src/r0/sync/get_state_events.rs | 2 +- src/r0/sync/get_state_events_for_empty_key.rs | 2 +- src/r0/sync/get_state_events_for_key.rs | 2 +- src/r0/sync/sync_events.rs | 2 +- src/r0/tag/create_tag.rs | 2 +- src/r0/tag/delete_tag.rs | 2 +- src/r0/tag/get_tags.rs | 2 +- src/r0/typing/create_typing_event.rs | 2 +- src/r0/voip/get_turn_server_info.rs | 2 +- src/unversioned/get_supported_versions.rs | 2 +- 61 files changed, 65 insertions(+), 63 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a0f07b4..10254c97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,10 @@ ruma-api-macros = "0.3.0" ruma-events = "0.11.0" ruma-identifiers = "0.11.0" ruma-signatures = "0.4.1" -serde = "1.0.80" -serde_derive = "1.0.80" -serde_json = "1.0.33" +serde_json = "1.0.38" serde_urlencoded = "0.5.4" url = "1.7.2" + +[dependencies.serde] +version = "1.0.87" +features = ["derive"] diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index 727ca075..40cb2160 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 4fef1d71..a5ce5f74 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs index aa844c7d..27e8e122 100644 --- a/src/r0/account/request_password_change_token.rs +++ b/src/r0/account/request_password_change_token.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs index b2176cd3..f476575b 100644 --- a/src/r0/account/request_register_token.rs +++ b/src/r0/account/request_register_token.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index 2d1d95a9..324e758a 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index f79c89ae..3eddf7dc 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::RoomAliasId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index 764cd941..290409fc 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index 6ae42124..fad88b97 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 261af7a9..11b6f5eb 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/contact/create_contact.rs b/src/r0/contact/create_contact.rs index a6956828..ec4bb64c 100644 --- a/src/r0/contact/create_contact.rs +++ b/src/r0/contact/create_contact.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 5b64e712..7a57e06b 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index 9b9c818b..3a35aa62 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index e515bb9c..a91f5660 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 858002c2..01b16309 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 1ec49ab3..3be8cd30 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -4,7 +4,7 @@ pub mod create_filter; pub mod get_filter; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; /// Format to use for returned events #[derive(Copy, Clone, Debug, Deserialize, Serialize)] diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs index 315cd50f..548eb805 100644 --- a/src/r0/filter/create_filter.rs +++ b/src/r0/filter/create_filter.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::FilterDefinition; diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index 0426fccc..23688b06 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::FilterDefinition; diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index a3558613..d0bfa4aa 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 5b7ea625..e4a3e2e2 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -3,7 +3,7 @@ //! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index d11dfaa7..a516c0c4 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; /// The desired resizing method. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 86ffb6f7..b1b9ebb5 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -11,7 +11,7 @@ pub mod leave_room; pub mod unban_user; use ruma_signatures::Signatures; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } // for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs index 80c57d35..4c891846 100644 --- a/src/r0/membership/ban_user.rs +++ b/src/r0/membership/ban_user.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs index f86d8d1e..a37402f7 100644 --- a/src/r0/membership/forget_room.rs +++ b/src/r0/membership/forget_room.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index 0a52943e..c24de8f8 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs index 9b99866a..9534ba67 100644 --- a/src/r0/membership/join_room_by_id.rs +++ b/src/r0/membership/join_room_by_id.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::ThirdPartySigned; diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index 7e39e233..ed0d4d9c 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use super::ThirdPartySigned; diff --git a/src/r0/membership/joined_rooms.rs b/src/r0/membership/joined_rooms.rs index 93da4aa6..f98beb48 100644 --- a/src/r0/membership/joined_rooms.rs +++ b/src/r0/membership/joined_rooms.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs index 54729193..eba79619 100644 --- a/src/r0/membership/kick_user.rs +++ b/src/r0/membership/kick_user.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs index c03b8729..772437ac 100644 --- a/src/r0/membership/leave_room.rs +++ b/src/r0/membership/leave_room.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index 8511df83..af18b24f 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index a4ecf0a1..1c10573f 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index 40cae333..be5be3f7 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceEvent; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs index d0c4d872..d030b907 100644 --- a/src/r0/presence/set_presence.rs +++ b/src/r0/presence/set_presence.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs index 4164272e..cc175539 100644 --- a/src/r0/presence/update_presence_subscriptions.rs +++ b/src/r0/presence/update_presence_subscriptions.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs index ef79761d..6d2a57d8 100644 --- a/src/r0/profile/get_avatar_url.rs +++ b/src/r0/profile/get_avatar_url.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs index ef65e3b5..420caee0 100644 --- a/src/r0/profile/get_display_name.rs +++ b/src/r0/profile/get_display_name.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index 6608948a..cde5abcb 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index 10c6e527..6130be3a 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs index 7a409513..95d926f1 100644 --- a/src/r0/profile/set_display_name.rs +++ b/src/r0/profile/set_display_name.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 74af32bd..30016499 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Error as FmtError, Formatter}; use ruma_api_macros::ruma_api; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs index b7889d26..eb9b2f29 100644 --- a/src/r0/redact/redact_event.rs +++ b/src/r0/redact/redact_event.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 55bb0eda..60ce8b31 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 3511e4c6..65199321 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use ruma_api_macros::ruma_api; use ruma_events::collections::all::Event; use ruma_identifiers::{EventId, RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::r0::filter::RoomEventFilter; diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index 267912c6..a329d329 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::{room::message::MessageEventContent, EventType}; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/send/send_state_event_for_empty_key.rs index 599ba80b..bfa4d4a3 100644 --- a/src/r0/send/send_state_event_for_empty_key.rs +++ b/src/r0/send/send_state_event_for_empty_key.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/send/send_state_event_for_key.rs b/src/r0/send/send_state_event_for_key.rs index 7b2e6ad5..ecb74ff1 100644 --- a/src/r0/send/send_state_event_for_key.rs +++ b/src/r0/send/send_state_event_for_key.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index ca25bb72..60062a1c 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index a80273e2..48b6ec8c 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index 104ffc39..89c9bbae 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::room::member::MemberEvent; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 430b23cc..cdd24140 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index 67dd151c..c1923c56 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/sync/get_state_events_for_empty_key.rs index d8642c72..de09da76 100644 --- a/src/r0/sync/get_state_events_for_empty_key.rs +++ b/src/r0/sync/get_state_events_for_empty_key.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/sync/get_state_events_for_key.rs index b28131c0..dbe2f8bf 100644 --- a/src/r0/sync/get_state_events_for_key.rs +++ b/src/r0/sync/get_state_events_for_key.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 2055173b..f9835d1e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -8,7 +8,7 @@ use ruma_events::{ stripped, }; use ruma_identifiers::RoomId; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::r0::filter::FilterDefinition; diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs index 1dadeb12..c6c2e33d 100644 --- a/src/r0/tag/create_tag.rs +++ b/src/r0/tag/create_tag.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs index 0db67d25..d9edaae2 100644 --- a/src/r0/tag/delete_tag.rs +++ b/src/r0/tag/delete_tag.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index dcf02617..11f7cdcc 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -3,7 +3,7 @@ use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index 49939327..b16fb8c7 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -2,7 +2,7 @@ use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 5d782893..b2c19c5d 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 6b48904c..88e747dc 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) use ruma_api_macros::ruma_api; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { From 50f1565a4c4caa38528d194de368477eab58e7dd Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 Apr 2019 17:29:59 -0700 Subject: [PATCH 107/350] Add note about minimum Rust version. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1b770295..4e9e7774 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ **ruma-client-api** contains serializable types for the requests and responses for each endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be shared by client and server code. +## Minimum Rust version + +ruma-client-api requires Rust 1.34 or later. + ## Status This project is currently experimental and is very likely to change drastically. From 63fefb952b8ae4f36afe98af9bd7691d0ab8d5d9 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 Apr 2019 18:11:00 -0700 Subject: [PATCH 108/350] Update dependencies. --- Cargo.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 10254c97..90975a57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,18 +12,18 @@ version = "0.2.0" edition = "2018" [dependencies] -futures = "0.1.25" -http = "0.1.14" -hyper = "0.12.16" -ruma-api = "0.6.0" -ruma-api-macros = "0.3.0" -ruma-events = "0.11.0" -ruma-identifiers = "0.11.0" -ruma-signatures = "0.4.1" -serde_json = "1.0.38" +futures = "0.1.26" +http = "0.1.17" +hyper = "0.12.27" +ruma-api = "0.7.0" +ruma-api-macros = "0.4.0" +ruma-events = "0.12.0" +ruma-identifiers = "0.12.0" +ruma-signatures = "0.4.2" +serde_json = "1.0.39" serde_urlencoded = "0.5.4" url = "1.7.2" [dependencies.serde] -version = "1.0.87" +version = "1.0.90" features = ["derive"] From 87ae777549c388e8ffd17c5b43730f0583866639 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 Apr 2019 18:11:16 -0700 Subject: [PATCH 109/350] Remove try_from feature. --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 50c057c3..b26a44b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ //! shared by client and server code. #![deny(missing_debug_implementations, missing_docs)] -#![feature(try_from)] use futures; use http; From 32a791c44f7b92b230eda9bdd01715f801f18c70 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 Apr 2019 18:11:32 -0700 Subject: [PATCH 110/350] Bump version to 0.3.0. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 90975a57..9da40445 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.2.0" +version = "0.3.0" edition = "2018" [dependencies] From d5b6e7e322fb38d9c1455d1742f791d00585ba7c Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 11 Apr 2019 18:22:09 -0700 Subject: [PATCH 111/350] Remove unused imports. --- src/lib.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b26a44b1..86c59f30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,14 +4,5 @@ #![deny(missing_debug_implementations, missing_docs)] -use futures; -use http; -use hyper; -use ruma_api; -use serde; -use serde_json; -use serde_urlencoded; -use url; - pub mod r0; pub mod unversioned; From e9febfedbcb07a0ae81fa3c80fcd9eb8a29930c7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 20 Apr 2019 15:08:43 +0200 Subject: [PATCH 112/350] Add /account/whoami endpoint --- src/r0/account.rs | 1 + src/r0/account/whoami.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/r0/account/whoami.rs diff --git a/src/r0/account.rs b/src/r0/account.rs index 7bc88a7c..d33db981 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -5,3 +5,4 @@ pub mod deactivate; pub mod register; pub mod request_password_change_token; pub mod request_register_token; +pub mod whoami; diff --git a/src/r0/account/whoami.rs b/src/r0/account/whoami.rs new file mode 100644 index 00000000..199fea39 --- /dev/null +++ b/src/r0/account/whoami.rs @@ -0,0 +1,22 @@ +//! [GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-whoami) + +use ruma_api_macros::ruma_api; +use serde::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get information about the owner of a given access token.", + method: GET, + name: "whoami", + path: "/_matrix/client/r0/account/whoami", + rate_limited: true, + requires_authentication: true, + } + + request {} + + response { + /// The id of the user that owns the access token. + pub user_id: String, + } +} From 27ec031689d4c76b6a419b9b37c228f8586bcdb9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 20 Apr 2019 18:50:41 +0200 Subject: [PATCH 113/350] Add /rooms/{roomId}/joined_members endpoint --- src/r0/membership.rs | 1 + src/r0/membership/joined_members.rs | 40 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/r0/membership/joined_members.rs diff --git a/src/r0/membership.rs b/src/r0/membership.rs index b1b9ebb5..d86584f6 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -5,6 +5,7 @@ pub mod forget_room; pub mod invite_user; pub mod join_room_by_id; pub mod join_room_by_id_or_alias; +pub mod joined_members; pub mod joined_rooms; pub mod kick_user; pub mod leave_room; diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs new file mode 100644 index 00000000..d7f7028e --- /dev/null +++ b/src/r0/membership/joined_members.rs @@ -0,0 +1,40 @@ +//! [GET /_matrix/client/r0/rooms/{roomId}/joined_members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-joined-members) + +use std::collections::HashMap; + +use ruma_api_macros::ruma_api; +use ruma_identifiers::{RoomId, UserId}; +use serde::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Get a map of user ids to member info objects for members of the room. Primarily for use in Application Services.", + method: GET, + name: "joined_members", + path: "/_matrix/client/r0/rooms/:room_id/joined_members", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The room to get the members of. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response { + /// A list of the rooms the user is in, i.e. + /// the ID of each room in which the user has joined membership. + pub joined: HashMap, + } +} + +// TODO: Find out whether display_name and avatar_url are optional +/// Information about a room member. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomMember { + /// The display name of the user. + pub display_name: String, + /// The mxc avatar url of the user. + pub avatar_url: Option, +} From 7493353c5a880ed91b3c6b6b6360c9fb987bcd1a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 22 Apr 2019 22:11:18 +0200 Subject: [PATCH 114/350] Add missing request body to create_media_conent --- src/r0/media/create_content.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index d0bfa4aa..0ee953de 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -17,6 +17,9 @@ ruma_api! { /// The content type of the file being uploaded. #[ruma_api(header = "CONTENT_TYPE")] pub content_type: String, + /// The file contents to upload. + #[ruma_api(body)] + pub file: Vec, } response { From 4c3e5d3324bae0416e359db5d14d2f7f60f64378 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 22 Apr 2019 22:12:43 +0200 Subject: [PATCH 115/350] Update create_media_content to r0.4.0 --- src/r0/media/create_content.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index 0ee953de..c6ccc779 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload) +//! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-media-r0-upload) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -9,11 +9,15 @@ ruma_api! { method: POST, name: "create_media_content", path: "/_matrix/media/r0/upload", - rate_limited: false, - requires_authentication: false, + rate_limited: true, + requires_authentication: true, } request { + /// The name of the file being uploaded. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub filename: Option, /// The content type of the file being uploaded. #[ruma_api(header = "CONTENT_TYPE")] pub content_type: String, From 85236be89c65510b2c67b4d1755e897f83644a27 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 22 Apr 2019 22:27:38 +0200 Subject: [PATCH 116/350] Update get_filter endpoint to r0.4.0 --- src/r0/filter/get_filter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index 23688b06..0f8bea5a 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) +//! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-filter-filterid) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; @@ -13,7 +13,7 @@ ruma_api! { name: "get_filter", path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", rate_limited: false, - requires_authentication: false, + requires_authentication: true, } request { From af8fe4225973d68826cc40a1e6fe630d2d38ab1c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 22 Apr 2019 22:33:37 +0200 Subject: [PATCH 117/350] Update link in get_member_events doc comment no code changes were necessary even though the spec was updated: we already specified requires_authentication: true when the spec was missing that information. --- src/r0/sync/get_member_events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index 89c9bbae..c4e0d20a 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -1,4 +1,4 @@ -//! [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) +//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-members) use ruma_api_macros::ruma_api; use ruma_events::room::member::MemberEvent; From 8f1d4a4d21b4698c6329d4138bdfa06a13351948 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 1 May 2019 20:46:57 -0700 Subject: [PATCH 118/350] Update all spec links to the r0.4.0 version. --- src/r0/account/change_password.rs | 2 +- src/r0/account/deactivate.rs | 2 +- src/r0/account/register.rs | 2 +- src/r0/account/request_password_change_token.rs | 2 +- src/r0/account/request_register_token.rs | 2 +- src/r0/alias/create_alias.rs | 2 +- src/r0/alias/delete_alias.rs | 2 +- src/r0/alias/get_alias.rs | 2 +- src/r0/config/set_global_account_data.rs | 2 +- src/r0/config/set_room_account_data.rs | 2 +- src/r0/contact/create_contact.rs | 2 +- src/r0/contact/get_contacts.rs | 2 +- src/r0/contact/request_contact_verification_token.rs | 2 +- src/r0/context/get_context.rs | 2 +- src/r0/directory/get_public_rooms.rs | 2 +- src/r0/filter/create_filter.rs | 2 +- src/r0/media/get_content.rs | 2 +- src/r0/media/get_content_thumbnail.rs | 2 +- src/r0/membership/ban_user.rs | 2 +- src/r0/membership/forget_room.rs | 2 +- src/r0/membership/invite_user.rs | 2 +- src/r0/membership/join_room_by_id.rs | 2 +- src/r0/membership/join_room_by_id_or_alias.rs | 2 +- src/r0/membership/kick_user.rs | 2 +- src/r0/membership/leave_room.rs | 2 +- src/r0/membership/unban_user.rs | 2 +- src/r0/presence/get_presence.rs | 2 +- src/r0/presence/get_subscribed_presences.rs | 2 +- src/r0/presence/set_presence.rs | 2 +- src/r0/presence/update_presence_subscriptions.rs | 2 +- src/r0/profile/get_avatar_url.rs | 2 +- src/r0/profile/get_display_name.rs | 2 +- src/r0/profile/get_profile.rs | 2 +- src/r0/profile/set_avatar_url.rs | 2 +- src/r0/profile/set_display_name.rs | 2 +- src/r0/receipt/create_receipt.rs | 2 +- src/r0/redact/redact_event.rs | 2 +- src/r0/room/create_room.rs | 2 +- src/r0/search/search_events.rs | 2 +- src/r0/send/send_message_event.rs | 2 +- src/r0/send/send_state_event_for_empty_key.rs | 2 +- src/r0/send/send_state_event_for_key.rs | 2 +- src/r0/server/get_user_info.rs | 2 +- src/r0/session/login.rs | 2 +- src/r0/session/logout.rs | 2 +- src/r0/sync/get_message_events.rs | 2 +- src/r0/sync/get_state_events.rs | 2 +- src/r0/sync/get_state_events_for_empty_key.rs | 2 +- src/r0/sync/get_state_events_for_key.rs | 2 +- src/r0/sync/sync_events.rs | 2 +- src/r0/tag/create_tag.rs | 2 +- src/r0/tag/delete_tag.rs | 2 +- src/r0/tag/get_tags.rs | 2 +- src/r0/typing/create_typing_event.rs | 2 +- src/r0/voip/get_turn_server_info.rs | 2 +- src/unversioned/get_supported_versions.rs | 2 +- 56 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index 40cb2160..a69bc750 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) +//! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index b32dbdbc..ff7919a8 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) +//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-deactivate) // TODO: missing request parameters use ruma_api_macros::ruma_api; diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index a5ce5f74..1a08df4e 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) +//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs index 27e8e122..53a207e0 100644 --- a/src/r0/account/request_password_change_token.rs +++ b/src/r0/account/request_password_change_token.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) +//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs index f476575b..cd391063 100644 --- a/src/r0/account/request_register_token.rs +++ b/src/r0/account/request_register_token.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) +//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index 324e758a..bf23bc41 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias) +//! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-directory-room-roomalias) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index 3eddf7dc..119aa68c 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -1,4 +1,4 @@ -//! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias) +//! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-directory-room-roomalias) use ruma_api_macros::ruma_api; use ruma_identifiers::RoomAliasId; diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index 290409fc..26ff81ca 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias) +//! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-directory-room-roomalias) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index fad88b97..4a41561f 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) +//! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-account-data-type) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 11b6f5eb..43bf2ec2 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/contact/create_contact.rs b/src/r0/contact/create_contact.rs index ec4bb64c..eed34509 100644 --- a/src/r0/contact/create_contact.rs +++ b/src/r0/contact/create_contact.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid) +//! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 7a57e06b..4243c594 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-account-3pid) +//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index 3a35aa62..d6bf95a6 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) +//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index a91f5660..a567e6e5 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) +//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) use ruma_api_macros::ruma_api; use ruma_events::collections::only; diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 01b16309..1eb1c28d 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) +//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs index 548eb805..1cacee78 100644 --- a/src/r0/filter/create_filter.rs +++ b/src/r0/filter/create_filter.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) +//! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-user-userid-filter) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index e4a3e2e2..d8a974be 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -1,6 +1,6 @@ //! Endpoints for the media repository. -//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid) +//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-download-servername-mediaid) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index a516c0c4..e13e340f 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) +//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs index 4c891846..9520a3bb 100644 --- a/src/r0/membership/ban_user.rs +++ b/src/r0/membership/ban_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) +//! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-ban) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs index a37402f7..be0b613a 100644 --- a/src/r0/membership/forget_room.rs +++ b/src/r0/membership/forget_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) +//! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-forget) use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index c24de8f8..8253b5dc 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) +//! [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-invite) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs index 9534ba67..bd9c2691 100644 --- a/src/r0/membership/join_room_by_id.rs +++ b/src/r0/membership/join_room_by_id.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) +//! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-join) use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index ed0d4d9c..467e5de5 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) +//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-join-roomidoralias) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs index eba79619..e075b1b6 100644 --- a/src/r0/membership/kick_user.rs +++ b/src/r0/membership/kick_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) +//! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-kick) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs index 772437ac..f84c04a6 100644 --- a/src/r0/membership/leave_room.rs +++ b/src/r0/membership/leave_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) +//! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-leave) use ruma_api_macros::ruma_api; use ruma_identifiers::RoomId; diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index af18b24f..859c6ad1 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) +//! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-unban) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 1c10573f..f1e8ea86 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status) +//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status) use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index be5be3f7..6fc323a1 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid) +//! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-list-userid) use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceEvent; diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs index d030b907..bfca3309 100644 --- a/src/r0/presence/set_presence.rs +++ b/src/r0/presence/set_presence.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status) +//! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-presence-userid-status) use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs index cc175539..3aacbd05 100644 --- a/src/r0/presence/update_presence_subscriptions.rs +++ b/src/r0/presence/update_presence_subscriptions.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid) +//! [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-presence-list-userid) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs index 6d2a57d8..30887550 100644 --- a/src/r0/profile/get_avatar_url.rs +++ b/src/r0/profile/get_avatar_url.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) +//! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-avatar-url) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs index 420caee0..f9f6e298 100644 --- a/src/r0/profile/get_display_name.rs +++ b/src/r0/profile/get_display_name.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) +//! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-displayname) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index cde5abcb..457624ab 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) +//! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index 6130be3a..778dda30 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) +//! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-avatar-url) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs index 95d926f1..01c4cd34 100644 --- a/src/r0/profile/set_display_name.rs +++ b/src/r0/profile/set_display_name.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) +//! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-displayname) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 30016499..58d6f933 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) +//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) use std::fmt::{Display, Error as FmtError, Formatter}; diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs index eb9b2f29..d2845fb5 100644 --- a/src/r0/redact/redact_event.rs +++ b/src/r0/redact/redact_event.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) +//! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) use ruma_api_macros::ruma_api; use ruma_identifiers::{EventId, RoomId}; diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 60ce8b31..8737dc10 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom) +//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-createroom) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 65199321..fd51bbcb 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -1,4 +1,4 @@ -//! [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.4.0.html#post-matrix-client-r0-search) use std::collections::HashMap; diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index a329d329..4f55978c 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,4 +1,4 @@ -//! [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) +//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api_macros::ruma_api; use ruma_events::{room::message::MessageEventContent, EventType}; diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/send/send_state_event_for_empty_key.rs index bfa4d4a3..f6b10396 100644 --- a/src/r0/send/send_state_event_for_empty_key.rs +++ b/src/r0/send/send_state_event_for_empty_key.rs @@ -1,4 +1,4 @@ -//! [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) +//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) use ruma_api_macros::ruma_api; use ruma_events::EventType; diff --git a/src/r0/send/send_state_event_for_key.rs b/src/r0/send/send_state_event_for_key.rs index ecb74ff1..335de505 100644 --- a/src/r0/send/send_state_event_for_key.rs +++ b/src/r0/send/send_state_event_for_key.rs @@ -1,4 +1,4 @@ -//! [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) +//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) use ruma_api_macros::ruma_api; use ruma_events::EventType; diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 60062a1c..e45e385f 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid) +//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-admin-whois-userid) use std::collections::HashMap; diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 48b6ec8c..a91fb1e1 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login) +//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/session/logout.rs b/src/r0/session/logout.rs index b4b9f02b..1f3286f2 100644 --- a/src/r0/session/logout.rs +++ b/src/r0/session/logout.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout) +//! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout) use ruma_api_macros::ruma_api; diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index cdd24140..d378796f 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -1,4 +1,4 @@ -//! [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) +//! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages) use ruma_api_macros::ruma_api; use ruma_events::collections::only; diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index c1923c56..766e0db2 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -1,4 +1,4 @@ -//! [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) +//! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) use ruma_api_macros::ruma_api; use ruma_events::collections::only; diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/sync/get_state_events_for_empty_key.rs index de09da76..e690e61b 100644 --- a/src/r0/sync/get_state_events_for_empty_key.rs +++ b/src/r0/sync/get_state_events_for_empty_key.rs @@ -1,4 +1,4 @@ -//! [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) +//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) use ruma_api_macros::ruma_api; use ruma_events::EventType; diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/sync/get_state_events_for_key.rs index dbe2f8bf..a26527c8 100644 --- a/src/r0/sync/get_state_events_for_key.rs +++ b/src/r0/sync/get_state_events_for_key.rs @@ -1,4 +1,4 @@ -//! [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) +//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) use ruma_api_macros::ruma_api; use ruma_events::EventType; diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index f9835d1e..4ee05169 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync) +//! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-sync) use std::collections::HashMap; diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs index c6c2e33d..93c57b5f 100644 --- a/src/r0/tag/create_tag.rs +++ b/src/r0/tag/create_tag.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs index d9edaae2..9ad3bbdc 100644 --- a/src/r0/tag/delete_tag.rs +++ b/src/r0/tag/delete_tag.rs @@ -1,4 +1,4 @@ -//! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +//! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 11f7cdcc..ddc384e8 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) +//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index b16fb8c7..e928c4ef 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) +//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index b2c19c5d..52260261 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver) +//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 88e747dc..3d0538ef 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions) +//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-versions) use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; From 3037b105c7630c9f6c2f0beeccdfb71148caf4ad Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 1 May 2019 21:14:59 -0700 Subject: [PATCH 119/350] Add homeserver discovery endpoint. --- src/unversioned.rs | 1 + src/unversioned/discover_homeserver.rs | 42 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/unversioned/discover_homeserver.rs diff --git a/src/unversioned.rs b/src/unversioned.rs index 6e13882c..e77bcd06 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -1,3 +1,4 @@ //! Endpoints that cannot change with new versions of the Matrix specification. pub mod get_supported_versions; +pub mod discover_homeserver; diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs new file mode 100644 index 00000000..b6ca5715 --- /dev/null +++ b/src/unversioned/discover_homeserver.rs @@ -0,0 +1,42 @@ +//! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-well-known-matrix-client) + +use ruma_api_macros::ruma_api; +use serde::{Deserialize, Serialize}; +use url::Url; + +/// Information about a discovered homeserver. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] +pub struct HomeserverInfo { + /// The base URL for the homeserver for client-server connections. + pub base_url: Url, +} + +/// Information about a discovered identity server. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] +pub struct IdentityServerInfo { + /// The base URL for the identity server for client-server connections. + pub base_url: Url, +} + +ruma_api! { + metadata { + description: "Get the versions of the client-server API supported by this homeserver.", + method: GET, + name: "discover_homeserver", + path: "/.well-known/matrix/client", + rate_limited: false, + requires_authentication: false, + } + + request {} + + response { + /// Information about the homeserver to connect to. + #[serde(rename = "m.homeserver")] + pub homeserver: HomeserverInfo, + + /// Information about the identity server to connect to. + #[serde(rename = "m.identity_server")] + pub identity_server: Option, + } +} From c9b7b986c6303a4a731912126cf41aa3275f6328 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 1 May 2019 21:23:50 -0700 Subject: [PATCH 120/350] Add logout all endpoint. --- src/r0/session.rs | 1 + src/r0/session/logout_all.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/r0/session/logout_all.rs diff --git a/src/r0/session.rs b/src/r0/session.rs index 21ad699a..0ee3808b 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -2,3 +2,4 @@ pub mod login; pub mod logout; +pub mod logout_all; diff --git a/src/r0/session/logout_all.rs b/src/r0/session/logout_all.rs new file mode 100644 index 00000000..4815e539 --- /dev/null +++ b/src/r0/session/logout_all.rs @@ -0,0 +1,18 @@ +//! [POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout-all) + +use ruma_api_macros::ruma_api; + +ruma_api! { + metadata { + description: "Invalidates all access tokens for a user, so that they can no longer be used for authorization.", + method: POST, + name: "logout_all", + path: "/_matrix/client/r0/logout/all", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response {} +} From 94c368d2e690cc1f1221f0ea680f6cae60bc141f Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 8 May 2019 09:06:22 +0200 Subject: [PATCH 121/350] Correct description of homeserver discovery endpoint. --- src/unversioned/discover_homeserver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index b6ca5715..73e222dc 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -20,7 +20,7 @@ pub struct IdentityServerInfo { ruma_api! { metadata { - description: "Get the versions of the client-server API supported by this homeserver.", + description: "Get discovery information about the domain.", method: GET, name: "discover_homeserver", path: "/.well-known/matrix/client", From 95aea3b401612d77c8587e0b2f01ae5e980af7d9 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 2 Jun 2019 09:13:24 -0700 Subject: [PATCH 122/350] Use stable Rust on Travis. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec2e0706..44998ebc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,3 @@ notifications: channels: - secure: "WtuFMaASfrKlPbXWg7cAzxTLSggrix/jqizB3bdGbZTWg8MR0qoa90U9St6h5ELWMc+7mQjJSky0/KXD9BOVLSlok8E12xb8H5soPMW6GjYAek4+JzUeXPYSKNYkP29ZQc26Z9P9TyN/WvJoXIQbaWfMoPmr/g3Rn4z5PyeQgp1+AC54w5zLPtLLjh+WHPYhRoCT7iAsYlx0UazEw3i+aGyN+UdogimDD9ISUKFHOWyXJGyBzFxSpAYaRESnT4I0rJo6ETBkUbEopXvTRyClOsgEk1HRb82+kVNqkampeSDZyb2aCGLbRESd16xVbcE5J2HYu59p5zc00PINMf2nApDEkN/RHERZ4w9lMaxi/fH1TMQZwoNPEd/5n1EU/SLjKi7o/kLdTKEcZyTMd7IZA+TqXjFhKHQlYouOEv742TcWz3jg5+AEhKqjkcpDZTEuNHyMAS4onHg1M9pK2rVh3xmVQ1V2iYM8yY2+73SefJzigkhtXwgnJEv6fJc8IFSPOHtEUBx2KkZps6sRwUxVz5zMgV+4t1h9l4Mt8wOSojoKSxgtAhsHj8pqPysT7vUJPhY6hzzW2nhVHd8IUt49xRNktUr9s+B7yS1Up6+84GTmPmR3lUa+dbZ1PaI2K8VVyctiA4tbkk/n+EFqXL9FY2Gh8XbaWnb7fpWHrJRuZL4=" use_notice: true -rust: - - "nightly" From 21c2288d51cf4e719734b437ff84490eb400affc Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 2 Jun 2019 18:00:23 -0700 Subject: [PATCH 123/350] Fix serialization error due to url not supporting serde 1.x. --- Cargo.toml | 6 +++++- src/unversioned/discover_homeserver.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9da40445..ee1a425d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,12 @@ ruma-identifiers = "0.12.0" ruma-signatures = "0.4.2" serde_json = "1.0.39" serde_urlencoded = "0.5.4" -url = "1.7.2" +url_serde = "0.2.0" [dependencies.serde] version = "1.0.90" features = ["derive"] + +[dependencies.url] +version = "1.7.2" +features = ["serde"] diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index 73e222dc..5070419b 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -8,6 +8,7 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct HomeserverInfo { /// The base URL for the homeserver for client-server connections. + #[serde(with = "url_serde")] pub base_url: Url, } @@ -15,6 +16,7 @@ pub struct HomeserverInfo { #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct IdentityServerInfo { /// The base URL for the identity server for client-server connections. + #[serde(with = "url_serde")] pub base_url: Url, } From 4a4c2dd025de2433bd8c01ab5856fed8260cc259 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 2 Jun 2019 18:14:37 -0700 Subject: [PATCH 124/350] Add rustfmt and clippy to CI and address clippy warnings. --- .rustfmt.toml | 1 - .travis.yml | 8 ++++++++ src/lib.rs | 26 +++++++++++++++++++++++++- src/r0/room/create_room.rs | 2 +- src/r0/search/search_events.rs | 4 ++-- src/r0/session/login.rs | 4 ++-- src/r0/sync/get_message_events.rs | 2 +- src/r0/sync/sync_events.rs | 15 ++++++++++----- src/unversioned.rs | 2 +- 9 files changed, 50 insertions(+), 14 deletions(-) delete mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index 7d2cf549..00000000 --- a/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -merge_imports = true diff --git a/.travis.yml b/.travis.yml index 44998ebc..e8d453d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,12 @@ language: "rust" +before_script: + - "rustup component add rustfmt" + - "rustup component add clippy" +script: + - "cargo fmt --all -- --check" + - "cargo clippy --all-targets --all-features -- -D warnings" + - "cargo build --verbose" + - "cargo test --verbose" notifications: email: false irc: diff --git a/src/lib.rs b/src/lib.rs index 86c59f30..4ca111ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,31 @@ //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! shared by client and server code. -#![deny(missing_debug_implementations, missing_docs)] +#![deny( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + warnings +)] +#![warn( + clippy::empty_line_after_outer_attr, + clippy::expl_impl_clone_on_copy, + clippy::if_not_else, + clippy::items_after_statements, + clippy::match_same_arms, + clippy::mem_forget, + clippy::missing_docs_in_private_items, + clippy::multiple_inherent_impl, + clippy::mut_mut, + clippy::needless_borrow, + clippy::needless_continue, + clippy::single_match_else, + clippy::unicode_not_nfc, + clippy::use_self, + clippy::used_underscore_binding, + clippy::wrong_pub_self_convention, + clippy::wrong_self_convention +)] pub mod r0; pub mod unversioned; diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 8737dc10..a54f31f5 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -53,7 +53,7 @@ ruma_api! { } /// Extra options to be added to the `m.room.create` event. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct CreationContent { /// Whether users on other servers can join this room. /// diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index fd51bbcb..36814128 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -72,7 +72,7 @@ pub struct Criteria { } /// Configures whether any context for the events returned are included in the response. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { /// How many events after the result are returned. pub after_limit: u64, @@ -103,7 +103,7 @@ pub struct EventContextResult { } /// A grouping for partioning the result set. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct Grouping { /// The key within events to use for this grouping. pub key: GroupingKey, diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index a91fb1e1..fd76156c 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -53,7 +53,7 @@ ruma_api! { } /// The medium of a third party identifier. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Medium { /// An email address. #[serde(rename = "email")] @@ -61,7 +61,7 @@ pub enum Medium { } /// The authentication mechanism. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum LoginType { /// A password is supplied to authenticate. #[serde(rename = "m.login.password")] diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index d378796f..1078972b 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -52,7 +52,7 @@ ruma_api! { } /// The direction to return events from. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Direction { /// Return events backwards in time from the requested `from` token. #[serde(rename = "b")] diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 4ee05169..f152ca04 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -57,7 +57,7 @@ ruma_api! { } /// Whether to set presence or not during sync. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum SetPresence { /// Do not set the presence of the user calling this API. #[serde(rename = "offline")] @@ -80,16 +80,18 @@ pub enum Filter { // (there are probably some corner cases like leading whitespace) #[serde(with = "filter_def_serde")] /// A complete filter definition serialized to JSON. - FilterDefinition(FilterDefinition), + FilterDefinition(Box), /// The ID of a filter saved on the server. FilterId(String), } +/// Serialization and deserialization logic for filter definitions. mod filter_def_serde { use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer}; use crate::r0::filter::FilterDefinition; + /// Serialization logic for filter definitions. pub fn serialize(filter_def: &FilterDefinition, serializer: S) -> Result where S: Serializer, @@ -98,12 +100,15 @@ mod filter_def_serde { serializer.serialize_str(&string) } - pub fn deserialize<'de, D>(deserializer: D) -> Result + /// Deserialization logic for filter definitions. + pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let filter_str = <&str>::deserialize(deserializer)?; - serde_json::from_str(filter_str).map_err(D::Error::custom) + serde_json::from_str(filter_str) + .map(Box::new) + .map_err(D::Error::custom) } } @@ -147,7 +152,7 @@ pub struct JoinedRoom { } /// unread notifications count -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/unversioned.rs b/src/unversioned.rs index e77bcd06..1622a72d 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -1,4 +1,4 @@ //! Endpoints that cannot change with new versions of the Matrix specification. -pub mod get_supported_versions; pub mod discover_homeserver; +pub mod get_supported_versions; From a16eb7cfe11fbd9b07b82e0a112b61fdff154757 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 16 Jun 2019 16:32:56 -0700 Subject: [PATCH 125/350] Use js_int types for numbers. See https://github.com/ruma/ruma-events/issues/27 for rationale. --- Cargo.toml | 18 +++++++++++------- .../account/request_password_change_token.rs | 3 ++- src/r0/account/request_register_token.rs | 3 ++- .../request_contact_verification_token.rs | 3 ++- src/r0/directory/get_public_rooms.rs | 3 ++- src/r0/filter.rs | 5 +++-- src/r0/media/get_content_thumbnail.rs | 5 +++-- src/r0/presence/get_presence.rs | 3 ++- src/r0/search/search_events.rs | 9 +++++---- src/r0/server/get_user_info.rs | 3 ++- src/r0/sync/get_message_events.rs | 3 ++- src/r0/sync/sync_events.rs | 7 ++++--- src/r0/typing/create_typing_event.rs | 3 ++- src/r0/voip/get_turn_server_info.rs | 3 ++- 14 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee1a425d..20166ba6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,20 +12,24 @@ version = "0.3.0" edition = "2018" [dependencies] -futures = "0.1.26" +futures = "0.1.27" http = "0.1.17" -hyper = "0.12.27" -ruma-api = "0.7.0" -ruma-api-macros = "0.4.0" +hyper = "0.12.29" +ruma-api = "0.8.0" +ruma-api-macros = "0.5.0" ruma-events = "0.12.0" -ruma-identifiers = "0.12.0" +ruma-identifiers = "0.13.0" ruma-signatures = "0.4.2" serde_json = "1.0.39" -serde_urlencoded = "0.5.4" +serde_urlencoded = "0.5.5" url_serde = "0.2.0" +[dependencies.js_int] +version = "0.1.0" +features = ["serde"] + [dependencies.serde] -version = "1.0.90" +version = "1.0.92" features = ["derive"] [dependencies.url] diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs index 53a207e0..56394bfa 100644 --- a/src/r0/account/request_password_change_token.rs +++ b/src/r0/account/request_password_change_token.rs @@ -1,5 +1,6 @@ //! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) +use js_int::UInt; use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -22,7 +23,7 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, /// TODO: This parameter is not documented in the spec. - pub send_attempt: u64, + pub send_attempt: UInt, } response {} diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs index cd391063..628ffc4d 100644 --- a/src/r0/account/request_register_token.rs +++ b/src/r0/account/request_register_token.rs @@ -1,5 +1,6 @@ //! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) +use js_int::UInt; use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -22,7 +23,7 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: u64, + pub send_attempt: UInt, } response {} diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index d6bf95a6..3eade882 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -1,5 +1,6 @@ //! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) +use js_int::UInt; use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -22,7 +23,7 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: u64, + pub send_attempt: UInt, } response {} diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 1eb1c28d..6a70fd83 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; use serde::{Deserialize, Serialize}; @@ -43,7 +44,7 @@ pub struct PublicRoomsChunk { #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, /// The number of members joined to the room. - pub num_joined_members: u64, + pub num_joined_members: UInt, /// The ID of the room. pub room_id: RoomId, /// The topic of the room, if any. diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 3be8cd30..95304bdf 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -3,6 +3,7 @@ pub mod create_filter; pub mod get_filter; +use js_int::UInt; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -37,7 +38,7 @@ pub struct RoomEventFilter { pub not_rooms: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option, /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. @@ -117,7 +118,7 @@ pub struct Filter { pub not_types: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option, /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index e13e340f..033864f2 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) +use js_int::UInt; use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -34,14 +35,14 @@ ruma_api! { /// The *desired* height of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] - pub height: Option, + pub height: Option, /// The desired resizing method. #[ruma_api(query)] pub method: Option, /// The *desired* width of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] - pub width: Option, + pub width: Option, } response { diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index f1e8ea86..010894af 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status) +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; @@ -30,7 +31,7 @@ ruma_api! { pub currently_active: Option, /// The length of time in milliseconds since an action was performed by the user. #[serde(skip_serializing_if = "Option::is_none")] - pub last_active_ago: Option, + pub last_active_ago: Option, /// The user's presence state. pub presence: PresenceState, } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 36814128..368d1113 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_events::collections::all::Event; use ruma_identifiers::{EventId, RoomId, UserId}; @@ -75,9 +76,9 @@ pub struct Criteria { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { /// How many events after the result are returned. - pub after_limit: u64, + pub after_limit: UInt, /// How many events before the result are returned. - pub before_limit: u64, + pub before_limit: UInt, /// Requests that the server returns the historic profile information for the users that /// sent the events that were returned. pub include_profile: bool, @@ -165,7 +166,7 @@ pub struct ResultCategories { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomEventResults { /// An approximate count of the total number of results found. - pub count: u64, + pub count: UInt, /// Any groups that were requested. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 pub groups: HashMap>, @@ -191,7 +192,7 @@ pub struct ResultGroup { #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, /// Key that can be used to order different groups. - pub order: u64, + pub order: UInt, /// Which results are in this group. pub results: Vec, } diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index e45e385f..1c16795f 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; @@ -36,7 +37,7 @@ pub struct ConnectionInfo { /// Most recently seen IP address of the session. pub ip: String, /// Unix timestamp that the session was last active. - pub last_seen: u64, + pub last_seen: UInt, /// User agent string last seen in the session. pub user_agent: String, } diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 1078972b..4498bcdf 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages) +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; @@ -38,7 +39,7 @@ ruma_api! { /// /// Default: 10. #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option, } response { diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index f152ca04..5bdc1048 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_events::{ collections::{all, only}, @@ -42,7 +43,7 @@ ruma_api! { /// The maximum time to poll in milliseconds before returning this request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub timeout: Option, + pub timeout: Option, } response { @@ -156,10 +157,10 @@ pub struct JoinedRoom { pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. #[serde(skip_serializing_if = "Option::is_none")] - pub highlight_count: Option, + pub highlight_count: Option, /// The total number of unread notifications for this room. #[serde(skip_serializing_if = "Option::is_none")] - pub notification_count: Option, + pub notification_count: Option, } /// Events in the room. diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index e928c4ef..d1178596 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -1,5 +1,6 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) +use js_int::UInt; use ruma_api_macros::ruma_api; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -20,7 +21,7 @@ ruma_api! { pub room_id: RoomId, /// The length of time in milliseconds to mark this user as typing. #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + pub timeout: Option, /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. pub typing: bool, /// The user who has started to type. diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 52260261..03fce2c3 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) +use js_int::UInt; use ruma_api_macros::ruma_api; use serde::{Deserialize, Serialize}; @@ -19,7 +20,7 @@ ruma_api! { /// The password to use. pub password: String, /// The time-to-live in seconds. - pub ttl: u64, + pub ttl: UInt, /// A list of TURN URIs. pub uris: Vec, /// The username to use. From 2eeb90ed5574f471df3a98d95133ea311a262ed3 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 16 Jun 2019 16:46:02 -0700 Subject: [PATCH 126/350] Add crates.io categories. [ci skip] --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 20166ba6..858d8589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [package] authors = ["Jimmy Cuadra "] +categories = ["api-bindings", "web-programming"] description = "Types for the endpoints in the Matrix client-server API." documentation = "https://docs.rs/ruma-client-api" homepage = "https://github.com/ruma/ruma-client-api" From e7e4d04244eafc6d8633aaddf54b157e524fd5ad Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 8 Jul 2019 14:24:07 -0700 Subject: [PATCH 127/350] Undo the change of storing FilterDefinition in a box. On second thought, it doesn't make sense to change this just cause of a clippy warning. We'll wait and see if it ever causes and real problems before making the API less consistent just to avoid a potential space saving issue. --- src/r0/sync/sync_events.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 5bdc1048..45d95b6f 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -67,6 +67,7 @@ pub enum SetPresence { /// A filter represented either as its full JSON definition or the ID of a saved filter. #[derive(Clone, Debug, Deserialize, Serialize)] +#[allow(clippy::large_enum_variant)] #[serde(untagged)] pub enum Filter { // The filter definition needs to be (de)serialized twice because it is a URL-encoded JSON @@ -81,7 +82,7 @@ pub enum Filter { // (there are probably some corner cases like leading whitespace) #[serde(with = "filter_def_serde")] /// A complete filter definition serialized to JSON. - FilterDefinition(Box), + FilterDefinition(FilterDefinition), /// The ID of a filter saved on the server. FilterId(String), } @@ -102,14 +103,13 @@ mod filter_def_serde { } /// Deserialization logic for filter definitions. - pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> + pub fn deserialize<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { let filter_str = <&str>::deserialize(deserializer)?; - serde_json::from_str(filter_str) - .map(Box::new) - .map_err(D::Error::custom) + + serde_json::from_str(filter_str).map_err(D::Error::custom) } } From 7a688395624e31a1b0c169a52e0ef106743b578b Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 24 Jul 2019 22:45:53 -0700 Subject: [PATCH 128/350] Run cargo-audit on CI. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index e8d453d5..81ffad9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,12 @@ language: "rust" +cache: "cargo" before_script: - "rustup component add rustfmt" - "rustup component add clippy" + - "cargo install --force cargo-audit" + - "cargo generate-lockfile" script: + - "cargo audit" - "cargo fmt --all -- --check" - "cargo clippy --all-targets --all-features -- -D warnings" - "cargo build --verbose" From 90b850a60d1d938d6313cfa4684008d81f41bda8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 19 Jul 2019 22:05:11 +0200 Subject: [PATCH 129/350] Update dependencies (except ruma-events) --- Cargo.toml | 19 ++++++------------- src/r0/account/change_password.rs | 3 +-- src/r0/account/deactivate.rs | 2 +- src/r0/account/register.rs | 2 +- .../account/request_password_change_token.rs | 3 +-- src/r0/account/request_register_token.rs | 3 +-- src/r0/account/whoami.rs | 3 +-- src/r0/alias/create_alias.rs | 3 +-- src/r0/alias/delete_alias.rs | 4 ++-- src/r0/alias/get_alias.rs | 3 +-- src/r0/config/set_global_account_data.rs | 3 +-- src/r0/config/set_room_account_data.rs | 3 +-- src/r0/contact/create_contact.rs | 2 +- src/r0/contact/get_contacts.rs | 2 +- .../request_contact_verification_token.rs | 3 +-- src/r0/context/get_context.rs | 3 +-- src/r0/directory/get_public_rooms.rs | 2 +- src/r0/filter/create_filter.rs | 3 +-- src/r0/filter/get_filter.rs | 4 ++-- src/r0/media/create_content.rs | 5 ++--- src/r0/media/get_content.rs | 7 +++---- src/r0/media/get_content_thumbnail.rs | 2 +- src/r0/membership.rs | 5 +++-- src/r0/membership/ban_user.rs | 3 +-- src/r0/membership/forget_room.rs | 3 +-- src/r0/membership/invite_user.rs | 3 +-- src/r0/membership/join_room_by_id.rs | 3 +-- src/r0/membership/join_room_by_id_or_alias.rs | 3 +-- src/r0/membership/joined_members.rs | 2 +- src/r0/membership/joined_rooms.rs | 3 +-- src/r0/membership/kick_user.rs | 3 +-- src/r0/membership/leave_room.rs | 3 +-- src/r0/membership/unban_user.rs | 4 ++-- src/r0/presence/get_presence.rs | 3 +-- src/r0/presence/get_subscribed_presences.rs | 3 +-- src/r0/presence/set_presence.rs | 3 +-- .../presence/update_presence_subscriptions.rs | 3 +-- src/r0/profile/get_avatar_url.rs | 3 +-- src/r0/profile/get_display_name.rs | 3 +-- src/r0/profile/get_profile.rs | 4 ++-- src/r0/profile/set_avatar_url.rs | 4 ++-- src/r0/profile/set_display_name.rs | 3 +-- src/r0/receipt/create_receipt.rs | 2 +- src/r0/redact/redact_event.rs | 3 +-- src/r0/room/create_room.rs | 2 +- src/r0/search/search_events.rs | 2 +- src/r0/send/send_message_event.rs | 3 +-- src/r0/send/send_state_event_for_empty_key.rs | 4 ++-- src/r0/send/send_state_event_for_key.rs | 3 +-- src/r0/server/get_user_info.rs | 2 +- src/r0/session/login.rs | 2 +- src/r0/session/logout.rs | 2 +- src/r0/session/logout_all.rs | 2 +- src/r0/sync/get_member_events.rs | 4 ++-- src/r0/sync/get_message_events.rs | 2 +- src/r0/sync/get_state_events.rs | 3 +-- src/r0/sync/get_state_events_for_empty_key.rs | 3 +-- src/r0/sync/get_state_events_for_key.rs | 3 +-- src/r0/sync/sync_events.rs | 2 +- src/r0/tag/create_tag.rs | 3 +-- src/r0/tag/delete_tag.rs | 3 +-- src/r0/tag/get_tags.rs | 3 +-- src/r0/typing/create_typing_event.rs | 3 +-- src/r0/voip/get_turn_server_info.rs | 3 +-- src/unversioned/discover_homeserver.rs | 4 +--- src/unversioned/get_supported_versions.rs | 3 +-- 66 files changed, 83 insertions(+), 131 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 858d8589..d4e37054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,26 +13,19 @@ version = "0.3.0" edition = "2018" [dependencies] -futures = "0.1.27" -http = "0.1.17" -hyper = "0.12.29" -ruma-api = "0.8.0" -ruma-api-macros = "0.5.0" +ruma-api = "0.10.0" ruma-events = "0.12.0" -ruma-identifiers = "0.13.0" -ruma-signatures = "0.4.2" -serde_json = "1.0.39" -serde_urlencoded = "0.5.5" -url_serde = "0.2.0" +ruma-identifiers = "0.14.0" +serde_json = "1.0.40" [dependencies.js_int] -version = "0.1.0" +version = "0.1.1" features = ["serde"] [dependencies.serde] -version = "1.0.92" +version = "1.0.98" features = ["derive"] [dependencies.url] -version = "1.7.2" +version = "2.0.0" features = ["serde"] diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index a69bc750..eb8a074d 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -1,7 +1,6 @@ //! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password) -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index ff7919a8..99fa8fcc 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-deactivate) // TODO: missing request parameters -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 1a08df4e..a83da7cc 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs index 56394bfa..976ba5fd 100644 --- a/src/r0/account/request_password_change_token.rs +++ b/src/r0/account/request_password_change_token.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) use js_int::UInt; -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs index 628ffc4d..d06321cc 100644 --- a/src/r0/account/request_register_token.rs +++ b/src/r0/account/request_register_token.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) use js_int::UInt; -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/account/whoami.rs b/src/r0/account/whoami.rs index 199fea39..8ae9414f 100644 --- a/src/r0/account/whoami.rs +++ b/src/r0/account/whoami.rs @@ -1,7 +1,6 @@ //! [GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-whoami) -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index bf23bc41..9cf460cf 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -1,8 +1,7 @@ //! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-directory-room-roomalias) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index 119aa68c..85ff53d2 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -1,8 +1,8 @@ //! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-directory-room-roomalias) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::RoomAliasId; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index 26ff81ca..93dca32a 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-directory-room-roomalias) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index 4a41561f..0c9a4751 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -1,8 +1,7 @@ //! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-account-data-type) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 43bf2ec2..86e3c343 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -1,8 +1,7 @@ //! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/contact/create_contact.rs b/src/r0/contact/create_contact.rs index eed34509..5b246cd4 100644 --- a/src/r0/contact/create_contact.rs +++ b/src/r0/contact/create_contact.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; ruma_api! { diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 4243c594..c7ba4814 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; ruma_api! { diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index 3eade882..eb12902c 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) use js_int::UInt; -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index a567e6e5..f3596019 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::collections::only; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 6a70fd83..301af00a 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; use serde::{Deserialize, Serialize}; diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs index 1cacee78..e6486860 100644 --- a/src/r0/filter/create_filter.rs +++ b/src/r0/filter/create_filter.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-user-userid-filter) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; use super::FilterDefinition; diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index 0f8bea5a..dd9a9389 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -1,8 +1,8 @@ //! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-filter-filterid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use super::FilterDefinition; diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index c6ccc779..5cc22aec 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -1,7 +1,6 @@ //! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-media-r0-upload) -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { @@ -19,7 +18,7 @@ ruma_api! { #[ruma_api(query)] pub filename: Option, /// The content type of the file being uploaded. - #[ruma_api(header = "CONTENT_TYPE")] + #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, /// The file contents to upload. #[ruma_api(body)] diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index d8a974be..83f9d937 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -2,8 +2,7 @@ //! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-download-servername-mediaid) -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { @@ -29,10 +28,10 @@ ruma_api! { #[ruma_api(body)] pub file: Vec, /// The content type of the file that was previously uploaded. - #[ruma_api(header = "CONTENT_TYPE")] + #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, /// The name of the file that was previously uploaded, if set. - #[ruma_api(header = "CONTENT_DISPOSITION")] + #[ruma_api(header = CONTENT_DISPOSITION)] pub content_disposition: String, } } diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 033864f2..82bea3d4 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; /// The desired resizing method. diff --git a/src/r0/membership.rs b/src/r0/membership.rs index d86584f6..833857dc 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -11,7 +11,8 @@ pub mod kick_user; pub mod leave_room; pub mod unban_user; -use ruma_signatures::Signatures; +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } @@ -26,7 +27,7 @@ pub struct ThirdPartySigned { /// The Matrix ID of the user who issued the invite. pub sender: String, /// A signatures object containing a signature of the entire signed object. - pub signatures: Signatures, + pub signatures: HashMap>, /// The state key of the m.third_party_invite event. pub token: String, } diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs index 9520a3bb..01f6636c 100644 --- a/src/r0/membership/ban_user.rs +++ b/src/r0/membership/ban_user.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-ban) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs index be0b613a..360a4a51 100644 --- a/src/r0/membership/forget_room.rs +++ b/src/r0/membership/forget_room.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-forget) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index 8253b5dc..f0d59871 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-invite) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs index bd9c2691..81fdca02 100644 --- a/src/r0/membership/join_room_by_id.rs +++ b/src/r0/membership/join_room_by_id.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-join) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; use super::ThirdPartySigned; diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index 467e5de5..bd0bf5e8 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-join-roomidoralias) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; -use serde::{Deserialize, Serialize}; use super::ThirdPartySigned; diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index d7f7028e..614c0809 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; diff --git a/src/r0/membership/joined_rooms.rs b/src/r0/membership/joined_rooms.rs index f98beb48..c1266525 100644 --- a/src/r0/membership/joined_rooms.rs +++ b/src/r0/membership/joined_rooms.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs index e075b1b6..1d70a8e0 100644 --- a/src/r0/membership/kick_user.rs +++ b/src/r0/membership/kick_user.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-kick) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs index f84c04a6..50e2a398 100644 --- a/src/r0/membership/leave_room.rs +++ b/src/r0/membership/leave_room.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-leave) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index 859c6ad1..18746670 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -1,8 +1,8 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-unban) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 010894af..d06e35e2 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -1,10 +1,9 @@ //! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status) use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index 6fc323a1..d9bf384a 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-list-userid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::presence::PresenceEvent; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs index bfca3309..5d0aa325 100644 --- a/src/r0/presence/set_presence.rs +++ b/src/r0/presence/set_presence.rs @@ -1,9 +1,8 @@ //! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-presence-userid-status) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs index 3aacbd05..7832967c 100644 --- a/src/r0/presence/update_presence_subscriptions.rs +++ b/src/r0/presence/update_presence_subscriptions.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-presence-list-userid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs index 30887550..8f91296c 100644 --- a/src/r0/profile/get_avatar_url.rs +++ b/src/r0/profile/get_avatar_url.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-avatar-url) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs index f9f6e298..47d033a4 100644 --- a/src/r0/profile/get_display_name.rs +++ b/src/r0/profile/get_display_name.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-displayname) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index 457624ab..6526032f 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -1,8 +1,8 @@ //! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index 778dda30..65eb1c33 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -1,8 +1,8 @@ //! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-avatar-url) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs index 01c4cd34..37bf8230 100644 --- a/src/r0/profile/set_display_name.rs +++ b/src/r0/profile/set_display_name.rs @@ -1,8 +1,7 @@ //! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-displayname) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 58d6f933..02915540 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -2,7 +2,7 @@ use std::fmt::{Display, Error as FmtError, Formatter}; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; use serde::{Deserialize, Serialize}; diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs index d2845fb5..b79f813c 100644 --- a/src/r0/redact/redact_event.rs +++ b/src/r0/redact/redact_event.rs @@ -1,8 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index a54f31f5..3bdce4b5 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-createroom) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 368d1113..14fd814a 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::collections::all::Event; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index 4f55978c..c97fd0a1 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,9 +1,8 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::{room::message::MessageEventContent, EventType}; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/send/send_state_event_for_empty_key.rs index f6b10396..2b51874c 100644 --- a/src/r0/send/send_state_event_for_empty_key.rs +++ b/src/r0/send/send_state_event_for_empty_key.rs @@ -1,9 +1,9 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use serde_json::Value; ruma_api! { diff --git a/src/r0/send/send_state_event_for_key.rs b/src/r0/send/send_state_event_for_key.rs index 335de505..7286bcee 100644 --- a/src/r0/send/send_state_event_for_key.rs +++ b/src/r0/send/send_state_event_for_key.rs @@ -1,9 +1,8 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; use serde_json::Value; ruma_api! { diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 1c16795f..c5a59d64 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index fd76156c..720ad1a5 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; diff --git a/src/r0/session/logout.rs b/src/r0/session/logout.rs index 1f3286f2..5f3b5090 100644 --- a/src/r0/session/logout.rs +++ b/src/r0/session/logout.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/session/logout_all.rs b/src/r0/session/logout_all.rs index 4815e539..b8613c05 100644 --- a/src/r0/session/logout_all.rs +++ b/src/r0/session/logout_all.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout-all) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index c4e0d20a..e1f7cf5f 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -1,9 +1,9 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-members) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::room::member::MemberEvent; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 4498bcdf..6c573dc0 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages) use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index 766e0db2..0636ac73 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::collections::only; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/sync/get_state_events_for_empty_key.rs index e690e61b..d2b03a54 100644 --- a/src/r0/sync/get_state_events_for_empty_key.rs +++ b/src/r0/sync/get_state_events_for_empty_key.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/sync/get_state_events_for_key.rs index a26527c8..bdeeb5ac 100644 --- a/src/r0/sync/get_state_events_for_key.rs +++ b/src/r0/sync/get_state_events_for_key.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 45d95b6f..84aaa945 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::{ collections::{all, only}, stripped, diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs index 93c57b5f..4aef78dc 100644 --- a/src/r0/tag/create_tag.rs +++ b/src/r0/tag/create_tag.rs @@ -1,9 +1,8 @@ //! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::tag::TagInfo; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs index 9ad3bbdc..ffe3adbe 100644 --- a/src/r0/tag/delete_tag.rs +++ b/src/r0/tag/delete_tag.rs @@ -1,8 +1,7 @@ //! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index ddc384e8..019bc4df 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,9 +1,8 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_events::tag::TagEventContent; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index d1178596..29356e12 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -1,9 +1,8 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) use js_int::UInt; -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; ruma_api! { metadata { diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 03fce2c3..15df4e77 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) use js_int::UInt; -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index 5070419b..96b66769 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -1,6 +1,6 @@ //! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-well-known-matrix-client) -use ruma_api_macros::ruma_api; +use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; use url::Url; @@ -8,7 +8,6 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct HomeserverInfo { /// The base URL for the homeserver for client-server connections. - #[serde(with = "url_serde")] pub base_url: Url, } @@ -16,7 +15,6 @@ pub struct HomeserverInfo { #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct IdentityServerInfo { /// The base URL for the identity server for client-server connections. - #[serde(with = "url_serde")] pub base_url: Url, } diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 3d0538ef..5d98b957 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,7 +1,6 @@ //! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-versions) -use ruma_api_macros::ruma_api; -use serde::{Deserialize, Serialize}; +use ruma_api::ruma_api; ruma_api! { metadata { From 7dffd7b7501cda08ed8b9323b8bf0974d7d0fa6a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 3 Aug 2019 14:01:01 -0700 Subject: [PATCH 130/350] Only build PRs and the master branch on CI. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 81ffad9b..bc6fbfec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ script: - "cargo clippy --all-targets --all-features -- -D warnings" - "cargo build --verbose" - "cargo test --verbose" +if: "type != push OR (tag IS blank AND branch = master)" notifications: email: false irc: From 11eba710839dfb6a4fb9bbce0afbab1cb4f3f532 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 4 Aug 2019 17:43:14 +0200 Subject: [PATCH 131/350] Remove remaining unused imports --- src/r0/alias/delete_alias.rs | 1 - src/r0/filter/get_filter.rs | 1 - src/r0/membership/unban_user.rs | 1 - src/r0/profile/get_profile.rs | 1 - src/r0/profile/set_avatar_url.rs | 1 - src/r0/send/send_state_event_for_empty_key.rs | 1 - src/r0/sync/get_member_events.rs | 1 - 7 files changed, 7 deletions(-) diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index 85ff53d2..dc8dfd5f 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use ruma_identifiers::RoomAliasId; -use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index dd9a9389..e074b15c 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::Deserialize; use super::FilterDefinition; diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index 18746670..20eda03f 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index 6526032f..54a2326f 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index 65eb1c33..c78edd32 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde::Deserialize; ruma_api! { metadata { diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/send/send_state_event_for_empty_key.rs index 2b51874c..0820ed80 100644 --- a/src/r0/send/send_state_event_for_empty_key.rs +++ b/src/r0/send/send_state_event_for_empty_key.rs @@ -3,7 +3,6 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde::Deserialize; use serde_json::Value; ruma_api! { diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index e1f7cf5f..2b1919e5 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -3,7 +3,6 @@ use ruma_api::ruma_api; use ruma_events::room::member::MemberEvent; use ruma_identifiers::RoomId; -use serde::Deserialize; ruma_api! { metadata { From 6a5af6bf8bd91ccb55e4a853ff42e98796fd4f1b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 5 Aug 2019 12:13:52 +0200 Subject: [PATCH 132/350] Make inclusion lists in event filters optional to be able to distinguish between no inclusion list (everything is included) and an empty inclusion list (nothing is included) --- src/r0/filter.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 95304bdf..952c7165 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -42,9 +42,9 @@ pub struct RoomEventFilter { /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub rooms: Vec, + pub rooms: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even @@ -55,16 +55,16 @@ pub struct RoomEventFilter { /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub senders: Vec, + pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub types: Vec, + pub types: Option>, } /// Filters to be applied to room data @@ -100,9 +100,9 @@ pub struct RoomFilter { /// /// If this list is absent then all rooms are included. This filter is applied before the /// filters in `ephemeral`, `state`, `timeline` or `account_data`. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub rooms: Vec, + pub rooms: Option>, } /// Filter for not-room data @@ -122,16 +122,16 @@ pub struct Filter { /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub senders: Vec, + pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub types: Vec, + pub types: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even @@ -150,9 +150,9 @@ pub struct FilterDefinition { /// to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' /// object. A literal '.' character in a field name may be escaped using a '\'. A server may /// include more fields than were requested. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - pub event_fields: Vec, + pub event_fields: Option>, /// The format to use for events. /// /// 'client' will return the events in a format suitable for clients. 'federation' will return From 05f181d9f12fca28cea3b5bbf18af2fad6134799 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 9 Aug 2019 00:36:56 +0200 Subject: [PATCH 133/350] Make serde_json::Value usage consistent --- src/r0/sync/get_state_events_for_empty_key.rs | 3 ++- src/r0/sync/get_state_events_for_key.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/sync/get_state_events_for_empty_key.rs index d2b03a54..88a0554d 100644 --- a/src/r0/sync/get_state_events_for_empty_key.rs +++ b/src/r0/sync/get_state_events_for_empty_key.rs @@ -3,6 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; +use serde_json::Value; ruma_api! { metadata { @@ -26,6 +27,6 @@ ruma_api! { response { /// The content of the state event. #[ruma_api(body)] - pub content: ::serde_json::Value, + pub content: Value, } } diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/sync/get_state_events_for_key.rs index bdeeb5ac..085b334c 100644 --- a/src/r0/sync/get_state_events_for_key.rs +++ b/src/r0/sync/get_state_events_for_key.rs @@ -3,6 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; +use serde_json::Value; ruma_api! { metadata { @@ -29,6 +30,6 @@ ruma_api! { response { /// The content of the state event. #[ruma_api(body)] - pub content: ::serde_json::Value, + pub content: Value, } } From 98e0bad1b1f53f6376c3bc3a8bc752f1b54b35bb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 9 Aug 2019 00:13:14 +0200 Subject: [PATCH 134/350] Update to the new ruma-events API --- Cargo.toml | 4 ++-- src/r0/context/get_context.rs | 10 +++++----- src/r0/presence/get_subscribed_presences.rs | 4 ++-- src/r0/search/search_events.rs | 8 ++++---- src/r0/send/send_message_event.rs | 4 ++-- src/r0/sync/get_member_events.rs | 4 ++-- src/r0/sync/get_message_events.rs | 4 ++-- src/r0/sync/get_state_events.rs | 4 ++-- src/r0/sync/sync_events.rs | 14 +++++++------- src/r0/tag/get_tags.rs | 4 ++-- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4e37054..e913bd31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,12 @@ edition = "2018" [dependencies] ruma-api = "0.10.0" -ruma-events = "0.12.0" +ruma-events = { git = "https://github.com/ruma/ruma-events", branch = "event-result-stub" } ruma-identifiers = "0.14.0" serde_json = "1.0.40" [dependencies.js_int] -version = "0.1.1" +version = "0.1.2" features = ["serde"] [dependencies.serde] diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index f3596019..e518dfd6 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) use ruma_api::ruma_api; -use ruma_events::collections::only; +use ruma_events::{collections::only, EventResult}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -32,16 +32,16 @@ ruma_api! { /// A token that can be used to paginate forwards with. pub end: String, /// Details of the requested event. - pub event: only::RoomEvent, + pub event: EventResult, /// A list of room events that happened just after the requested event, in chronological /// order. - pub events_after: Vec, + pub events_after: Vec>, /// A list of room events that happened just before the requested event, in /// reverse-chronological order. - pub events_before: Vec, + pub events_before: Vec>, /// A token that can be used to paginate backwards with. pub start: String, /// The state of the room at the last event returned. - pub state: Vec, + pub state: Vec>, } } diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index d9bf384a..656b1c8a 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-list-userid) use ruma_api::ruma_api; -use ruma_events::presence::PresenceEvent; +use ruma_events::{presence::PresenceEvent, EventResult}; use ruma_identifiers::UserId; ruma_api! { @@ -23,6 +23,6 @@ ruma_api! { response { /// A list of presence events for every user on this list. #[ruma_api(body)] - pub presence_events: Vec, + pub presence_events: Vec>, } } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 14fd814a..58796f89 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::collections::all::Event; +use ruma_events::{collections::all::Event, EventResult}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -91,10 +91,10 @@ pub struct EventContextResult { pub end: String, /// Events just after the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>, + pub events_after: Option>>, /// Events just before the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>, + pub events_before: Option>>, /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] @@ -206,7 +206,7 @@ pub struct SearchResult { /// A number that describes how closely this result matches the search. Higher is closer. pub rank: f64, /// The event that matched. - pub result: Event, + pub result: EventResult, } /// A user profile. diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index c97fd0a1..46b3043f 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,7 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventType}; +use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,7 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] - pub data: MessageEventContent, + pub data: EventResult, // FIXME } response { diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index 2b1919e5..aa5c9fcd 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-members) use ruma_api::ruma_api; -use ruma_events::room::member::MemberEvent; +use ruma_events::{room::member::MemberEvent, EventResult}; use ruma_identifiers::RoomId; ruma_api! { @@ -22,6 +22,6 @@ ruma_api! { response { /// A list of member events. - pub chunk: Vec + pub chunk: Vec> } } diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 6c573dc0..56c542c2 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::collections::only; +use ruma_events::{collections::only, EventResult}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -46,7 +46,7 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - pub chunk: Vec, + pub chunk: Vec>, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index 0636ac73..dd122f65 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) use ruma_api::ruma_api; -use ruma_events::collections::only; +use ruma_events::{collections::only, EventResult}; use ruma_identifiers::RoomId; ruma_api! { @@ -25,6 +25,6 @@ ruma_api! { /// list of events. If the user has left the room then this will be the state of the /// room when they left as a list of events. #[ruma_api(body)] - pub room_state: Vec, + pub room_state: Vec>, } } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 84aaa945..e054c42e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -6,7 +6,7 @@ use js_int::UInt; use ruma_api::ruma_api; use ruma_events::{ collections::{all, only}, - stripped, + stripped, EventResult, }; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -172,28 +172,28 @@ pub struct Timeline { /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, /// A list of events. - pub events: Vec, + pub events: Vec>, } /// State events in the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct State { /// A list of state events. - pub events: Vec, + pub events: Vec>, } /// The private data that this user has attached to this room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AccountData { /// A list of events. - pub events: Vec, + pub events: Vec>, } /// Ephemeral events not recorded in the timeline or state of the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Ephemeral { /// A list of events. - pub events: Vec, + pub events: Vec>, } /// Updates to the rooms that the user has been invited to. @@ -207,12 +207,12 @@ pub struct InvitedRoom { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InviteState { /// A list of state events. - pub events: Vec, + pub events: Vec>, } /// Updates to the presence status of other users. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Presence { /// A list of events. - pub events: Vec, + pub events: Vec>, } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 019bc4df..4f0abea0 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) use ruma_api::ruma_api; -use ruma_events::tag::TagEventContent; +use ruma_events::{tag::TagEventContent, EventResult}; use ruma_identifiers::{RoomId, UserId}; ruma_api! { @@ -25,6 +25,6 @@ ruma_api! { response { /// The user's tags for the room. - pub tags: TagEventContent, + pub tags: EventResult, } } From 2022dcc5f2c4f4f0ee1f17e4cdefd3a3d5d8613e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 14 Oct 2019 22:14:01 +0200 Subject: [PATCH 135/350] Update deps --- Cargo.toml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e913bd31..adddb456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,19 +13,10 @@ version = "0.3.0" edition = "2018" [dependencies] +js_int = { version = "0.1.2", features = ["serde"] } ruma-api = "0.10.0" -ruma-events = { git = "https://github.com/ruma/ruma-events", branch = "event-result-stub" } +ruma-events = { git = "https://github.com/ruma/ruma-events", branch = "event-result-2" } ruma-identifiers = "0.14.0" -serde_json = "1.0.40" - -[dependencies.js_int] -version = "0.1.2" -features = ["serde"] - -[dependencies.serde] -version = "1.0.98" -features = ["derive"] - -[dependencies.url] -version = "2.0.0" -features = ["serde"] +serde = { version = "1.0.101", features = ["derive"] } +serde_json = "1.0.41" +url = { version = "2.1.0", features = ["serde"] } From 4ad8ee7d08db3cda434ba420cdb37de0bf0c325c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Oct 2019 00:23:53 +0200 Subject: [PATCH 136/350] Switch ruma-api branch --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index adddb456..25c4f9e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.10.0" +ruma-api = { git = "https://github.com/ruma/ruma-api", branch = "serverless" } ruma-events = { git = "https://github.com/ruma/ruma-events", branch = "event-result-2" } ruma-identifiers = "0.14.0" serde = { version = "1.0.101", features = ["derive"] } From 134738f6766c2e6abceb6718525d9eb2c8c42e70 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Oct 2019 00:41:18 +0200 Subject: [PATCH 137/350] Remove stuff only needed for server-side usage --- src/r0/search/search_events.rs | 8 ++++---- src/r0/send/send_message_event.rs | 4 ++-- src/r0/sync/sync_events.rs | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 58796f89..e9d67459 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -85,7 +85,7 @@ pub struct EventContext { } /// Context for search results, if requested. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct EventContextResult { /// Pagination token for the end of the chunk. pub end: String, @@ -155,7 +155,7 @@ pub enum OrderBy { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct ResultCategories { /// Room event results. #[serde(skip_serializing_if = "Option::is_none")] @@ -163,7 +163,7 @@ pub struct ResultCategories { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct RoomEventResults { /// An approximate count of the total number of results found. pub count: UInt, @@ -198,7 +198,7 @@ pub struct ResultGroup { } /// A search result. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct SearchResult { /// Context for result, if requested. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index 46b3043f..c97fd0a1 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,7 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; +use ruma_events::{room::message::MessageEventContent, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,7 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] - pub data: EventResult, // FIXME + pub data: MessageEventContent, } response { diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index e054c42e..21845d9c 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -114,7 +114,7 @@ mod filter_def_serde { } /// Updates to rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct Rooms { /// The rooms that the user has left or been banned from. pub leave: HashMap, @@ -125,7 +125,7 @@ pub struct Rooms { } /// Historical updates to left rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. @@ -135,7 +135,7 @@ pub struct LeftRoom { } /// Updates to joined rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct JoinedRoom { /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, @@ -164,7 +164,7 @@ pub struct UnreadNotificationsCount { } /// Events in the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. pub limited: bool, @@ -176,42 +176,42 @@ pub struct Timeline { } /// State events in the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct State { /// A list of state events. pub events: Vec>, } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct AccountData { /// A list of events. pub events: Vec>, } /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct Ephemeral { /// A list of events. pub events: Vec>, } /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct InvitedRoom { /// The state of a room that the user has been invited to. pub invite_state: InviteState, } /// The state of a room that the user has been invited to. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct InviteState { /// A list of state events. pub events: Vec>, } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] pub struct Presence { /// A list of events. pub events: Vec>, From b35e843fe22edfb4331fcfdeb3f60d0d0da3cfd5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Oct 2019 20:35:46 +0100 Subject: [PATCH 138/350] Update dependencies --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25c4f9e0..2c5e9224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = { git = "https://github.com/ruma/ruma-api", branch = "serverless" } -ruma-events = { git = "https://github.com/ruma/ruma-events", branch = "event-result-2" } +ruma-api = "0.11.0" +ruma-events = "0.15.1" ruma-identifiers = "0.14.0" -serde = { version = "1.0.101", features = ["derive"] } +serde = { version = "1.0.102", features = ["derive"] } serde_json = "1.0.41" url = { version = "2.1.0", features = ["serde"] } From 41387208ab751ab7c80b155e365a834d0a9e434f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Oct 2019 20:39:57 +0100 Subject: [PATCH 139/350] Test Rust 1.34.2 in CI (and beta, nightly) --- .travis.yml | 40 +++++++++++++++++++++++++++++++--------- README.md | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc6fbfec..612041c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,38 @@ language: "rust" cache: "cargo" +rust: + - 1.34.2 + - stable + - beta + - nightly +jobs: + allow_failures: + - rust: nightly + fast_finish: true + before_script: - - "rustup component add rustfmt" - - "rustup component add clippy" - - "cargo install --force cargo-audit" - - "cargo generate-lockfile" + - rustup component add rustfmt + - | + if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + rustup component add clippy + fi + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo install --force cargo-audit + fi + - cargo generate-lockfile script: - - "cargo audit" - - "cargo fmt --all -- --check" - - "cargo clippy --all-targets --all-features -- -D warnings" - - "cargo build --verbose" - - "cargo test --verbose" + - | + if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then + cargo audit + fi + - cargo fmt -- --check + - | + if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + cargo clippy --all-targets --all-features -- -D warnings + fi + - cargo build --verbose + - cargo test --verbose if: "type != push OR (tag IS blank AND branch = master)" notifications: email: false diff --git a/README.md b/README.md index 4e9e7774..90c31607 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ These types can be shared by client and server code. ## Minimum Rust version -ruma-client-api requires Rust 1.34 or later. +ruma-client-api requires Rust 1.34.2 or later. ## Status From ad582de058e24057597563f9822ecc25c2bbb9a5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Oct 2019 20:49:09 +0100 Subject: [PATCH 140/350] Allow clippy warning use_self --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4ca111ab..217e2ff6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,8 @@ clippy::wrong_pub_self_convention, clippy::wrong_self_convention )] +// Since we support Rust 1.34.2, we can't apply this suggestion yet +#![allow(clippy::use_self)] pub mod r0; pub mod unversioned; From e6fd6a34f3515ff8816b6c9e00972d1ae1387945 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Oct 2019 20:49:28 +0100 Subject: [PATCH 141/350] Bump version to 0.4.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2c5e9224..f2c458fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.3.0" +version = "0.4.0" edition = "2018" [dependencies] From 6ae72856d778abb0df355ca372dc99cd563c20dc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 31 Oct 2019 22:38:01 +0100 Subject: [PATCH 142/350] =?UTF-8?q?Remove=20#![deny(warnings)],=20#![warn(?= =?UTF-8?q?clippy::=E2=80=A6)]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 217e2ff6..fc875b94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,27 +5,7 @@ #![deny( missing_copy_implementations, missing_debug_implementations, - missing_docs, - warnings -)] -#![warn( - clippy::empty_line_after_outer_attr, - clippy::expl_impl_clone_on_copy, - clippy::if_not_else, - clippy::items_after_statements, - clippy::match_same_arms, - clippy::mem_forget, - clippy::missing_docs_in_private_items, - clippy::multiple_inherent_impl, - clippy::mut_mut, - clippy::needless_borrow, - clippy::needless_continue, - clippy::single_match_else, - clippy::unicode_not_nfc, - clippy::use_self, - clippy::used_underscore_binding, - clippy::wrong_pub_self_convention, - clippy::wrong_self_convention + missing_docs )] // Since we support Rust 1.34.2, we can't apply this suggestion yet #![allow(clippy::use_self)] From c56469eba57e3a67da7afb01ece60e6e946a9270 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 19:54:24 +0100 Subject: [PATCH 143/350] Update public room list endpoints to r0.6.0 --- CHANGELOG.md | 10 ++++ src/r0/directory.rs | 35 ++++++++++++ src/r0/directory/get_public_rooms.rs | 55 +++++++----------- src/r0/directory/get_public_rooms_filtered.rs | 57 +++++++++++++++++++ 4 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 src/r0/directory/get_public_rooms_filtered.rs diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..45d4b6d5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# [unreleased] + +Breaking changes: + +* Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` + +Improvements: + +* Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 +* Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 7108a7ca..bd5ebff9 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1,3 +1,38 @@ //! Endpoints for the public room directory. pub mod get_public_rooms; +pub mod get_public_rooms_filtered; + +use js_int::UInt; +use ruma_identifiers::{RoomAliasId, RoomId}; +use serde::{Deserialize, Serialize}; + +/// A chunk of a room list response, describing one room +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct PublicRoomsChunk { + /// Aliases of the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub aliases: Option>, + /// The canonical alias of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub canonical_alias: Option, + /// The name of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// The number of members joined to the room. + pub num_joined_members: UInt, + /// The ID of the room. + pub room_id: RoomId, + /// The topic of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// Whether the room may be viewed by guest users without joining. + pub world_readable: bool, + /// Whether guest users may join the room and participate in it. + /// + /// If they can, they will be subject to ordinary power level rules like any other user. + pub guest_can_join: bool, + /// The URL for the room's avatar, if one is set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, +} diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 301af00a..5586bf77 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,9 +1,9 @@ -//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) +//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-r0-publicrooms) use js_int::UInt; use ruma_api::ruma_api; -use ruma_identifiers::{RoomAliasId, RoomId}; -use serde::{Deserialize, Serialize}; + +use super::PublicRoomsChunk; ruma_api! { metadata { @@ -15,41 +15,28 @@ ruma_api! { requires_authentication: false, } - request {} + request { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + limit: Option, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + since: Option, + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + server: Option, + } response { - /// A pagination token for the response. - pub start: String, /// A paginated chunk of public rooms. pub chunk: Vec, /// A pagination token for the response. - pub end: String + pub next_batch: Option, + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, } } - -/// A chunk of the response, describing one room -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct PublicRoomsChunk { - /// Aliases of the room. - //#[serde(skip_serializing_if = "Option::is_none")] - pub aliases: Option>, - /// The URL for the room's avatar, if one is set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - /// Whether guest users may join the room and participate in it. - /// - /// If they can, they will be subject to ordinary power level rules like any other user. - pub guest_can_join: bool, - /// The name of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - /// The number of members joined to the room. - pub num_joined_members: UInt, - /// The ID of the room. - pub room_id: RoomId, - /// The topic of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - /// Whether the room may be viewed by guest users without joining. - pub world_readable: bool, -} diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs new file mode 100644 index 00000000..b8bf71de --- /dev/null +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -0,0 +1,57 @@ +//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-publicrooms) + +use js_int::UInt; +use ruma_api::ruma_api; +use serde::{Deserialize, Serialize}; + +use super::PublicRoomsChunk; + +ruma_api! { + metadata { + description: "Get the list of rooms in this homeserver's public directory.", + method: POST, + name: "get_public_rooms_filtered", + path: "/_matrix/client/r0/publicRooms", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + server: Option, + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + limit: Option, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + since: Option, + /// Filter to apply to the results. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + filter: Option, + } + + response { + /// A paginated chunk of public rooms. + pub chunk: Vec, + /// A pagination token for the response. + pub next_batch: Option, + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, + } +} + +/// A filter for public rooms lists +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Filter { + /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. + #[serde(skip_serializing_if = "Option::is_none")] + generic_search_term: Option, +} From 2748142f41933bff0d77016f16cbbca5546fd721 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 20:02:52 +0100 Subject: [PATCH 144/350] Update doc comment URLs * create_alias: No changes, bump to r0.6.0 * get_public_rooms_filtered: Use canonical URL --- src/r0/alias/create_alias.rs | 2 +- src/r0/directory/get_public_rooms_filtered.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index 9cf460cf..55a9e30c 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-directory-room-roomalias) +//! [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-directory-room-roomalias) use ruma_api::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index b8bf71de..e29e1f82 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-publicrooms) +//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-publicrooms) use js_int::UInt; use ruma_api::ruma_api; From 776ef792533c1ce77c3d7cdf11600d2ef30246fe Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 20:22:05 +0100 Subject: [PATCH 145/350] Rewrite r0.6.0 back to form without ending since the server redirects to that form, even though some links refer to the .html form --- src/r0/directory/get_public_rooms.rs | 2 +- src/r0/directory/get_public_rooms_filtered.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 5586bf77..97b834b6 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-r0-publicrooms) +//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-publicrooms) use js_int::UInt; use ruma_api::ruma_api; diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index e29e1f82..b8bf71de 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-publicrooms) +//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-publicrooms) use js_int::UInt; use ruma_api::ruma_api; From 71fc53189746f8578008c8da63328a35e302a8e4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 20:22:54 +0100 Subject: [PATCH 146/350] Compact serde attributes --- src/r0/room/create_room.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 3bdce4b5..09de202a 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -58,32 +58,28 @@ pub struct CreationContent { /// Whether users on other servers can join this room. /// /// Defaults to `true` if key does not exist. - #[serde(rename = "m.federate")] - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(rename = "m.federate", skip_serializing_if = "Option::is_none")] pub federate: Option, } /// A convenience parameter for setting a few default state events. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum RoomPreset { /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. - #[serde(rename = "private_chat")] PrivateChat, /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. - #[serde(rename = "public_chat")] PublicChat, /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. - #[serde(rename = "trusted_private_chat")] TrustedPrivateChat, } /// Whether or not a newly created room will be listed in the room directory. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum Visibility { /// Indicates that the room will be shown in the published room list. - #[serde(rename = "public")] Public, /// Indicates that the room from the published room list. - #[serde(rename = "private")] Private, } From 4e319ae27e0ee39804529798d43ed74996e47aeb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 20:30:25 +0100 Subject: [PATCH 147/350] Compact more serde attributes --- src/r0/account/register.rs | 3 +- src/r0/filter.rs | 42 +++++++------------ src/r0/media/get_content_thumbnail.rs | 3 +- .../presence/update_presence_subscriptions.rs | 6 +-- src/r0/room/create_room.rs | 3 +- src/r0/search/search_events.rs | 9 ++-- 6 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index a83da7cc..64c71d66 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -85,13 +85,12 @@ pub struct AuthenticationData { /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum RegistrationKind { /// A guest account /// /// These accounts may have limited permissions and may not be supported by all servers. - #[serde(rename = "guest")] Guest, /// A regular user account - #[serde(rename = "user")] User, } diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 952c7165..5dd3a579 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -9,12 +9,11 @@ use serde::{Deserialize, Serialize}; /// Format to use for returned events #[derive(Copy, Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum EventFormat { /// Client format, as described in the Client API. - #[serde(rename = "client")] Client, /// Raw events from federation. - #[serde(rename = "federation")] Federation, } @@ -26,15 +25,13 @@ pub struct RoomEventFilter { /// If this list is absent then no event types are excluded. A matching type will be excluded /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// sequence of characters. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_types: Vec, /// A list of room IDs to exclude. /// /// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// it is listed in the 'rooms' filter. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_rooms: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -42,28 +39,24 @@ pub struct RoomEventFilter { /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub rooms: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even /// if it is listed in the 'senders' filter. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_senders: Vec, /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub types: Option>, } @@ -93,15 +86,13 @@ pub struct RoomFilter { /// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// it is listed in the 'rooms' filter. This filter is applied before the filters in /// `ephemeral`, `state`, `timeline` or `account_data`. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_rooms: Vec, /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. This filter is applied before the /// filters in `ephemeral`, `state`, `timeline` or `account_data`. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub rooms: Option>, } @@ -113,8 +104,7 @@ pub struct Filter { /// If this list is absent then no event types are excluded. A matching type will be excluded /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// sequence of characters. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_types: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -122,22 +112,19 @@ pub struct Filter { /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub types: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even /// if it is listed in the 'senders' filter. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_senders: Vec, } @@ -150,8 +137,7 @@ pub struct FilterDefinition { /// to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' /// object. A literal '.' character in a field name may be escaped using a '\'. A server may /// include more fields than were requested. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub event_fields: Option>, /// The format to use for events. /// diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 82bea3d4..5090b419 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -6,12 +6,11 @@ use serde::{Deserialize, Serialize}; /// The desired resizing method. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum Method { /// Crop the original to produce the requested image dimensions. - #[serde(rename = "crop")] Crop, /// Maintain the original aspect ratio of the source image. - #[serde(rename = "scale")] Scale, } diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs index 7832967c..bf957425 100644 --- a/src/r0/presence/update_presence_subscriptions.rs +++ b/src/r0/presence/update_presence_subscriptions.rs @@ -15,12 +15,10 @@ ruma_api! { request { /// A list of user IDs to remove from the list. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub drop: Vec, /// A list of user IDs to add to the list. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub invite: Vec, /// The user whose presence state will be updated. #[ruma_api(path)] diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 09de202a..21b40d80 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -21,8 +21,7 @@ ruma_api! { /// A list of user IDs to invite to the room. /// /// This will tell the server to invite everyone in the list to the newly created room. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub invite: Vec, /// If this is included, an `m.room.name` event will be sent into the room to indicate /// the name of the room. diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index e9d67459..c235dee4 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -62,8 +62,7 @@ pub struct Criteria { #[serde(skip_serializing_if = "Option::is_none")] pub include_state: Option, /// The keys to search for. Defaults to all keys. - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub keys: Vec, /// The order in which to search for results. #[serde(skip_serializing_if = "Option::is_none")] @@ -112,12 +111,11 @@ pub struct Grouping { /// The key within events to use for this grouping. #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[serde(rename_all = "snake_case")] pub enum GroupingKey { /// `room_id` - #[serde(rename = "room_id")] RoomId, /// `sender` - #[serde(rename = "sender")] Sender, } @@ -144,13 +142,12 @@ pub enum SearchKeys { /// The order in which to search for results. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum OrderBy { /// Prioritize events by a numerical ranking of how closely they matched the search /// criteria. - #[serde(rename = "rank")] Rank, /// Prioritize recent events. - #[serde(rename = "recent")] Recent, } From 122aeccf961e982a85a843c6679532053949a96d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 21:09:30 +0100 Subject: [PATCH 148/350] Fix ruma_api attributes in r0::directory::* --- src/r0/directory/get_public_rooms.rs | 3 +++ src/r0/directory/get_public_rooms_filtered.rs | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 97b834b6..dcf0cf98 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -18,14 +18,17 @@ ruma_api! { request { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] limit: Option, /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] since: Option, /// The server to fetch the public room lists from. /// /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] server: Option, } diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index b8bf71de..f6b5ad6e 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -21,18 +21,16 @@ ruma_api! { /// /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] server: Option, /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(body)] limit: Option, /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(body)] since: Option, /// Filter to apply to the results. #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(body)] filter: Option, } From 6026d960ce7387dab7363e77f0980a02859e8fd9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 21:11:07 +0100 Subject: [PATCH 149/350] Update get_content_thumbnail to r0.6.0 --- src/r0/media/get_content_thumbnail.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 5090b419..532f153f 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) +//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-thumbnail-servername-mediaid) use js_int::UInt; use ruma_api::ruma_api; @@ -20,11 +20,16 @@ ruma_api! { method: GET, name: "get_content_thumbnail", path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", - rate_limited: false, + rate_limited: true, requires_authentication: false, } request { + /// Whether to fetch media deemed remote. + /// + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + pub allow_remote: Option, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] pub media_id: String, @@ -34,17 +39,20 @@ ruma_api! { /// The *desired* height of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] - pub height: Option, + pub height: UInt, /// The desired resizing method. #[ruma_api(query)] pub method: Option, /// The *desired* width of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] - pub width: Option, + pub width: UInt, } response { + /// The content type of the thumbnail. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, /// A thumbnail of the requested content. #[ruma_api(body)] pub file: Vec, From d140eff32452b10ba38793dcfa40cd74ed7a0d75 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Nov 2019 22:55:37 +0100 Subject: [PATCH 150/350] Fix wrong parameter type in get_message_events --- src/r0/sync/get_message_events.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 56c542c2..7944c6c3 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -25,6 +25,7 @@ ruma_api! { /// 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. + #[ruma_api(query)] pub from: String, /// The token to stop returning events at. /// @@ -32,13 +33,16 @@ ruma_api! { /// 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")] + #[ruma_api(query)] pub to: Option, /// The direction to return events from. + #[ruma_api(query)] pub dir: Direction, /// The maximum number of events to return. /// /// Default: 10. #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] pub limit: Option, } From 48dcfe93158088d089c226dcb905c0a20d9cb5b6 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 14 Nov 2019 13:42:22 +0100 Subject: [PATCH 151/350] 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, +} From c017c957d7fa5af5af367c860f909411ef299f87 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 21 Nov 2019 14:21:59 +0100 Subject: [PATCH 152/350] Update ruma-api to 0.11.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f2c458fc..5052e4a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.11.0" +ruma-api = "0.11.2" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.102", features = ["derive"] } From 5a84d9ba26907059b10ff3389bbc7de7cbc6fc7a Mon Sep 17 00:00:00 2001 From: Wim de With Date: Thu, 21 Nov 2019 14:26:41 +0100 Subject: [PATCH 153/350] Add third party network endpoints --- src/r0.rs | 1 + src/r0/thirdparty.rs | 74 +++++++++++++++++++ .../thirdparty/get_location_for_protocol.rs | 34 +++++++++ .../thirdparty/get_location_for_room_alias.rs | 29 ++++++++ src/r0/thirdparty/get_protocol.rs | 28 +++++++ src/r0/thirdparty/get_protocols.rs | 26 +++++++ src/r0/thirdparty/get_user_for_protocol.rs | 34 +++++++++ src/r0/thirdparty/get_user_for_user_id.rs | 29 ++++++++ 8 files changed, 255 insertions(+) create mode 100644 src/r0/thirdparty.rs create mode 100644 src/r0/thirdparty/get_location_for_protocol.rs create mode 100644 src/r0/thirdparty/get_location_for_room_alias.rs create mode 100644 src/r0/thirdparty/get_protocol.rs create mode 100644 src/r0/thirdparty/get_protocols.rs create mode 100644 src/r0/thirdparty/get_user_for_protocol.rs create mode 100644 src/r0/thirdparty/get_user_for_user_id.rs diff --git a/src/r0.rs b/src/r0.rs index 22171154..8bca9393 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -21,6 +21,7 @@ pub mod server; pub mod session; pub mod sync; pub mod tag; +pub mod thirdparty; pub mod typing; pub mod user_directory; pub mod voip; diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs new file mode 100644 index 00000000..185ad65e --- /dev/null +++ b/src/r0/thirdparty.rs @@ -0,0 +1,74 @@ +//! Endpoints for third party lookups + +pub mod get_location_for_protocol; +pub mod get_location_for_room_alias; +pub mod get_protocol; +pub mod get_protocols; +pub mod get_user_for_protocol; +pub mod get_user_for_user_id; + +use std::collections::HashMap; + +use ruma_identifiers::{RoomAliasId, UserId}; + +use serde::{Deserialize, Serialize}; + +/// Metadata about a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Protocol { + /// Fields which may be used to identify a third party user. + pub user_fields: Vec, + /// Fields which may be used to identify a third party location. + pub location_fields: Vec, + /// A content URI representing an icon for the third party protocol. + pub icon: String, + /// The type definitions for the fields defined in `user_fields` and `location_fields`. + pub field_types: HashMap, + /// A list of objects representing independent instances of configuration. + pub instances: Vec, +} + +/// Metadata about an instance of a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ProtocolInstance { + /// A human-readable description for the protocol, such as the name. + pub desc: String, + /// An optional content URI representing the protocol. + #[serde(skip_serializing_if = "Option::is_none")] + pub icon: Option, + /// Preset values for `fields` the client may use to search by. + pub fields: HashMap, + /// A unique identifier across all instances. + pub network_id: String, +} + +/// A type definition for a field used to identify third party users or locations. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct FieldType { + /// A regular expression for validation of a field's value. + pub regexp: String, + /// A placeholder serving as a valid example of the field value. + pub placeholder: String, +} + +/// A third party network location. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Location { + /// An alias for a matrix room. + pub alias: RoomAliasId, + /// The protocol ID that the third party location is a part of. + pub protocol: String, + /// Information used to identify this third party location. + pub fields: HashMap, +} + +/// A third party network user. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct User { + /// A matrix user ID representing a third party user. + pub userid: UserId, + /// The protocol ID that the third party user is a part of. + pub protocol: String, + /// Information used to identify this third party user. + pub fields: HashMap, +} diff --git a/src/r0/thirdparty/get_location_for_protocol.rs b/src/r0/thirdparty/get_location_for_protocol.rs new file mode 100644 index 00000000..4ae94589 --- /dev/null +++ b/src/r0/thirdparty/get_location_for_protocol.rs @@ -0,0 +1,34 @@ +//! [GET /_matrix/client/r0/thirdparty/location/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-location-protocol) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::Location; + +ruma_api! { + metadata { + description: "Fetches third party locations for a protocol.", + method: GET, + name: "get_location_for_protocol", + path: "/_matrix/client/r0/thirdparty/location/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: String, + /// One or more custom fields to help identify the third party location. + // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. + #[ruma_api(query_map)] + pub fields: HashMap, + } + + response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, + } +} diff --git a/src/r0/thirdparty/get_location_for_room_alias.rs b/src/r0/thirdparty/get_location_for_room_alias.rs new file mode 100644 index 00000000..a9c8a4e2 --- /dev/null +++ b/src/r0/thirdparty/get_location_for_room_alias.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/client/r0/thirdparty/location](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-location) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomAliasId; + +use super::Location; + +ruma_api! { + metadata { + description: "Retrieve an array of third party network locations from a Matrix room alias.", + method: GET, + name: "get_location_for_room_alias", + path: "/_matrix/client/r0/thirdparty/location", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The Matrix room alias to look up. + #[ruma_api(query)] + pub alias: RoomAliasId, + } + + response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, + } +} diff --git a/src/r0/thirdparty/get_protocol.rs b/src/r0/thirdparty/get_protocol.rs new file mode 100644 index 00000000..ea94b348 --- /dev/null +++ b/src/r0/thirdparty/get_protocol.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/client/r0/thirdparty/protocol/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-protocol-protocol) + +use ruma_api::ruma_api; + +use super::Protocol; + +ruma_api! { + metadata { + description: "Fetches the metadata from the homeserver about a particular third party protocol.", + method: GET, + name: "get_protocol", + path: "/_matrix/client/r0/thirdparty/protocol/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The name of the protocol. + #[ruma_api(path)] + pub protocol: String, + } + + response { + /// Metadata about the protocol. + #[ruma_api(body)] + pub protocol: Protocol, + } +} diff --git a/src/r0/thirdparty/get_protocols.rs b/src/r0/thirdparty/get_protocols.rs new file mode 100644 index 00000000..c17124e4 --- /dev/null +++ b/src/r0/thirdparty/get_protocols.rs @@ -0,0 +1,26 @@ +//! [GET /_matrix/client/r0/thirdparty/protocols](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-protocols) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::Protocol; + +ruma_api! { + metadata { + description: "Fetches the overall metadata about protocols supported by the homeserver.", + method: GET, + name: "get_protocols", + path: "/_matrix/client/r0/thirdparty/protocols", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// Metadata about protocols supported by the homeserver. + #[ruma_api(body)] + pub protocols: HashMap, + } +} diff --git a/src/r0/thirdparty/get_user_for_protocol.rs b/src/r0/thirdparty/get_user_for_protocol.rs new file mode 100644 index 00000000..4f34e7dc --- /dev/null +++ b/src/r0/thirdparty/get_user_for_protocol.rs @@ -0,0 +1,34 @@ +//! [GET /_matrix/client/r0/thirdparty/user/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-user-protocol) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::User; + +ruma_api! { + metadata { + description: "Fetches third party users for a protocol.", + method: GET, + name: "get_user_for_protocol", + path: "/_matrix/client/r0/thirdparty/user/:protocol", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: String, + /// One or more custom fields that are passed to the AS to help identify the user. + // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. + #[ruma_api(query_map)] + pub fields: HashMap, + } + + response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, + } +} diff --git a/src/r0/thirdparty/get_user_for_user_id.rs b/src/r0/thirdparty/get_user_for_user_id.rs new file mode 100644 index 00000000..10653609 --- /dev/null +++ b/src/r0/thirdparty/get_user_for_user_id.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/client/r0/thirdparty/user](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-user) + +use ruma_api::ruma_api; +use ruma_identifiers::UserId; + +use super::User; + +ruma_api! { + metadata { + description: "Retrieve an array of third party users from a Matrix User ID.", + method: GET, + name: "get_user_for_user_id", + path: "/_matrix/client/r0/thirdparty/user", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The Matrix User ID to look up. + #[ruma_api(query)] + pub userid: UserId, + } + + response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, + } +} From 44387425ba18fc194e3cac7a8461835b8ca91592 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 22 Nov 2019 11:05:37 +0100 Subject: [PATCH 154/350] Bump MSRV --- .travis.yml | 6 +++--- CHANGELOG.md | 1 + README.md | 2 +- src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 612041c2..8b188c77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: "rust" cache: "cargo" rust: - - 1.34.2 + - 1.36.0 - stable - beta - nightly @@ -13,7 +13,7 @@ jobs: before_script: - rustup component add rustfmt - | - if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then rustup component add clippy fi - | @@ -28,7 +28,7 @@ script: fi - cargo fmt -- --check - | - if [ "$TRAVIS_RUST_VERSION" != "1.34.2" ]; then + if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then cargo clippy --all-targets --all-features -- -D warnings fi - cargo build --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d4b6d5..ba1b9925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Breaking changes: * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` +* Our Minimum Supported Rust Version is now 1.36.0 Improvements: diff --git a/README.md b/README.md index 90c31607..7baea26c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ These types can be shared by client and server code. ## Minimum Rust version -ruma-client-api requires Rust 1.34.2 or later. +ruma-client-api requires Rust 1.36.0 or later. ## Status diff --git a/src/lib.rs b/src/lib.rs index fc875b94..2bf1f422 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ missing_debug_implementations, missing_docs )] -// Since we support Rust 1.34.2, we can't apply this suggestion yet +// Since we support Rust 1.36.0, we can't apply this suggestion yet #![allow(clippy::use_self)] pub mod r0; From 886715b8869130dd1f87189da23123c9f79dd59f Mon Sep 17 00:00:00 2001 From: Aaron DeVore Date: Sat, 23 Nov 2019 03:03:55 -0800 Subject: [PATCH 155/350] Add filter optional query param to /messages (r0.3.0 compatibility) --- CHANGELOG.md | 1 + src/r0/sync/get_message_events.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1b9925..f8fc55f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ Improvements: * Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 * Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) +* Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 7944c6c3..45f771bd 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -6,6 +6,8 @@ use ruma_events::{collections::only, EventResult}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; +use crate::r0::filter::RoomEventFilter; + ruma_api! { metadata { description: "Get message events for a room.", @@ -44,6 +46,10 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub limit: Option, + /// A RoomEventFilter to filter returned events with. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub filter: Option, } response { From 2ae14de8e56baa631f4feb93decb7c1634b2cca4 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Sun, 24 Nov 2019 16:41:41 +0100 Subject: [PATCH 156/350] Add application service extension The application service specification defines a single extension for the client-server API. This endpoint can only be used by application services. --- CHANGELOG.md | 2 ++ src/r0.rs | 1 + src/r0/appservice.rs | 3 +++ src/r0/appservice/set_room_visibility.rs | 30 ++++++++++++++++++++++++ src/r0/room.rs | 12 ++++++++++ src/r0/room/create_room.rs | 12 ++-------- 6 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 src/r0/appservice.rs create mode 100644 src/r0/appservice/set_room_visibility.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f8fc55f0..0e952a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Breaking changes: * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` +* Move `r0::room::create_room::Visibility` to `r0::room::Visibility` * Our Minimum Supported Rust Version is now 1.36.0 Improvements: @@ -10,3 +11,4 @@ Improvements: * Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 * Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) * Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) +* Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) diff --git a/src/r0.rs b/src/r0.rs index 8bca9393..2bd7ab9d 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -2,6 +2,7 @@ pub mod account; pub mod alias; +pub mod appservice; pub mod config; pub mod contact; pub mod context; diff --git a/src/r0/appservice.rs b/src/r0/appservice.rs new file mode 100644 index 00000000..50dd6665 --- /dev/null +++ b/src/r0/appservice.rs @@ -0,0 +1,3 @@ +//! Endpoints part of the application service extension of the client-server API + +pub mod set_room_visibility; diff --git a/src/r0/appservice/set_room_visibility.rs b/src/r0/appservice/set_room_visibility.rs new file mode 100644 index 00000000..ea188fca --- /dev/null +++ b/src/r0/appservice/set_room_visibility.rs @@ -0,0 +1,30 @@ +//! [PUT /_matrix/client/r0/directory/list/appservice/{networkId}/{roomId}](https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-client-r0-directory-list-appservice-networkid-roomid) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use crate::r0::room::Visibility; + +ruma_api! { + metadata { + description: "Updates the visibility of a given room on the application service's room directory.", + method: PUT, + name: "set_room_visibility", + path: "/_matrix/client/r0/directory/list/appservice/:network_id/:room_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The protocol (network) ID to update the room list for. + #[ruma_api(path)] + pub network_id: String, + /// The room ID to add to the directory. + #[ruma_api(path)] + pub room_id: RoomId, + /// Whether the room should be visible (public) in the directory or not (private). + pub visibility: Visibility, + } + + response {} +} diff --git a/src/r0/room.rs b/src/r0/room.rs index abee7187..329ec69e 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,3 +1,15 @@ //! Endpoints for room creation. pub mod create_room; + +use serde::{Deserialize, Serialize}; + +/// Whether or not a newly created room will be listed in the room directory. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum Visibility { + /// Indicates that the room will be shown in the published room list. + Public, + /// Indicates that the room will not be shown in the published room list. + Private, +} diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 21b40d80..fba3862c 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -4,6 +4,8 @@ use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; +use super::Visibility; + ruma_api! { metadata { description: "Create a new room.", @@ -72,13 +74,3 @@ pub enum RoomPreset { /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. TrustedPrivateChat, } - -/// Whether or not a newly created room will be listed in the room directory. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum Visibility { - /// Indicates that the room will be shown in the published room list. - Public, - /// Indicates that the room from the published room list. - Private, -} From 6e665efd1c263b2410c5ca6d41fcab8a72561fc7 Mon Sep 17 00:00:00 2001 From: Aaron DeVore Date: Sun, 24 Nov 2019 14:52:25 -0800 Subject: [PATCH 157/350] Add contains_url to RoomEventFilter (r0.3.0 compatibility) --- CHANGELOG.md | 1 + src/r0/filter.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e952a93..25140c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,4 @@ Improvements: * Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) * Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) +* Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 5dd3a579..50ffbae0 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -58,6 +58,12 @@ pub struct RoomEventFilter { /// match any sequence of characters. #[serde(default, skip_serializing_if = "Option::is_none")] pub types: Option>, + /// If `true` include only events with a URL key in their content. + /// If `false`, exclude such events. + /// + /// If this item is absent then all event types are included. + #[serde(skip_serializing_if = "Option::is_none")] + pub contains_url: Option, } /// Filters to be applied to room data From e30c82d248b62ebcd1a7ca4d5b24a8089efb949f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 17 Nov 2019 19:59:45 +0100 Subject: [PATCH 158/350] Update ruma-api, restore request receiving / response sending support --- Cargo.toml | 2 +- src/r0/context/get_context.rs | 12 +++-- src/r0/presence/get_subscribed_presences.rs | 3 +- src/r0/search/search_events.rs | 23 +++++---- src/r0/send/send_message_event.rs | 3 +- src/r0/sync/get_member_events.rs | 3 +- src/r0/sync/get_message_events.rs | 3 +- src/r0/sync/get_state_events.rs | 3 +- src/r0/sync/sync_events.rs | 53 ++++++++++++++------- src/r0/tag/get_tags.rs | 3 +- 10 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5052e4a0..92561c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.11.2" +ruma-api = "0.12.0-alpha.1" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.102", features = ["derive"] } diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index e518dfd6..566ac742 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -32,16 +32,20 @@ ruma_api! { /// A token that can be used to paginate forwards with. pub end: String, /// Details of the requested event. - pub event: EventResult, + #[wrap_incoming(with EventResult)] + pub event: only::RoomEvent, /// A list of room events that happened just after the requested event, in chronological /// order. - pub events_after: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub events_after: Vec, /// A list of room events that happened just before the requested event, in /// reverse-chronological order. - pub events_before: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub events_before: Vec, /// A token that can be used to paginate backwards with. pub start: String, /// The state of the room at the last event returned. - pub state: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub state: Vec, } } diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index 656b1c8a..fc581989 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -23,6 +23,7 @@ ruma_api! { response { /// A list of presence events for every user on this list. #[ruma_api(body)] - pub presence_events: Vec>, + #[wrap_incoming(PresenceEvent with EventResult)] + pub presence_events: Vec, } } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index c235dee4..e9b74a9f 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api::ruma_api; +use ruma_api::{ruma_api, Outgoing}; use ruma_events::{collections::all::Event, EventResult}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -32,6 +32,7 @@ ruma_api! { response { /// A grouping of search results by category. + #[wrap_incoming] pub search_categories: ResultCategories, } } @@ -84,16 +85,18 @@ pub struct EventContext { } /// Context for search results, if requested. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct EventContextResult { /// Pagination token for the end of the chunk. pub end: String, /// Events just after the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>>, + #[wrap_incoming(Event with EventResult)] + pub events_after: Option>, /// Events just before the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>>, + #[wrap_incoming(Event with EventResult)] + pub events_before: Option>, /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] @@ -152,15 +155,16 @@ pub enum OrderBy { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct ResultCategories { /// Room event results. #[serde(skip_serializing_if = "Option::is_none")] + #[wrap_incoming(RoomEventResults)] pub room_events: Option, } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct RoomEventResults { /// An approximate count of the total number of results found. pub count: UInt, @@ -172,6 +176,7 @@ pub struct RoomEventResults { #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, /// List of results in the requested order. + #[wrap_incoming(SearchResult)] pub results: Vec, /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. @@ -195,15 +200,17 @@ pub struct ResultGroup { } /// A search result. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct SearchResult { /// Context for result, if requested. #[serde(skip_serializing_if = "Option::is_none")] + #[wrap_incoming(EventContextResult)] pub context: Option, /// A number that describes how closely this result matches the search. Higher is closer. pub rank: f64, /// The event that matched. - pub result: EventResult, + #[wrap_incoming(with EventResult)] + pub result: Event, } /// A user profile. diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index c97fd0a1..81d5f7ba 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,7 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventType}; +use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,6 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] + #[wrap_incoming(with EventResult)] pub data: MessageEventContent, } diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index aa5c9fcd..c4b589d2 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -22,6 +22,7 @@ ruma_api! { response { /// A list of member events. - pub chunk: Vec> + #[wrap_incoming(MemberEvent with EventResult)] + pub chunk: Vec } } diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 45f771bd..385478ce 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -56,7 +56,8 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - pub chunk: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub chunk: Vec, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index dd122f65..8e3d8a73 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -25,6 +25,7 @@ ruma_api! { /// list of events. If the user has left the room then this will be the state of the /// room when they left as a list of events. #[ruma_api(body)] - pub room_state: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub room_state: Vec, } } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 21845d9c..b9ccf1ca 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api::ruma_api; +use ruma_api::{ruma_api, Outgoing}; use ruma_events::{ collections::{all, only}, stripped, EventResult, @@ -50,11 +50,12 @@ ruma_api! { /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, /// Updates to rooms. + #[wrap_incoming] pub rooms: Rooms, /// Updates to the presence status of other users. + #[wrap_incoming] pub presence: Presence, } - } /// Whether to set presence or not during sync. @@ -114,41 +115,50 @@ mod filter_def_serde { } /// Updates to rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Rooms { /// The rooms that the user has left or been banned from. + #[wrap_incoming(LeftRoom)] pub leave: HashMap, /// The rooms that the user has joined. + #[wrap_incoming(JoinedRoom)] pub join: HashMap, /// The rooms that the user has been invited to. + #[wrap_incoming(InvitedRoom)] pub invite: HashMap, } /// Historical updates to left rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. + #[wrap_incoming] pub timeline: Timeline, /// The state updates for the room up to the start of the timeline. + #[wrap_incoming] pub state: State, } /// Updates to joined rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct JoinedRoom { /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, /// The timeline of messages and state changes in the room. + #[wrap_incoming] pub timeline: Timeline, /// Updates to the state, between the time indicated by the `since` parameter, and the start /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not /// given, or `full_state` is true). + #[wrap_incoming] pub state: State, /// The private data that this user has attached to this room. + #[wrap_incoming] pub account_data: AccountData, /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// room. e.g. typing. + #[wrap_incoming] pub ephemeral: Ephemeral, } @@ -164,7 +174,7 @@ pub struct UnreadNotificationsCount { } /// Events in the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. pub limited: bool, @@ -172,47 +182,54 @@ pub struct Timeline { /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, /// A list of events. - pub events: Vec>, + #[wrap_incoming(all::RoomEvent with EventResult)] + pub events: Vec, } /// State events in the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct State { /// A list of state events. - pub events: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub events: Vec, } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct AccountData { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Ephemeral { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct InvitedRoom { /// The state of a room that the user has been invited to. + #[wrap_incoming] pub invite_state: InviteState, } /// The state of a room that the user has been invited to. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct InviteState { /// A list of state events. - pub events: Vec>, + #[wrap_incoming(stripped::StrippedState with EventResult)] + pub events: Vec, } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Presence { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 4f0abea0..a9448802 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -25,6 +25,7 @@ ruma_api! { response { /// The user's tags for the room. - pub tags: EventResult, + #[wrap_incoming(with EventResult)] + pub tags: TagEventContent, } } From e7db5307820aad89aa81f7eed7cbc2f2783ee0e8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 4 Aug 2019 17:22:59 +0200 Subject: [PATCH 159/350] Add Default impls, ignore_all ctors to filter types --- src/r0/filter.rs | 52 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 50ffbae0..2de9de95 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -18,7 +18,7 @@ pub enum EventFormat { } /// Filters to be applied to room events -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct RoomEventFilter { /// A list of event types to exclude. /// @@ -66,8 +66,18 @@ pub struct RoomEventFilter { pub contains_url: Option, } +impl RoomEventFilter { + /// A filter that can be used to ignore all room events + pub fn ignore_all() -> Self { + Self { + types: Some(vec![]), + ..Default::default() + } + } +} + /// Filters to be applied to room data -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct RoomFilter { /// Include rooms that the user has left in the sync. /// @@ -102,8 +112,18 @@ pub struct RoomFilter { pub rooms: Option>, } +impl RoomFilter { + /// A filter that can be used to ignore all room events (of any type) + pub fn ignore_all() -> Self { + Self { + rooms: Some(vec![]), + ..Default::default() + } + } +} + /// Filter for not-room data -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Filter { /// A list of event types to exclude. /// @@ -134,8 +154,18 @@ pub struct Filter { pub not_senders: Vec, } +impl Filter { + /// A filter that can be used to ignore all events + pub fn ignore_all() -> Self { + Self { + types: Some(vec![]), + ..Default::default() + } + } +} + /// A filter definition -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct FilterDefinition { /// List of event fields to include. /// @@ -148,7 +178,7 @@ pub struct FilterDefinition { /// The format to use for events. /// /// 'client' will return the events in a format suitable for clients. 'federation' will return - /// the raw event as receieved over federation. The default is 'client'. + /// the raw event as received over federation. The default is 'client'. #[serde(skip_serializing_if = "Option::is_none")] pub event_format: Option, /// The user account data that isn't associated with rooms to include. @@ -161,3 +191,15 @@ pub struct FilterDefinition { #[serde(skip_serializing_if = "Option::is_none")] pub presence: Option, } + +impl FilterDefinition { + /// A filter that can be used to ignore all events + pub fn ignore_all() -> Self { + Self { + account_data: Some(Filter::ignore_all()), + room: Some(RoomFilter::ignore_all()), + presence: Some(Filter::ignore_all()), + ..Default::default() + } + } +} From c4550208021f6c1cd445d399926514f90b251724 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Nov 2019 00:27:25 +0100 Subject: [PATCH 160/350] Update r0::account::change_password to r0.6.0 --- CHANGELOG.md | 3 +++ src/r0/account.rs | 12 ++++++++++++ src/r0/account/change_password.rs | 7 +++++-- src/r0/account/register.rs | 12 ++---------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25140c88..0553d0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Breaking changes: * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` * Move `r0::room::create_room::Visibility` to `r0::room::Visibility` * Our Minimum Supported Rust Version is now 1.36.0 +* Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` Improvements: @@ -13,3 +14,5 @@ Improvements: * Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) +* Update `r0::account::change_password` from r0.3.0 to r0.6.0 + * Add optional `auth` field diff --git a/src/r0/account.rs b/src/r0/account.rs index d33db981..c1507fa9 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -6,3 +6,15 @@ pub mod register; pub mod request_password_change_token; pub mod request_register_token; pub mod whoami; + +use serde::{Deserialize, Serialize}; + +/// Additional authentication information for the user-interactive authentication API. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct AuthenticationData { + /// The login type that the client is attempting to complete. + #[serde(rename = "type")] + kind: String, + /// The value of the session key given by the homeserver. + session: Option, +} diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index eb8a074d..96989561 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -1,7 +1,9 @@ -//! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password) +//! [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password) use ruma_api::ruma_api; +use super::AuthenticationData; + ruma_api! { metadata { description: "Change the password of the current user's account.", @@ -15,7 +17,8 @@ ruma_api! { request { /// The new password for the account. pub new_password: String, - // TODO: missing `auth` field + /// Additional authentication information for the user-interactive authentication API. + pub auth: Option, } response {} diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 64c71d66..7c06297b 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -4,6 +4,8 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; +use super::AuthenticationData; + ruma_api! { metadata { description: "Register an account on this homeserver.", @@ -73,16 +75,6 @@ ruma_api! { } } -/// Additional authentication information for the user-interactive authentication API. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct AuthenticationData { - /// The login type that the client is attempting to complete. - #[serde(rename = "type")] - kind: String, - /// The value of the session key given by the homeserver. - session: Option, -} - /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] From e2e0f8ad2b47a5a1b3bc5d4242fa6cc2e0f3a558 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 3 Dec 2019 12:06:31 +0100 Subject: [PATCH 161/350] Update deps, release 0.5.0-alpha.1 --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 92561c73..da5f143a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.4.0" +version = "0.5.0-alpha.1" edition = "2018" [dependencies] @@ -17,6 +17,6 @@ js_int = { version = "0.1.2", features = ["serde"] } ruma-api = "0.12.0-alpha.1" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" -serde = { version = "1.0.102", features = ["derive"] } -serde_json = "1.0.41" +serde = { version = "1.0.103", features = ["derive"] } +serde_json = "1.0.42" url = { version = "2.1.0", features = ["serde"] } From 83493de30c71f04103923619b714eec1fe269cf3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 12 Dec 2019 21:17:12 +0100 Subject: [PATCH 162/350] Update ruma-api to 0.12.0, release 0.5.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da5f143a..47b7cb11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,12 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.5.0-alpha.1" +version = "0.5.0" edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.12.0-alpha.1" +ruma-api = "0.12.0" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.103", features = ["derive"] } From ec74c2d7986eedd2a0fd249f935a1a3d63d4a7ea Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 12 Dec 2019 22:25:35 +0100 Subject: [PATCH 163/350] Fix MSRV, update CHANGELOG.md --- .travis.yml | 9 +++------ CHANGELOG.md | 4 ++-- README.md | 2 +- src/lib.rs | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b188c77..03e1dca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: "rust" cache: "cargo" rust: - - 1.36.0 + - 1.39.0 - stable - beta - nightly @@ -12,10 +12,7 @@ jobs: before_script: - rustup component add rustfmt - - | - if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then - rustup component add clippy - fi + - rustup component add clippy - | if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then cargo install --force cargo-audit @@ -28,7 +25,7 @@ script: fi - cargo fmt -- --check - | - if [ "$TRAVIS_RUST_VERSION" != "1.36.0" ]; then + if [ "$TRAVIS_RUST_VERSION" != "1.39.0" ]; then cargo clippy --all-targets --all-features -- -D warnings fi - cargo build --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md index 0553d0e4..cf0ccc57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ -# [unreleased] +# r0.5.0 Breaking changes: * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` * Move `r0::room::create_room::Visibility` to `r0::room::Visibility` -* Our Minimum Supported Rust Version is now 1.36.0 +* Our Minimum Supported Rust Version is now 1.39.0 * Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` Improvements: diff --git a/README.md b/README.md index 7baea26c..18757086 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ These types can be shared by client and server code. ## Minimum Rust version -ruma-client-api requires Rust 1.36.0 or later. +ruma-client-api requires Rust 1.39.0 or later. ## Status diff --git a/src/lib.rs b/src/lib.rs index 2bf1f422..eb2423c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,6 @@ missing_debug_implementations, missing_docs )] -// Since we support Rust 1.36.0, we can't apply this suggestion yet -#![allow(clippy::use_self)] pub mod r0; pub mod unversioned; From 69a8f35dbe60fb0e7da4b51d21050dcdef3ff913 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 13 Dec 2019 12:13:12 +0100 Subject: [PATCH 164/350] Update change log --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf0ccc57..4748c444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ +# [unreleased] + # r0.5.0 Breaking changes: +* Our Minimum Supported Rust Version is now 1.39.0 +* Update ruma-api from 0.11.0 to 0.12.0 * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` * Move `r0::room::create_room::Visibility` to `r0::room::Visibility` -* Our Minimum Supported Rust Version is now 1.39.0 * Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` Improvements: From f964dd3ede38911e20feb8b1a3fac5c91b059ba4 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Sat, 21 Dec 2019 16:09:18 -0500 Subject: [PATCH 165/350] Remove presence lists. Presence lists were removed in 0.5.0. --- src/r0/presence.rs | 2 -- src/r0/presence/get_subscribed_presences.rs | 29 ------------------- .../presence/update_presence_subscriptions.rs | 29 ------------------- 3 files changed, 60 deletions(-) delete mode 100644 src/r0/presence/get_subscribed_presences.rs delete mode 100644 src/r0/presence/update_presence_subscriptions.rs diff --git a/src/r0/presence.rs b/src/r0/presence.rs index 47bb1eb6..38049dda 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -1,6 +1,4 @@ //! Endpoints for user presence. pub mod get_presence; -pub mod get_subscribed_presences; pub mod set_presence; -pub mod update_presence_subscriptions; diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs deleted file mode 100644 index fc581989..00000000 --- a/src/r0/presence/get_subscribed_presences.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-list-userid) - -use ruma_api::ruma_api; -use ruma_events::{presence::PresenceEvent, EventResult}; -use ruma_identifiers::UserId; - -ruma_api! { - metadata { - description: "Get the precence status from the user's subscriptions.", - method: GET, - name: "get_subscribed_presences", - path: "/_matrix/client/r0/presence/list/:user_id", - rate_limited: false, - requires_authentication: true, - } - - request { - /// The user whose presence state will be retrieved. - #[ruma_api(path)] - pub user_id: UserId, - } - - response { - /// A list of presence events for every user on this list. - #[ruma_api(body)] - #[wrap_incoming(PresenceEvent with EventResult)] - pub presence_events: Vec, - } -} diff --git a/src/r0/presence/update_presence_subscriptions.rs b/src/r0/presence/update_presence_subscriptions.rs deleted file mode 100644 index bf957425..00000000 --- a/src/r0/presence/update_presence_subscriptions.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-presence-list-userid) - -use ruma_api::ruma_api; -use ruma_identifiers::UserId; - -ruma_api! { - metadata { - description: "Update the presence subscriptions of the user.", - method: POST, - name: "update_presence_subscriptions", - path: "/_matrix/client/r0/presence/list/:user_id", - rate_limited: true, - requires_authentication: true, - } - - request { - /// A list of user IDs to remove from the list. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub drop: Vec, - /// A list of user IDs to add to the list. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub invite: Vec, - /// The user whose presence state will be updated. - #[ruma_api(path)] - pub user_id: UserId, - } - - response {} -} From d749f7ebc118d68abc5a6a30813a420a1d9e0294 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 23 Dec 2019 22:46:42 -0500 Subject: [PATCH 166/350] Add delete_devices endpoint. --- CHANGELOG.md | 1 + src/r0.rs | 1 + src/r0/device.rs | 3 +++ src/r0/device/delete_devices.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 src/r0/device.rs create mode 100644 src/r0/device/delete_devices.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4748c444..67b38a61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,3 +19,4 @@ Improvements: * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field +* Add `r0::device::delete_devices` (introduced upstream in r0.4.0) diff --git a/src/r0.rs b/src/r0.rs index 2bd7ab9d..1a57c5f9 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -6,6 +6,7 @@ pub mod appservice; pub mod config; pub mod contact; pub mod context; +pub mod device; pub mod directory; pub mod filter; pub mod media; diff --git a/src/r0/device.rs b/src/r0/device.rs new file mode 100644 index 00000000..e15727b9 --- /dev/null +++ b/src/r0/device.rs @@ -0,0 +1,3 @@ +//! Endpoints for managing devices. + +pub mod delete_devices; diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/delete_devices.rs new file mode 100644 index 00000000..6f8795e9 --- /dev/null +++ b/src/r0/device/delete_devices.rs @@ -0,0 +1,26 @@ +//! [POST /_matrix/client/r0/delete_devices](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-delete-devices) + +use crate::r0::account::AuthenticationData; +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Delete specified devices", + method: POST, + path: "/_matrix/client/r0/delete_devices", + name: "delete_devices", + rate_limited: false, + requires_authentication: true, + } + + request { + /// List of devices to delete. + devices: Vec, + + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + } + + response { } +} From 523e58a8015d3af5846e6d539706684112e574a0 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 24 Dec 2019 00:03:47 -0500 Subject: [PATCH 167/350] Add device endpoints. --- CHANGELOG.md | 2 +- src/r0/device.rs | 23 ++++++++++++++++- ...lete_devices.rs => bulk_delete_devices.rs} | 4 +-- src/r0/device/delete_device.rs | 25 +++++++++++++++++++ src/r0/device/get_device.rs | 25 +++++++++++++++++++ src/r0/device/get_devices.rs | 21 ++++++++++++++++ src/r0/device/set_device.rs | 24 ++++++++++++++++++ 7 files changed, 120 insertions(+), 4 deletions(-) rename src/r0/device/{delete_devices.rs => bulk_delete_devices.rs} (88%) create mode 100644 src/r0/device/delete_device.rs create mode 100644 src/r0/device/get_device.rs create mode 100644 src/r0/device/get_devices.rs create mode 100644 src/r0/device/set_device.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b38a61..aa76aac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,4 +19,4 @@ Improvements: * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field -* Add `r0::device::delete_devices` (introduced upstream in r0.4.0) +* Add `r0::device` endpoint diff --git a/src/r0/device.rs b/src/r0/device.rs index e15727b9..a2eae059 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -1,3 +1,24 @@ //! Endpoints for managing devices. -pub mod delete_devices; +use ruma_identifiers::DeviceId; +use js_int::UInt; +use serde::{Deserialize, Serialize}; + +pub mod bulk_delete_devices; +pub mod get_device; +pub mod get_devices; +pub mod set_device; +pub mod delete_device; + +/// Information about a registered device. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)] +pub struct Device { + /// Device ID + pub device_id: DeviceId, + /// Public display name of the device. + pub display_name: Option, + /// Most recently seen IP address of the session. + pub ip: Option, + /// Unix timestamp that the session was last active. + pub last_seen: Option, +} diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/bulk_delete_devices.rs similarity index 88% rename from src/r0/device/delete_devices.rs rename to src/r0/device/bulk_delete_devices.rs index 6f8795e9..d4e76962 100644 --- a/src/r0/device/delete_devices.rs +++ b/src/r0/device/bulk_delete_devices.rs @@ -5,10 +5,10 @@ use ruma_api::ruma_api; ruma_api! { metadata { - description: "Delete specified devices", + description: "Delete specified devices.", method: POST, path: "/_matrix/client/r0/delete_devices", - name: "delete_devices", + name: "bulk_delete_devices", rate_limited: false, requires_authentication: true, } diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs new file mode 100644 index 00000000..cefb61c9 --- /dev/null +++ b/src/r0/device/delete_device.rs @@ -0,0 +1,25 @@ +//! [DELETE /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; +use crate::r0::account::AuthenticationData; + +ruma_api! { + metadata { + description: "Delete a device for authenticated user.", + method: DELETE, + name: "delete_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + } + + response {} +} \ No newline at end of file diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs new file mode 100644 index 00000000..43f6dc55 --- /dev/null +++ b/src/r0/device/get_device.rs @@ -0,0 +1,25 @@ +//! [GET /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; +use super::Device; + +ruma_api! { + metadata { + description: "Get a device for authenticated user.", + method: GET, + name: "get_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + } + + response { + device: Device, + } +} diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs new file mode 100644 index 00000000..20746c85 --- /dev/null +++ b/src/r0/device/get_devices.rs @@ -0,0 +1,21 @@ +//! [GET /_matrix/client/r0/devices](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices) + +use ruma_api::ruma_api; +use super::Device; + +ruma_api! { + metadata { + description: "Get registered devices for authenticated user.", + method: GET, + name: "get_devices", + path: "/_matrix/client/r0/devices", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + devices: Vec + } +} diff --git a/src/r0/device/set_device.rs b/src/r0/device/set_device.rs new file mode 100644 index 00000000..0d653e16 --- /dev/null +++ b/src/r0/device/set_device.rs @@ -0,0 +1,24 @@ +//! [PUT /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Update metadata for a device.", + method: PUT, + name: "set_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + display_name: Option, + } + + response {} +} \ No newline at end of file From f6bc55bd39f7f6a3c63fe198b0f3031c8a6c9bf9 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 24 Dec 2019 00:09:03 -0500 Subject: [PATCH 168/350] Use DeviceId instead of String. --- src/r0/device/bulk_delete_devices.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r0/device/bulk_delete_devices.rs b/src/r0/device/bulk_delete_devices.rs index d4e76962..1d849142 100644 --- a/src/r0/device/bulk_delete_devices.rs +++ b/src/r0/device/bulk_delete_devices.rs @@ -2,6 +2,7 @@ use crate::r0::account::AuthenticationData; use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; ruma_api! { metadata { @@ -15,7 +16,7 @@ ruma_api! { request { /// List of devices to delete. - devices: Vec, + devices: Vec, /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] From f58f4c073b85a2bd78283ed1d882eb3dd0694fa4 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 24 Dec 2019 00:10:58 -0500 Subject: [PATCH 169/350] Formatting fixes. --- src/r0/device.rs | 4 ++-- src/r0/device/delete_device.rs | 4 ++-- src/r0/device/get_device.rs | 2 +- src/r0/device/get_devices.rs | 2 +- src/r0/device/set_device.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/r0/device.rs b/src/r0/device.rs index a2eae059..09164d45 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -1,14 +1,14 @@ //! Endpoints for managing devices. -use ruma_identifiers::DeviceId; use js_int::UInt; +use ruma_identifiers::DeviceId; use serde::{Deserialize, Serialize}; pub mod bulk_delete_devices; +pub mod delete_device; pub mod get_device; pub mod get_devices; pub mod set_device; -pub mod delete_device; /// Information about a registered device. #[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)] diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs index cefb61c9..bea045e4 100644 --- a/src/r0/device/delete_device.rs +++ b/src/r0/device/delete_device.rs @@ -1,8 +1,8 @@ //! [DELETE /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-devices-deviceid) +use crate::r0::account::AuthenticationData; use ruma_api::ruma_api; use ruma_identifiers::DeviceId; -use crate::r0::account::AuthenticationData; ruma_api! { metadata { @@ -22,4 +22,4 @@ ruma_api! { } response {} -} \ No newline at end of file +} diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs index 43f6dc55..8f064083 100644 --- a/src/r0/device/get_device.rs +++ b/src/r0/device/get_device.rs @@ -1,8 +1,8 @@ //! [GET /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices-deviceid) +use super::Device; use ruma_api::ruma_api; use ruma_identifiers::DeviceId; -use super::Device; ruma_api! { metadata { diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs index 20746c85..57bb9510 100644 --- a/src/r0/device/get_devices.rs +++ b/src/r0/device/get_devices.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/devices](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices) -use ruma_api::ruma_api; use super::Device; +use ruma_api::ruma_api; ruma_api! { metadata { diff --git a/src/r0/device/set_device.rs b/src/r0/device/set_device.rs index 0d653e16..e6a304c3 100644 --- a/src/r0/device/set_device.rs +++ b/src/r0/device/set_device.rs @@ -21,4 +21,4 @@ ruma_api! { } response {} -} \ No newline at end of file +} From d025c3e26e14bd0d67a1661285d467cdb9477774 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 24 Dec 2019 10:12:45 -0500 Subject: [PATCH 170/350] Make style and naming convention for devices endpoint consistent. --- CHANGELOG.md | 2 +- src/r0/device.rs | 4 ++-- src/r0/device/{bulk_delete_devices.rs => delete_devices.rs} | 4 ++-- src/r0/device/get_devices.rs | 2 +- src/r0/device/{set_device.rs => update_device.rs} | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename src/r0/device/{bulk_delete_devices.rs => delete_devices.rs} (93%) rename src/r0/device/{set_device.rs => update_device.rs} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa76aac7..190392f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,4 +19,4 @@ Improvements: * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field -* Add `r0::device` endpoint +* Add `r0::device` endpoints diff --git a/src/r0/device.rs b/src/r0/device.rs index 09164d45..11c27344 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -4,11 +4,11 @@ use js_int::UInt; use ruma_identifiers::DeviceId; use serde::{Deserialize, Serialize}; -pub mod bulk_delete_devices; pub mod delete_device; +pub mod delete_devices; pub mod get_device; pub mod get_devices; -pub mod set_device; +pub mod update_device; /// Information about a registered device. #[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)] diff --git a/src/r0/device/bulk_delete_devices.rs b/src/r0/device/delete_devices.rs similarity index 93% rename from src/r0/device/bulk_delete_devices.rs rename to src/r0/device/delete_devices.rs index 1d849142..2adf8ea5 100644 --- a/src/r0/device/bulk_delete_devices.rs +++ b/src/r0/device/delete_devices.rs @@ -9,7 +9,7 @@ ruma_api! { description: "Delete specified devices.", method: POST, path: "/_matrix/client/r0/delete_devices", - name: "bulk_delete_devices", + name: "delete_devices", rate_limited: false, requires_authentication: true, } @@ -23,5 +23,5 @@ ruma_api! { auth: Option, } - response { } + response {} } diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs index 57bb9510..4419d369 100644 --- a/src/r0/device/get_devices.rs +++ b/src/r0/device/get_devices.rs @@ -16,6 +16,6 @@ ruma_api! { request {} response { - devices: Vec + devices: Vec, } } diff --git a/src/r0/device/set_device.rs b/src/r0/device/update_device.rs similarity index 95% rename from src/r0/device/set_device.rs rename to src/r0/device/update_device.rs index e6a304c3..2d3db701 100644 --- a/src/r0/device/set_device.rs +++ b/src/r0/device/update_device.rs @@ -7,7 +7,7 @@ ruma_api! { metadata { description: "Update metadata for a device.", method: PUT, - name: "set_device", + name: "update_device", path: "/_matrix/client/r0/devices/:device_id", rate_limited: false, requires_authentication: true, From 16a8aa70d67f5c9856765e0452e5056e99969e97 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 24 Dec 2019 10:15:56 -0500 Subject: [PATCH 171/350] Use DeviceId identifier consistently. --- src/r0/account/register.rs | 6 +++--- src/r0/session/login.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 7c06297b..3ab0a9c5 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register) use ruma_api::ruma_api; -use ruma_identifiers::UserId; +use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; use super::AuthenticationData; @@ -37,7 +37,7 @@ ruma_api! { /// If this does not correspond to a known client device, a new device will be created. /// The server will auto-generate a device_id if this is not specified. #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, + pub device_id: Option, /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. @@ -71,7 +71,7 @@ ruma_api! { /// ID of the registered device. /// /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: String, + pub device_id: DeviceId, } } diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 720ad1a5..01dea6ed 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) use ruma_api::ruma_api; -use ruma_identifiers::UserId; +use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; ruma_api! { @@ -30,7 +30,7 @@ ruma_api! { pub address: Option, /// ID of the client device #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, + pub device_id: Option, } response { From 0a31182e592e643ed69ebbe9430a08c2dec7730a Mon Sep 17 00:00:00 2001 From: iinuwa Date: Tue, 24 Dec 2019 13:45:16 -0800 Subject: [PATCH 172/350] Add room event endpoint --- CHANGELOG.md | 1 + src/r0/room.rs | 1 + src/r0/room/get_room_event.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/r0/room/get_room_event.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 190392f5..09ef111b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,3 +20,4 @@ Improvements: * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field * Add `r0::device` endpoints +* Add `r0::room::get_room_event` (introduced in r0.4.0) diff --git a/src/r0/room.rs b/src/r0/room.rs index 329ec69e..890064da 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,6 +1,7 @@ //! Endpoints for room creation. pub mod create_room; +pub mod get_room_event; use serde::{Deserialize, Serialize}; diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs new file mode 100644 index 00000000..8fadde7b --- /dev/null +++ b/src/r0/room/get_room_event.rs @@ -0,0 +1,32 @@ +//! [GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-event-eventid) + +use ruma_api::ruma_api; +use ruma_events::{collections::all, EventResult}; +use ruma_identifiers::{EventId, RoomId}; +use serde::Deserialize; + +ruma_api! { + metadata { + description: "Get a single event based on roomId/eventId", + method: GET, + name: "get_room_event", + path: "/_matrix/client/r0/rooms/:room_id/event/:event_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The ID of the room the event is in. + #[ruma_api(path)] + pub room_id: RoomId, + /// The ID of the event. + #[ruma_api(path)] + pub event_id: EventId, + } + + response { + /// Arbitrary JSON of the event body. Returns both room and state events. + #[wrap_incoming(with EventResult)] + pub event: all::RoomEvent, + } +} From 23611df0c2973c48a93fcfd987188aeb138709e9 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 25 Dec 2019 09:47:19 -0500 Subject: [PATCH 173/350] Document removal of presence list endpoints. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09ef111b..c62c4cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking changes: * Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` * Move `r0::room::create_room::Visibility` to `r0::room::Visibility` * Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` +* Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in 0.5.0) Improvements: From f434c70e876006c0856cab6619d21041d939221f Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 25 Dec 2019 09:47:47 -0500 Subject: [PATCH 174/350] Update summary of room module. Now that the `r0::room` module includes more endpoints than just `create_room`, the doc string should reflect that. --- src/r0/room.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/room.rs b/src/r0/room.rs index 890064da..f386bf85 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -1,4 +1,4 @@ -//! Endpoints for room creation. +//! Endpoints for room management. pub mod create_room; pub mod get_room_event; From 301d38c104fc54c06c5767676e7c241d9c6ec6d7 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Thu, 26 Dec 2019 09:44:45 -0500 Subject: [PATCH 175/350] Refactor send and sync modules This commit moves the message, member and state event endpoints from the send and sync modules to make interaction with those events more consistent with how other events are used, for example, `r0::::_event`. --- CHANGELOG.md | 12 +++++++++++- src/r0.rs | 3 ++- src/r0/membership.rs | 1 + src/r0/{sync => membership}/get_member_events.rs | 0 src/r0/message.rs | 4 ++++ .../create_message_event.rs} | 2 +- src/r0/{sync => message}/get_message_events.rs | 0 src/r0/send.rs | 5 ----- src/r0/state.rs | 7 +++++++ .../create_state_event_for_empty_key.rs} | 2 +- .../create_state_event_for_key.rs} | 2 +- src/r0/{sync => state}/get_state_events.rs | 0 .../get_state_events_for_empty_key.rs | 0 src/r0/{sync => state}/get_state_events_for_key.rs | 0 src/r0/sync.rs | 5 ----- 15 files changed, 28 insertions(+), 15 deletions(-) rename src/r0/{sync => membership}/get_member_events.rs (100%) create mode 100644 src/r0/message.rs rename src/r0/{send/send_message_event.rs => message/create_message_event.rs} (97%) rename src/r0/{sync => message}/get_message_events.rs (100%) delete mode 100644 src/r0/send.rs create mode 100644 src/r0/state.rs rename src/r0/{send/send_state_event_for_empty_key.rs => state/create_state_event_for_empty_key.rs} (95%) rename src/r0/{send/send_state_event_for_key.rs => state/create_state_event_for_key.rs} (96%) rename src/r0/{sync => state}/get_state_events.rs (100%) rename src/r0/{sync => state}/get_state_events_for_empty_key.rs (100%) rename src/r0/{sync => state}/get_state_events_for_key.rs (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index c62c4cde..6618fe58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,22 @@ Breaking changes: * Move `r0::room::create_room::Visibility` to `r0::room::Visibility` * Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` * Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in 0.5.0) +* Refactor `r0::send` endpoints and remove module: + * Move `r0::send::send_message_event` to `r0::message::create_message_event` + * Move `r0::send::send_state_event_for_empty_key` to `r0::state:create_state_event_for_empty_key` + * Move `r0::send::send_state_event_for_key` to `r0::state:create_state_event_for_key` +* Refactor `r0::sync` endpoints: + * Move `r0::sync::get_member_events` to `r0::membership::get_member_events` + * Move `r0::sync::get_message_events` to `r0::message::get_message_events` + * Move `r0::sync::get_state_events` to `r0::state::get_state_events` + * Move `r0::sync::get_state_events_for_empty_key` to `r0::state::get_state_events_for_empty_key` + * Move `r0::sync::get_state_events_for_key` to `r0::state::get_state_events_for_key` Improvements: * Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 * Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) -* Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) +* Add `filter` optional parameter to `r0::message::get_message_events` (introduced upstream in r0.3.0) * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 diff --git a/src/r0.rs b/src/r0.rs index 1a57c5f9..68d5a76f 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -11,6 +11,7 @@ pub mod directory; pub mod filter; pub mod media; pub mod membership; +pub mod message; pub mod presence; pub mod profile; pub mod push; @@ -18,9 +19,9 @@ pub mod receipt; pub mod redact; pub mod room; pub mod search; -pub mod send; pub mod server; pub mod session; +pub mod state; pub mod sync; pub mod tag; pub mod thirdparty; diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 833857dc..023965c7 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -2,6 +2,7 @@ pub mod ban_user; pub mod forget_room; +pub mod get_member_events; pub mod invite_user; pub mod join_room_by_id; pub mod join_room_by_id_or_alias; diff --git a/src/r0/sync/get_member_events.rs b/src/r0/membership/get_member_events.rs similarity index 100% rename from src/r0/sync/get_member_events.rs rename to src/r0/membership/get_member_events.rs diff --git a/src/r0/message.rs b/src/r0/message.rs new file mode 100644 index 00000000..1bcdf5ae --- /dev/null +++ b/src/r0/message.rs @@ -0,0 +1,4 @@ +//! Enpoints for sending and receiving messages + +pub mod create_message_event; +pub mod get_message_events; diff --git a/src/r0/send/send_message_event.rs b/src/r0/message/create_message_event.rs similarity index 97% rename from src/r0/send/send_message_event.rs rename to src/r0/message/create_message_event.rs index 81d5f7ba..da5f2f76 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -8,7 +8,7 @@ ruma_api! { metadata { description: "Send a message event to a room.", method: PUT, - name: "send_message_event", + name: "create_message_event", path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", rate_limited: false, requires_authentication: true, diff --git a/src/r0/sync/get_message_events.rs b/src/r0/message/get_message_events.rs similarity index 100% rename from src/r0/sync/get_message_events.rs rename to src/r0/message/get_message_events.rs diff --git a/src/r0/send.rs b/src/r0/send.rs deleted file mode 100644 index 03445f54..00000000 --- a/src/r0/send.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! Endpoints for sending events. - -pub mod send_message_event; -pub mod send_state_event_for_empty_key; -pub mod send_state_event_for_key; diff --git a/src/r0/state.rs b/src/r0/state.rs new file mode 100644 index 00000000..36c8f2b4 --- /dev/null +++ b/src/r0/state.rs @@ -0,0 +1,7 @@ +//! Endpoints for managing room state + +pub mod create_state_event_for_empty_key; +pub mod create_state_event_for_key; +pub mod get_state_events; +pub mod get_state_events_for_empty_key; +pub mod get_state_events_for_key; diff --git a/src/r0/send/send_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs similarity index 95% rename from src/r0/send/send_state_event_for_empty_key.rs rename to src/r0/state/create_state_event_for_empty_key.rs index 0820ed80..935d473f 100644 --- a/src/r0/send/send_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -9,7 +9,7 @@ ruma_api! { metadata { description: "Send a state event to a room associated with the empty state key.", method: PUT, - name: "send_state_event_for_empty_key", + name: "create_state_event_for_empty_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type", rate_limited: false, requires_authentication: true, diff --git a/src/r0/send/send_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs similarity index 96% rename from src/r0/send/send_state_event_for_key.rs rename to src/r0/state/create_state_event_for_key.rs index 7286bcee..c77e9ad7 100644 --- a/src/r0/send/send_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -9,7 +9,7 @@ ruma_api! { metadata { description: "Send a state event to a room associated with a given state key.", method: PUT, - name: "send_state_event_for_key", + name: "create_state_event_for_key", path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", rate_limited: false, requires_authentication: true, diff --git a/src/r0/sync/get_state_events.rs b/src/r0/state/get_state_events.rs similarity index 100% rename from src/r0/sync/get_state_events.rs rename to src/r0/state/get_state_events.rs diff --git a/src/r0/sync/get_state_events_for_empty_key.rs b/src/r0/state/get_state_events_for_empty_key.rs similarity index 100% rename from src/r0/sync/get_state_events_for_empty_key.rs rename to src/r0/state/get_state_events_for_empty_key.rs diff --git a/src/r0/sync/get_state_events_for_key.rs b/src/r0/state/get_state_events_for_key.rs similarity index 100% rename from src/r0/sync/get_state_events_for_key.rs rename to src/r0/state/get_state_events_for_key.rs diff --git a/src/r0/sync.rs b/src/r0/sync.rs index fd6b4679..25045f8d 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -1,8 +1,3 @@ //! Endpoints for getting and synchronizing events. -pub mod get_member_events; -pub mod get_message_events; -pub mod get_state_events; -pub mod get_state_events_for_empty_key; -pub mod get_state_events_for_key; pub mod sync_events; From d2ae6188226d4946e46df7407dfb73656a79ee96 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 31 Dec 2019 00:53:00 +0100 Subject: [PATCH 176/350] Move things done after 0.5.0 to `[unreleased]` in change log --- CHANGELOG.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6618fe58..61e90397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,7 @@ # [unreleased] -# r0.5.0 - Breaking changes: -* Our Minimum Supported Rust Version is now 1.39.0 -* Update ruma-api from 0.11.0 to 0.12.0 -* Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` -* Move `r0::room::create_room::Visibility` to `r0::room::Visibility` -* Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` * Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in 0.5.0) * Refactor `r0::send` endpoints and remove module: * Move `r0::send::send_message_event` to `r0::message::create_message_event` @@ -23,12 +16,25 @@ Breaking changes: Improvements: +* Add `r0::device` endpoints +* Add `r0::room::get_room_event` (introduced in r0.4.0) + +# 0.5.0 + +Breaking changes: + +* Our Minimum Supported Rust Version is now 1.39.0 +* Update ruma-api from 0.11.0 to 0.12.0 +* Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` +* Move `r0::room::create_room::Visibility` to `r0::room::Visibility` +* Move `r0::account::register::AuthenticationData` to `r0::account::AuthenticationData` + +Improvements: + * Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 * Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) -* Add `filter` optional parameter to `r0::message::get_message_events` (introduced upstream in r0.3.0) +* Add `filter` optional parameter to `r0::sync::get_message_events` (introduced upstream in r0.3.0) * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field -* Add `r0::device` endpoints -* Add `r0::room::get_room_event` (introduced in r0.4.0) From 26d7e2f04d66ff8eff8c7555e68982c4db437940 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 31 Dec 2019 17:09:15 +0100 Subject: [PATCH 177/350] Limit `events` in `sync_events::Presence` to `PresenceEvent`s --- src/r0/sync/sync_events.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index b9ccf1ca..2abada9a 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -5,8 +5,13 @@ use std::collections::HashMap; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; use ruma_events::{ - collections::{all, only}, - stripped, EventResult, + collections::{ + all::{RoomEvent, StateEvent}, + only::Event as NonRoomEvent, + }, + presence::PresenceEvent, + stripped::StrippedState, + EventResult, }; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -182,32 +187,33 @@ pub struct Timeline { /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, /// A list of events. - #[wrap_incoming(all::RoomEvent with EventResult)] - pub events: Vec, + #[wrap_incoming(RoomEvent with EventResult)] + pub events: Vec, } /// State events in the room. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct State { /// A list of state events. - #[wrap_incoming(only::StateEvent with EventResult)] - pub events: Vec, + #[wrap_incoming(StateEvent with EventResult)] + pub events: Vec, } /// The private data that this user has attached to this room. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct AccountData { /// A list of events. - #[wrap_incoming(only::Event with EventResult)] - pub events: Vec, + // TODO: Create + #[wrap_incoming(NonRoomEvent with EventResult)] + pub events: Vec, } /// Ephemeral events not recorded in the timeline or state of the room. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct Ephemeral { /// A list of events. - #[wrap_incoming(only::Event with EventResult)] - pub events: Vec, + #[wrap_incoming(NonRoomEvent with EventResult)] + pub events: Vec, } /// Updates to the rooms that the user has been invited to. @@ -222,14 +228,14 @@ pub struct InvitedRoom { #[derive(Clone, Debug, Serialize, Outgoing)] pub struct InviteState { /// A list of state events. - #[wrap_incoming(stripped::StrippedState with EventResult)] - pub events: Vec, + #[wrap_incoming(StrippedState with EventResult)] + pub events: Vec, } /// Updates to the presence status of other users. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct Presence { /// A list of events. - #[wrap_incoming(only::Event with EventResult)] - pub events: Vec, + #[wrap_incoming(PresenceEvent with EventResult)] + pub events: Vec, } From 61bdd1ba9672622552aca952ae77b3b72842f8bb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 31 Dec 2019 17:11:48 +0100 Subject: [PATCH 178/350] Reduce usage of ruma_events::collections::only in the case of get_message_events this intentionally changes a type --- src/r0/message/get_message_events.rs | 6 +++--- src/r0/state/get_state_events.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index 385478ce..c7851020 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::all::RoomEvent, EventResult}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -56,8 +56,8 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - #[wrap_incoming(only::RoomEvent with EventResult)] - pub chunk: Vec, + #[wrap_incoming(RoomEvent with EventResult)] + pub chunk: Vec, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/state/get_state_events.rs b/src/r0/state/get_state_events.rs index 8e3d8a73..3b81e3d4 100644 --- a/src/r0/state/get_state_events.rs +++ b/src/r0/state/get_state_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::all::StateEvent, EventResult}; use ruma_identifiers::RoomId; ruma_api! { @@ -25,7 +25,7 @@ ruma_api! { /// list of events. If the user has left the room then this will be the state of the /// room when they left as a list of events. #[ruma_api(body)] - #[wrap_incoming(only::StateEvent with EventResult)] - pub room_state: Vec, + #[wrap_incoming(StateEvent with EventResult)] + pub room_state: Vec, } } From b3a26c499a096342d389dbae4169442a79d34d05 Mon Sep 17 00:00:00 2001 From: Karlinde Date: Thu, 2 Jan 2020 11:31:54 +0100 Subject: [PATCH 179/350] Add endpoint for setting read markers --- CHANGELOG.md | 1 + src/r0.rs | 1 + src/r0/read_marker.rs | 3 +++ src/r0/read_marker/set_read_marker.rs | 35 +++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 src/r0/read_marker.rs create mode 100644 src/r0/read_marker/set_read_marker.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 61e90397..d811a283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Improvements: * Add `r0::device` endpoints * Add `r0::room::get_room_event` (introduced in r0.4.0) +* Add `r0::read_marker::set_read_marker` (introduced in r0.4.0) # 0.5.0 diff --git a/src/r0.rs b/src/r0.rs index 68d5a76f..cf8718c4 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -15,6 +15,7 @@ pub mod message; pub mod presence; pub mod profile; pub mod push; +pub mod read_marker; pub mod receipt; pub mod redact; pub mod room; diff --git a/src/r0/read_marker.rs b/src/r0/read_marker.rs new file mode 100644 index 00000000..7b9e14c3 --- /dev/null +++ b/src/r0/read_marker.rs @@ -0,0 +1,3 @@ +//! Endpoints for "fully read markers" + +pub mod set_read_marker; diff --git a/src/r0/read_marker/set_read_marker.rs b/src/r0/read_marker/set_read_marker.rs new file mode 100644 index 00000000..e7dbd31d --- /dev/null +++ b/src/r0/read_marker/set_read_marker.rs @@ -0,0 +1,35 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/read_markers](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-read-markers) + +use ruma_api::ruma_api; +use ruma_identifiers::{EventId, RoomId}; + +ruma_api! { + metadata { + description: "Sets the position of the read marker for a given room, and optionally the read receipt's location.", + method: POST, + name: "set_read_marker", + path: "/_matrix/client/r0/rooms/:room_id/read_markers", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The room ID to set the read marker in for the user. + #[ruma_api(path)] + pub room_id: RoomId, + + /// The event ID the read marker should be located at. + /// The event MUST belong to the room. + #[serde(rename = "m.fully_read")] + pub fully_read: EventId, + + /// The event ID to set the read receipt location at. + /// This is equivalent to calling the create_read_receipt endpoint and is + /// provided here to save that extra call. + #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")] + pub read_receipt: Option, + + } + + response {} +} From c0e8e3a84c959a2b2e8fcf8cba981d7f9b344ccb Mon Sep 17 00:00:00 2001 From: Karlinde Date: Thu, 2 Jan 2020 11:37:14 +0100 Subject: [PATCH 180/350] Add endpoint for getting server capabilities --- CHANGELOG.md | 1 + src/r0.rs | 1 + src/r0/capabilities.rs | 3 ++ src/r0/capabilities/get_capabilities.rs | 70 +++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 src/r0/capabilities.rs create mode 100644 src/r0/capabilities/get_capabilities.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index d811a283..fd0b93e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Improvements: * Add `r0::device` endpoints * Add `r0::room::get_room_event` (introduced in r0.4.0) * Add `r0::read_marker::set_read_marker` (introduced in r0.4.0) +* Add `r0::capabilities::get_capabilities` (introduced in r0.5.0) # 0.5.0 diff --git a/src/r0.rs b/src/r0.rs index cf8718c4..93415eb7 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -3,6 +3,7 @@ pub mod account; pub mod alias; pub mod appservice; +pub mod capabilities; pub mod config; pub mod contact; pub mod context; diff --git a/src/r0/capabilities.rs b/src/r0/capabilities.rs new file mode 100644 index 00000000..a0774dd8 --- /dev/null +++ b/src/r0/capabilities.rs @@ -0,0 +1,3 @@ +//! Endpoints for querying the server's supported feature set + +pub mod get_capabilities; diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs new file mode 100644 index 00000000..b657e207 --- /dev/null +++ b/src/r0/capabilities/get_capabilities.rs @@ -0,0 +1,70 @@ +//! [GET /_matrix/client/r0/capabilities](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities) + +use ruma_api::ruma_api; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::HashMap; + +ruma_api! { + metadata { + description: "Gets information about the server's supported feature set and other relevant capabilities.", + method: GET, + name: "get_capabilities", + path: "/_matrix/client/r0/capabilities", + rate_limited: true, + requires_authentication: true + } + + request {} + + response { + /// The capabilities the server supports + pub capabilities: Capabilities, + } +} + +/// Contains information about all the capabilities that the server supports. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Capabilities { + /// Capability to indicate if the user can change their password. + #[serde(rename = "m.change_password", skip_serializing_if = "Option::is_none")] + pub change_password: Option, + + /// The room versions the server supports. + #[serde(rename = "m.room_versions", skip_serializing_if = "Option::is_none")] + pub room_versions: Option, + + /// Any other custom capabilities that the server supports outside of the specification, + /// labeled using the Java package naming convention and stored as arbitrary JSON values. + #[serde(flatten)] + pub custom_capabilities: HashMap, +} + +/// Information about the m.change_password capability +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub struct ChangePasswordCapability { + /// True if the user can change their password, false otherwise. + pub enabled: bool, +} + +/// Information about the m.room_versions capability +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RoomVersionsCapability { + /// The default room version the server is using for new rooms. + pub default: String, + + /// A detailed description of the room versions the server supports. + pub available: HashMap, +} + +/// The stability of a room version +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum RoomVersionStability { + /// An unstable room version + #[serde(rename = "stable")] + Stable, + + /// A stable room version + #[serde(rename = "unstable")] + Unstable, +} From bc03dc6f2ec381f854d6a66c3ce7da226dde730d Mon Sep 17 00:00:00 2001 From: Karlinde Date: Fri, 3 Jan 2020 00:49:29 +0100 Subject: [PATCH 181/350] Add endpoints for key management --- CHANGELOG.md | 1 + src/r0.rs | 1 + src/r0/keys.rs | 152 +++++++++++++++++++++++++++++++++ src/r0/keys/claim_keys.rs | 40 +++++++++ src/r0/keys/get_key_changes.rs | 36 ++++++++ src/r0/keys/get_keys.rs | 46 ++++++++++ src/r0/keys/upload_keys.rs | 35 ++++++++ 7 files changed, 311 insertions(+) create mode 100644 src/r0/keys.rs create mode 100644 src/r0/keys/claim_keys.rs create mode 100644 src/r0/keys/get_key_changes.rs create mode 100644 src/r0/keys/get_keys.rs create mode 100644 src/r0/keys/upload_keys.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index fd0b93e1..20dcf06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Improvements: * Add `r0::room::get_room_event` (introduced in r0.4.0) * Add `r0::read_marker::set_read_marker` (introduced in r0.4.0) * Add `r0::capabilities::get_capabilities` (introduced in r0.5.0) +* Add `r0::keys` endpoints (introduced in r0.3.0) # 0.5.0 diff --git a/src/r0.rs b/src/r0.rs index 93415eb7..79123f05 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -10,6 +10,7 @@ pub mod context; pub mod device; pub mod directory; pub mod filter; +pub mod keys; pub mod media; pub mod membership; pub mod message; diff --git a/src/r0/keys.rs b/src/r0/keys.rs new file mode 100644 index 00000000..e307d3b6 --- /dev/null +++ b/src/r0/keys.rs @@ -0,0 +1,152 @@ +//! Endpoints for key management + +use std::{ + collections::HashMap, + convert::TryFrom, + fmt::{Debug, Display, Error as FmtError, Formatter}, +}; + +use ruma_events::Algorithm; +use ruma_identifiers::{DeviceId, UserId}; +use serde::{ + de::{self, Unexpected}, + Deserialize, Deserializer, Serialize, Serializer, +}; + +pub mod claim_keys; +pub mod get_key_changes; +pub mod get_keys; +pub mod upload_keys; + +/// The basic key algorithms in the specification +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum KeyAlgorithm { + /// The Ed25519 signature algorithm. + #[serde(rename = "ed25519")] + Ed25519, + + /// The Curve25519 ECDH algorithm. + #[serde(rename = "curve25519")] + Curve25519, + + /// The Curve25519 ECDH algorithm, but the key also contains signatures + #[serde(rename = "signed_curve25519")] + SignedCurve25519, +} + +impl Display for KeyAlgorithm { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + let algorithm_str = match *self { + KeyAlgorithm::Ed25519 => "ed25519", + KeyAlgorithm::Curve25519 => "curve25519", + KeyAlgorithm::SignedCurve25519 => "signed_curve25519", + }; + write!(f, "{}", algorithm_str)?; + Ok(()) + } +} + +impl TryFrom<&'_ str> for KeyAlgorithm { + type Error = &'static str; + fn try_from(s: &str) -> Result { + match s { + "ed25519" => Ok(KeyAlgorithm::Ed25519), + "curve25519" => Ok(KeyAlgorithm::Curve25519), + "signed_curve25519" => Ok(KeyAlgorithm::SignedCurve25519), + _ => Err("Unknown algorithm"), + } + } +} + +/// A key algorithm and a device id, combined with a ':' +#[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub DeviceId); + +impl Serialize for AlgorithmAndDeviceId { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let s = format!("{}:{}", self.0, self.1); + serializer.serialize_str(&s) + } +} + +impl<'de> Deserialize<'de> for AlgorithmAndDeviceId { + #[allow(clippy::comparison_chain)] + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value = String::deserialize(deserializer)?; + let parts = value.split(':').collect::>(); + + const EXPECTED: &str = "a string composed of an algorithm and a device id separated by ':'"; + + if parts.len() < 2 { + return Err(de::Error::invalid_type( + Unexpected::Other("string without a ':' separator"), + &EXPECTED, + )); + } else if parts.len() > 2 { + return Err(de::Error::invalid_type( + Unexpected::Other("string with more than one ':' separator"), + &EXPECTED, + )); + } + + let algorithm_result = KeyAlgorithm::try_from(parts[0]); + match algorithm_result { + Ok(algorithm) => Ok(AlgorithmAndDeviceId(algorithm, parts[1].to_string())), + Err(_) => Err(de::Error::invalid_value( + Unexpected::Str(parts[0]), + &"valid key algorithm", + )), + } + } +} + +/// Identity keys for a device. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeviceKeys { + /// The ID of the user the device belongs to. Must match the user ID used when logging in. + pub user_id: UserId, + /// The ID of the device these keys belong to. Must match the device ID used when logging in. + pub device_id: DeviceId, + /// The encryption algorithms supported by this device. + pub algorithms: Vec, + /// Public identity keys. + pub keys: HashMap, + /// Signatures for the device key object. + pub signatures: HashMap>, + /// Additional data added to the device key information by intermediate servers, and + /// not covered by the signatures. + #[serde(skip_serializing_if = "Option::is_none")] + pub unsigned: Option, +} + +/// Additional data added to device key information by intermediate servers. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UnsignedDeviceInfo { + /// The display name which the user set on the device. + device_display_name: String, +} + +/// A key for the SignedCurve25519 algorithm +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SignedKey { + /// Base64-encoded 32-byte Curve25519 public key. + pub key: String, + /// Signatures for the key object. + pub signatures: HashMap>, +} + +/// A one-time public key for "pre-key" messages. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum OneTimeKey { + /// A key containing signatures, for the SignedCurve25519 algorithm. + SignedKey(SignedKey), + /// A string-valued key, for the Ed25519 and Curve25519 algorithms. + Key(String), +} diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs new file mode 100644 index 00000000..b21a62bd --- /dev/null +++ b/src/r0/keys/claim_keys.rs @@ -0,0 +1,40 @@ +//! [POST /_matrix/client/r0/keys/claim](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-claim) + +use std::collections::HashMap; + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::{DeviceId, UserId}; +use serde_json::Value; + +use super::{AlgorithmAndDeviceId, KeyAlgorithm, OneTimeKey}; + +ruma_api! { + metadata { + description: "Claims one-time keys for use in pre-key messages.", + method: POST, + name: "claim_keys", + path: "/_matrix/client/r0/keys/claim", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The time (in milliseconds) to wait when downloading keys from remote servers. + /// 10 seconds is the recommended default. + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + /// The keys to be claimed. + pub one_time_keys: HashMap>, + } + + response { + /// If any remote homeservers could not be reached, they are recorded here. + /// The names of the properties are the names of the unreachable servers. + pub failures: HashMap, + + /// One-time keys for the queried devices. + pub one_time_keys: HashMap>>, + } +} diff --git a/src/r0/keys/get_key_changes.rs b/src/r0/keys/get_key_changes.rs new file mode 100644 index 00000000..f8b8c22a --- /dev/null +++ b/src/r0/keys/get_key_changes.rs @@ -0,0 +1,36 @@ +//! [GET /_matrix/client/r0/keys/changes](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-keys-changes) + +use ruma_api::ruma_api; +use ruma_identifiers::UserId; + +ruma_api! { + metadata { + description: "Gets a list of users who have updated their device identity keys since a previous sync token.", + method: GET, + name: "get_key_changes", + path: "/_matrix/client/r0/keys/changes", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The desired start point of the list. + /// Should be the next_batch field from a response to an earlier call to /sync. + #[ruma_api(query)] + pub from: String, + + /// The desired end point of the list. + /// Should be the next_batch field from a recent call to /sync - typically the most recent such call. + #[ruma_api(query)] + pub to: String, + } + + response { + /// The Matrix User IDs of all users who updated their device identity keys. + pub changed: Vec, + + /// The Matrix User IDs of all users who may have left all the end-to-end + /// encrypted rooms they previously shared with the user. + pub left: Vec + } +} diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs new file mode 100644 index 00000000..e314ffba --- /dev/null +++ b/src/r0/keys/get_keys.rs @@ -0,0 +1,46 @@ +//! [POST /_matrix/client/r0/keys/query](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-query) + +use std::collections::HashMap; + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::{DeviceId, UserId}; +use serde_json::Value; + +use super::DeviceKeys; + +ruma_api! { + metadata { + description: "Returns the current devices and identity keys for the given users.", + method: POST, + name: "get_keys", + path: "/_matrix/client/r0/keys/query", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The time (in milliseconds) to wait when downloading keys from remote servers. + /// 10 seconds is the recommended default. + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. + pub device_keys: HashMap>, + + /// If the client is fetching keys as a result of a device update received in a sync request, + /// this should be the 'since' token of that sync request, or any later sync token. + /// This allows the server to ensure its response contains the keys advertised by the notification in that sync. + #[serde(skip_serializing_if = "Option::is_none")] + pub token: Option + } + + response { + /// If any remote homeservers could not be reached, they are recorded here. + /// The names of the properties are the names of the unreachable servers. + pub failures: HashMap, + + /// Information on the queried devices. + pub device_keys: HashMap>, + } +} diff --git a/src/r0/keys/upload_keys.rs b/src/r0/keys/upload_keys.rs new file mode 100644 index 00000000..64b692ac --- /dev/null +++ b/src/r0/keys/upload_keys.rs @@ -0,0 +1,35 @@ +//! [POST /_matrix/client/r0/keys/upload](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-upload) + +use std::collections::HashMap; + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}; + +ruma_api! { + metadata { + description: "Publishes end-to-end encryption keys for the device.", + method: POST, + name: "upload_keys", + path: "/_matrix/client/r0/keys/upload", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Identity keys for the device. May be absent if no new identity keys are required. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_keys: Option, + + /// One-time public keys for "pre-key" messages. + #[serde(skip_serializing_if = "Option::is_none")] + pub one_time_keys: Option>, + } + + response { + /// For each key algorithm, the number of unclaimed one-time keys of that + /// type currently held on the server for this device. + pub one_time_key_counts: HashMap + } +} From a35f8a7f850176dac1994a6ef66fd425470e4561 Mon Sep 17 00:00:00 2001 From: Karl Linderhed Date: Fri, 3 Jan 2020 14:02:07 +0100 Subject: [PATCH 182/350] Add endpoint for getting supported login types --- src/r0/session.rs | 1 + src/r0/session/get_login_types.rs | 32 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/r0/session/get_login_types.rs diff --git a/src/r0/session.rs b/src/r0/session.rs index 0ee3808b..5096af71 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -1,5 +1,6 @@ //! Endpoints for user session management. +pub mod get_login_types; pub mod login; pub mod logout; pub mod logout_all; diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs new file mode 100644 index 00000000..7f0d0d4d --- /dev/null +++ b/src/r0/session/get_login_types.rs @@ -0,0 +1,32 @@ +//! [GET /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-login) + +use ruma_api::ruma_api; +use serde::{Deserialize, Serialize}; + +use super::login::LoginType; + +ruma_api! { + metadata { + description: "Gets the homeserver's supported login types to authenticate users. Clients should pick one of these and supply it as the type when logging in.", + method: GET, + name: "get_login_types", + path: "/_matrix/client/r0/login", + rate_limited: true, + requires_authentication: false, + } + + request {} + + response { + /// The homeserver's supported login types. + pub flows: Vec + } +} + +/// A supported login type in a homeserver +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub struct LoginFlow { + /// The login type. + #[serde(rename = "type")] + pub login_type: LoginType, +} From 3ec3a6e2f2618320e4ebf50416f09c409f24532e Mon Sep 17 00:00:00 2001 From: iinuwa Date: Fri, 3 Jan 2020 10:04:32 -0500 Subject: [PATCH 183/350] Add contributor guide --- CONTRIBUTING.md | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..46856b78 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,172 @@ +Welcome! Thanks for looking into contributing to our project! + +# Table of Contents + +- [Looking for Help?](#looking-for-help) + - [Documentation](#documentation) + - [Chat Rooms](#chat-rooms) +- [Reporting Issues](#reporting-issues) +- [Submitting Code](#submitting-code) + - [Coding Style](#coding-style) + - [Modifying Endpoints](#modifying-endpoints) + - [Submitting PRs](#submitting-prs) + - [Where do I start?](#where-do-i-start) +- [Testing](#testing) +- [Contact](#contact) + +# Looking for Help? + +Here is a list of helpful resources you can consult: + +## Documentation + +- [Matrix spec Documentation](https://matrix.org/docs/spec/client_server/latest) +- Documentation to other Ruma modules: + - [ruma-events](https://docs.rs/ruma-events/) + - [ruma-api](https://docs.rs/ruma-api/) + - [ruma-client](https://docs.rs/ruma-client/) + +## Chat Rooms + +- Ruma Matrix room: [#ruma:matrix.org](https://matrix.to/#/#ruma:matrix.org) +- Matrix Developer room: [#matrix-dev:matrix.org](https://matrix.to/#/#matrix-dev:matrix.org) + +# Reporting Issues + +If you find any bugs, inconsistencies or other problems, feel free to submit +a GitHub [issue](issues). + +If you have a quick question, it may be easier to leave a message on +[#ruma:matrix.org](https://matrix.to/#/#ruma:matrix.org). + +Also, if you have trouble getting on board, let us know so we can help future +contributors to the project overcome that hurdle too. + +# Submitting Code + +Ready to write some code? Great! Here are some guidelines to follow to +help you on your way: + +## Coding Style + +### Import Formatting + +Organize your imports into three groups separated by blank lines: + +1. `std` imports +1. External imports (from other crates) +1. Local imports (`self::`, `super::`, `crate::` and things like `LocalType::*`) + +For example, + +```rust +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::MyType; +``` + +Also, group imports by module. For example, do this: + +```rust +use std::{ + collections::HashMap, + convert::TryFrom, + fmt::{Debug, Display, Error as FmtError, Formatter}, +}; +``` + +as opposed to: + +```rust +use std::collections::HashMap; +use std::convert::TryFrom; +use std::fmt::{Debug, Display, Error as FmtError, Formatter}; +``` + +### Code Formatting and Linting + +Use `rustfmt` to format your code and `clippy` to lint your code. Before +committing your changes, go ahead and run `cargo fmt` and `cargo clippy +--all-targets --all-features` on the repository to make sure that the +formatting and linting checks pass in CI. Note that `clippy` warnings are +reported as errors in CI builds, so make sure to handle those before +comitting as well. (To install the tools, run `rustup component add rustfmt +clippy`.) + +### Commit Messages + +Write commit messages using the imperative mood, as if completing the sentence: +"If applied, this commit will \_\_\_." For example, use "Fix some bug" instead +of "Fixed some bug" or "Add a feature" instead of "Added a feature". + +(Take a look at this +[blog post](https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/) +for more information on writing good commit messages.) + +## Modifying Endpoints + +### Matrix Spec Version + +Use the latest r0.x.x documentation when adding or modifying code. We target +the latest minor version of the Matrix specification. (Note: We might +reconsider this when the Client-Server API hits r1.0.0.) + +### Endpoint Documentation Header + +Add a comment to the top of each endpoint file that includes the path +and a link to the documentation of the spec. You can use the latest +version at the time of the commit. For example: + +```rust +//! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.4.0#get-well-known-matrix-client) +``` + +### Naming Endpoints + +When adding new endpoints, select the module that fits the purpose of the +endpoint. When naming the endpoint itself, you can use the following +guidelines: +- The name should be a verb describing what the client is requesting, e.g. + `get_some_resource`. +- Endpoints which are basic CRUD operations should use the prefixes + `create`, `get`, `update`, and `delete`. +- The prefix `set` is preferred to create if the resource is a singleton. + In other words, when there's no distinction between `create` and `update`. +- Try to use names that are as descriptive as possible and distinct from + other endpoints in all other modules. (For example, instead of + `r0::room::get_event`, use `r0::room::get_room_event`). +- If you're not sure what to name it, pick any name and we can help you + with it. + +### Tracking Changes + +Add your changes to the [change log](CHANGELOG.md). If possible, try to +find and denote the version of the spec that included the change you are +making. + +## Submitting PRs + +Once you're ready to submit your code, create a pull request, and one of our +maintainers will review it. Once your PR has passed review, a maintainer will +merge the request and you're done! 🎉 + +## Where do I start? + +If this is your first contribution to the project, we recommend taking a look +at one of the [open issues][] we've marked for new contributors. + +It may be helpful to peruse some of the documentation for `ruma-events` and +`ruma-api` listed above for some context. + +[open issues]: https://github.com/ruma/ruma-client-api/issues?q=is%3Aopen+is%3Aissue+label%3Aeffort%2Feasy + +# Testing + +Before committing, run `cargo check` to make sure that your changes can build, as well as running the formatting and linting tools [mentioned above](#code-formatting-and-linting). + +# Contact + +Thanks again for being a contributor! If you have any questions, join us at +[#ruma:matrix.org](https://matrix.to/#/#ruma:matrix.org). From 806eec754bcac25e59b9d1d0fe7f4440877b766c Mon Sep 17 00:00:00 2001 From: Karl Linderhed Date: Fri, 3 Jan 2020 17:11:25 +0100 Subject: [PATCH 184/350] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20dcf06c..8e49bf58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Improvements: * Add `r0::read_marker::set_read_marker` (introduced in r0.4.0) * Add `r0::capabilities::get_capabilities` (introduced in r0.5.0) * Add `r0::keys` endpoints (introduced in r0.3.0) +* Add `r0::session::get_login_types` (introduced in r0.4.0) # 0.5.0 From 4a0e0e8bfe2d516d7d82e1025fd75659aa580c28 Mon Sep 17 00:00:00 2001 From: Karl Linderhed Date: Fri, 3 Jan 2020 22:13:40 +0100 Subject: [PATCH 185/350] Add get_username_availibility endpoint --- CHANGELOG.md | 1 + src/r0/account.rs | 1 + src/r0/account/get_username_availability.rs | 26 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/r0/account/get_username_availability.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e49bf58..f5ba26a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Improvements: * Add `r0::capabilities::get_capabilities` (introduced in r0.5.0) * Add `r0::keys` endpoints (introduced in r0.3.0) * Add `r0::session::get_login_types` (introduced in r0.4.0) +* Add `r0::account::get_username_availability` (introduced in r0.4.0) # 0.5.0 diff --git a/src/r0/account.rs b/src/r0/account.rs index c1507fa9..6dee7f72 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,6 +2,7 @@ pub mod change_password; pub mod deactivate; +pub mod get_username_availability; pub mod register; pub mod request_password_change_token; pub mod request_register_token; diff --git a/src/r0/account/get_username_availability.rs b/src/r0/account/get_username_availability.rs new file mode 100644 index 00000000..c2fc34ff --- /dev/null +++ b/src/r0/account/get_username_availability.rs @@ -0,0 +1,26 @@ +//! [GET /_matrix/client/r0/register/available](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available) + +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Checks to see if a username is available, and valid, for the server.", + method: GET, + name: "get_username_availability", + path: "/_matrix/client/r0/register/available", + rate_limited: true, + requires_authentication: false, + } + + request { + /// The username to check the availability of. + #[ruma_api(query)] + pub username: String, + } + + response { + /// A flag to indicate that the username is available. + /// This should always be true when the server replies with 200 OK. + pub available: bool + } +} From 097bd6a86c84cca8da0ef2207830416fda64020f Mon Sep 17 00:00:00 2001 From: iinuwa Date: Thu, 9 Jan 2020 05:45:28 -0600 Subject: [PATCH 186/350] Add/update endpoints for requesting account management tokens --- CHANGELOG.md | 11 ++++- src/r0/account.rs | 20 ++++++++- ...request_3pid_management_token_via_email.rs | 41 ++++++++++++++++++ ...equest_3pid_management_token_via_msisdn.rs | 43 +++++++++++++++++++ .../account/request_password_change_token.rs | 29 ------------- ...request_password_change_token_via_email.rs | 41 ++++++++++++++++++ ...equest_password_change_token_via_msisdn.rs | 37 ++++++++++++++++ src/r0/account/request_register_token.rs | 29 ------------- .../request_registration_token_via_email.rs | 41 ++++++++++++++++++ .../request_registration_token_via_msisdn.rs | 43 +++++++++++++++++++ 10 files changed, 274 insertions(+), 61 deletions(-) create mode 100644 src/r0/account/request_3pid_management_token_via_email.rs create mode 100644 src/r0/account/request_3pid_management_token_via_msisdn.rs delete mode 100644 src/r0/account/request_password_change_token.rs create mode 100644 src/r0/account/request_password_change_token_via_email.rs create mode 100644 src/r0/account/request_password_change_token_via_msisdn.rs delete mode 100644 src/r0/account/request_register_token.rs create mode 100644 src/r0/account/request_registration_token_via_email.rs create mode 100644 src/r0/account/request_registration_token_via_msisdn.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ba26a9..af0ba747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Breaking changes: * Move `r0::sync::get_state_events` to `r0::state::get_state_events` * Move `r0::sync::get_state_events_for_empty_key` to `r0::state::get_state_events_for_empty_key` * Move `r0::sync::get_state_events_for_key` to `r0::state::get_state_events_for_key` +* Update endpoints for requesting account management tokens via email: + * Move `r0::account::request_password_change_token` to `r0::account::request_password_change_token_via_email` + * Move `r0::account::request_register_token` to `r0::account::request_registration_token_via_email` + * Modify `r0::account::request_registration_token_via_email` not to be rate-limited and require authentication Improvements: @@ -23,6 +27,11 @@ Improvements: * Add `r0::keys` endpoints (introduced in r0.3.0) * Add `r0::session::get_login_types` (introduced in r0.4.0) * Add `r0::account::get_username_availability` (introduced in r0.4.0) +* Add endpoints to request management tokens (introduced upstream in r0.4.0): + * `r0::account::request_3pid_management_token_via_msisdn` + * `r0::account::request_password_change_token_via_msisdn` + * `r0::account::request_registration_token_via_msisdn` + * `r0::acount::request_3pid_management_token_via_email` # 0.5.0 @@ -42,4 +51,4 @@ Improvements: * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 - * Add optional `auth` field + * Add optional `auth` field \ No newline at end of file diff --git a/src/r0/account.rs b/src/r0/account.rs index 6dee7f72..66460b05 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -4,8 +4,13 @@ pub mod change_password; pub mod deactivate; pub mod get_username_availability; pub mod register; -pub mod request_password_change_token; -pub mod request_register_token; +pub mod request_3pid_management_token_via_email; +pub mod request_3pid_management_token_via_msisdn; +pub mod request_password_change_token_via_email; +pub mod request_password_change_token_via_msisdn; +pub mod request_registration_token_via_email; +pub mod request_registration_token_via_msisdn; + pub mod whoami; use serde::{Deserialize, Serialize}; @@ -19,3 +24,14 @@ pub struct AuthenticationData { /// The value of the session key given by the homeserver. session: Option, } + +/// Additional authentication information for requestToken endpoints. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct IdentityServerInfo { + /// The ID server to send the onward request to as a hostname with an + /// appended colon and port number if the port is not the default. + /// Deprecated since r0.6.0. + pub id_server: String, + /// Access token previously registered with identity server. + pub id_access_token: String, +} diff --git a/src/r0/account/request_3pid_management_token_via_email.rs b/src/r0/account/request_3pid_management_token_via_email.rs new file mode 100644 index 00000000..5485c1fa --- /dev/null +++ b/src/r0/account/request_3pid_management_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a 3PID management token with a 3rd party email.", + method: POST, + name: "request_3pid_association_token_via_email", + path: "/_matrix/client/r0/account/3pid/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_3pid_management_token_via_msisdn.rs b/src/r0/account/request_3pid_management_token_via_msisdn.rs new file mode 100644 index 00000000..0d0ef810 --- /dev/null +++ b/src/r0/account/request_3pid_management_token_via_msisdn.rs @@ -0,0 +1,43 @@ +//! [POST /_matrix/client/r0/account/3pid/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a 3PID management token with a phone number.", + method: POST, + name: "request_3pid_association_token_via_msisdn", + path: "/_matrix/client/r0/account/3pid/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs deleted file mode 100644 index 976ba5fd..00000000 --- a/src/r0/account/request_password_change_token.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) - -use js_int::UInt; -use ruma_api::ruma_api; - -ruma_api! { - metadata { - description: "Request that a password change token is sent to the given email address.", - method: POST, - name: "request_password_change_token", - path: "/_matrix/client/r0/account/password/email/requestToken", - rate_limited: false, - requires_authentication: false, - } - - request { - /// TODO: This parameter is not documented in the spec. - pub client_secret: String, - /// TODO: This parameter is not documented in the spec. - pub email: String, - /// TODO: This parameter is not documented in the spec. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// TODO: This parameter is not documented in the spec. - pub send_attempt: UInt, - } - - response {} -} diff --git a/src/r0/account/request_password_change_token_via_email.rs b/src/r0/account/request_password_change_token_via_email.rs new file mode 100644 index 00000000..0ddbbf77 --- /dev/null +++ b/src/r0/account/request_password_change_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request that a password change token is sent to the given email address.", + method: POST, + name: "request_password_change_token_via_email", + path: "/_matrix/client/r0/account/password/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_password_change_token_via_msisdn.rs b/src/r0/account/request_password_change_token_via_msisdn.rs new file mode 100644 index 00000000..35eaf27f --- /dev/null +++ b/src/r0/account/request_password_change_token_via_msisdn.rs @@ -0,0 +1,37 @@ +//! [POST /_matrix/client/r0/account/password/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Request that a password change token is sent to the given phone number.", + method: POST, + name: "request_password_change_token_via_msisdn", + path: "/_matrix/client/r0/account/password/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs deleted file mode 100644 index d06321cc..00000000 --- a/src/r0/account/request_register_token.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) - -use js_int::UInt; -use ruma_api::ruma_api; - -ruma_api! { - metadata { - description: "Request a register token with a 3rd party email.", - method: POST, - name: "request_register_token", - path: "/_matrix/client/r0/register/email/requestToken", - rate_limited: true, - requires_authentication: true, - } - - request { - /// Client-generated secret string used to protect this session. - pub client_secret: String, - /// The email address. - pub email: String, - /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, - } - - response {} -} diff --git a/src/r0/account/request_registration_token_via_email.rs b/src/r0/account/request_registration_token_via_email.rs new file mode 100644 index 00000000..2b10eafc --- /dev/null +++ b/src/r0/account/request_registration_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a registration token with a 3rd party email.", + method: POST, + name: "request_registration_token_via_email", + path: "/_matrix/client/r0/register/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_registration_token_via_msisdn.rs b/src/r0/account/request_registration_token_via_msisdn.rs new file mode 100644 index 00000000..dc8dfa6d --- /dev/null +++ b/src/r0/account/request_registration_token_via_msisdn.rs @@ -0,0 +1,43 @@ +//! [POST /_matrix/client/r0/register/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-register-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a registration token with a phone number.", + method: POST, + name: "request_registration_token_via_msisdn", + path: "/_matrix/client/r0/register/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} From 246de197902bd523285a7a56bcefaa06e9bd008e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 13 Jan 2020 11:45:35 +0100 Subject: [PATCH 187/350] Update get_presence to r0.6.0 --- CHANGELOG.md | 7 ++++--- src/r0/presence/get_presence.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af0ba747..b19a690c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,8 +30,9 @@ Improvements: * Add endpoints to request management tokens (introduced upstream in r0.4.0): * `r0::account::request_3pid_management_token_via_msisdn` * `r0::account::request_password_change_token_via_msisdn` - * `r0::account::request_registration_token_via_msisdn` - * `r0::acount::request_3pid_management_token_via_email` + * `r0::account::request_registration_token_via_msisdn` + * `r0::acount::request_3pid_management_token_via_email` +* Update `r0::presence_get_presence` from r0.4.0 to r0.6.0 # 0.5.0 @@ -51,4 +52,4 @@ Improvements: * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 - * Add optional `auth` field \ No newline at end of file + * Add optional `auth` field diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index d06e35e2..0d76d74c 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status) +//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status) use js_int::UInt; use ruma_api::ruma_api; @@ -12,7 +12,7 @@ ruma_api! { name: "get_presence", path: "/_matrix/client/r0/presence/:user_id/status", rate_limited: false, - requires_authentication: false, + requires_authentication: true, } request { From 258fbf5a0154602612ed6bb18821b62791ff3f7a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 13 Jan 2020 20:20:17 +0100 Subject: [PATCH 188/350] Use #[ruma_api(raw_body)] for r0::media::{get,create}_media --- Cargo.toml | 2 +- src/r0/media/create_content.rs | 2 +- src/r0/media/get_content.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47b7cb11..d7da2448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.12.0" +ruma-api = "0.12.1" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.103", features = ["derive"] } diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index 5cc22aec..2a9f8eea 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -21,7 +21,7 @@ ruma_api! { #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, /// The file contents to upload. - #[ruma_api(body)] + #[ruma_api(raw_body)] pub file: Vec, } diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 83f9d937..3374729a 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -25,7 +25,7 @@ ruma_api! { response { /// The content that was previously uploaded. - #[ruma_api(body)] + #[ruma_api(raw_body)] pub file: Vec, /// The content type of the file that was previously uploaded. #[ruma_api(header = CONTENT_TYPE)] From 4bc52af69af2c75958b8d3c34a6e5876fb104d18 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Mon, 13 Jan 2020 16:22:09 -0600 Subject: [PATCH 189/350] Add missing 3PID endpoints --- src/r0/account.rs | 12 +++++++++++- src/r0/account/bind_3pid.rs | 29 +++++++++++++++++++++++++++++ src/r0/account/delete_3pid.rs | 33 +++++++++++++++++++++++++++++++++ src/r0/account/unbind_3pid.rs | 33 +++++++++++++++++++++++++++++++++ src/r0/contact/get_contacts.rs | 9 +-------- src/r0/session/login.rs | 9 +-------- src/r0/thirdparty.rs | 10 ++++++++++ 7 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 src/r0/account/bind_3pid.rs create mode 100644 src/r0/account/delete_3pid.rs create mode 100644 src/r0/account/unbind_3pid.rs diff --git a/src/r0/account.rs b/src/r0/account.rs index 66460b05..b16ab28f 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -1,7 +1,9 @@ //! Endpoints for account registration and management. +pub mod bind_3pid; pub mod change_password; pub mod deactivate; +pub mod delete_3pid; pub mod get_username_availability; pub mod register; pub mod request_3pid_management_token_via_email; @@ -10,6 +12,7 @@ pub mod request_password_change_token_via_email; pub mod request_password_change_token_via_msisdn; pub mod request_registration_token_via_email; pub mod request_registration_token_via_msisdn; +pub mod unbind_3pid; pub mod whoami; @@ -30,8 +33,15 @@ pub struct AuthenticationData { pub struct IdentityServerInfo { /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. - /// Deprecated since r0.6.0. pub id_server: String, /// Access token previously registered with identity server. pub id_access_token: String, } + +/// Possible values for deleting or unbinding 3PIDs +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +enum ThirdPartyIdRemovalStatus { + NoSupport, + Success, +} diff --git a/src/r0/account/bind_3pid.rs b/src/r0/account/bind_3pid.rs new file mode 100644 index 00000000..e8603f6e --- /dev/null +++ b/src/r0/account/bind_3pid.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/account/3pid/bind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind) + +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Bind a 3PID to a user's account on an identity server", + method: POST, + name: "bind_3pid", + path: "/_matrix/client/r0/account/3pid/bind", + rate_limited: true, + requires_authentication: true, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The ID server to send the onward request to as a hostname with an + /// appended colon and port number if the port is not the default. + #[serde(flatten)] + pub identity_server_info: IdentityServerInfo, + /// The session identifier given by the identity server. + pub sid: String, + } + + response {} +} diff --git a/src/r0/account/delete_3pid.rs b/src/r0/account/delete_3pid.rs new file mode 100644 index 00000000..b9109efe --- /dev/null +++ b/src/r0/account/delete_3pid.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/account/3pid/delete](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-delete) + +use ruma_api::ruma_api; + +use super::ThirdPartyIdRemovalStatus; +use crate::r0::thirdparty::Medium; + +ruma_api! { + metadata { + description: "Delete a 3PID from a user's account on an identity server.", + method: POST, + name: "delete_3pid", + path: "/_matrix/client/r0/account/3pid/delete", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Identity server to delete from. + #[serde(skip_serializing_if = "Option::is_none")] + id_server: Option, + /// Medium of the 3PID to be removed. + medium: Medium, + /// Third-party address being removed. + address: String, + } + + response { + /// Result of unbind operation. + id_server_unbind_result: ThirdPartyIdRemovalStatus, + } + +} diff --git a/src/r0/account/unbind_3pid.rs b/src/r0/account/unbind_3pid.rs new file mode 100644 index 00000000..69f68f8e --- /dev/null +++ b/src/r0/account/unbind_3pid.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/account/3pid/unbind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-unbind) + +use ruma_api::ruma_api; + +use super::ThirdPartyIdRemovalStatus; +use crate::r0::thirdparty::Medium; + +ruma_api! { + metadata { + description: "Unbind a 3PID from a user's account on an identity server.", + method: POST, + name: "unbind_3pid", + path: "/_matrix/client/r0/account/3pid/unbind", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Identity server to unbind from. + #[serde(skip_serializing_if = "Option::is_none")] + id_server: Option, + /// Medium of the 3PID to be removed. + medium: Medium, + /// Third-party address being removed. + address: String, + } + + response { + /// Result of unbind operation. + id_server_unbind_result: ThirdPartyIdRemovalStatus, + } + +} diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index c7ba4814..5c7837c6 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid) +use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; @@ -22,14 +23,6 @@ ruma_api! { } } -/// The medium of third party identifier. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, -} - /// An identifier external to Matrix. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartyIdentifier { diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 01dea6ed..6e4a4b17 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,5 +1,6 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) +use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; @@ -52,14 +53,6 @@ ruma_api! { } } -/// The medium of a third party identifier. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, -} - /// The authentication mechanism. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum LoginType { diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index 185ad65e..82b1012d 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -72,3 +72,13 @@ pub struct User { /// Information used to identify this third party user. pub fields: HashMap, } + +/// The medium of a third party identifier. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Medium { + /// Email address identifier + Email, + /// Phone number identifier + MSISDN, +} From 4a37625ea9d52fe5fe14575881d9dd2b03dfabb7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 13 Jan 2020 23:26:10 +0100 Subject: [PATCH 190/350] Update change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b19a690c..f90e4328 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Breaking changes: * Move `r0::account::request_password_change_token` to `r0::account::request_password_change_token_via_email` * Move `r0::account::request_register_token` to `r0::account::request_registration_token_via_email` * Modify `r0::account::request_registration_token_via_email` not to be rate-limited and require authentication +* Merge duplicate enums `r0::contact::get_contact::Medium` and `r0::session::login::Medium` and move them to `r0::thirdparty` Improvements: @@ -33,6 +34,9 @@ Improvements: * `r0::account::request_registration_token_via_msisdn` * `r0::acount::request_3pid_management_token_via_email` * Update `r0::presence_get_presence` from r0.4.0 to r0.6.0 +* Add `r0::account::bind_3pid` +* Add `r0::account::delete_3pid` +* Add `r0::account::unbind_3pid` # 0.5.0 From 0314384c60c9d2c85fdef9224d0916901c54d6d2 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Tue, 14 Jan 2020 08:20:31 -0600 Subject: [PATCH 191/350] Add content reporting endpoint --- src/r0/room.rs | 1 + src/r0/room/report_content.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/r0/room/report_content.rs diff --git a/src/r0/room.rs b/src/r0/room.rs index f386bf85..c0ab2146 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -2,6 +2,7 @@ pub mod create_room; pub mod get_room_event; +pub mod report_content; use serde::{Deserialize, Serialize}; diff --git a/src/r0/room/report_content.rs b/src/r0/room/report_content.rs new file mode 100644 index 00000000..43713bea --- /dev/null +++ b/src/r0/room/report_content.rs @@ -0,0 +1,31 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/report/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-report-eventid) + +use js_int::Int; +use ruma_api::ruma_api; +use ruma_identifiers::{EventId, RoomId}; + +ruma_api! { + metadata { + description: "Report content as inappropriate.", + method: POST, + name: "report_content", + path: "/rooms/:room_id/report/:event_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Room in which the event to be reported is located. + #[ruma_api(path)] + room_id: RoomId, + /// Event to report. + #[ruma_api(path)] + event_id: EventId, + /// Integer between -100 and 0 rating offensivness. + score: Int, + /// Reason to report content. May be blank. + reason: String, + } + + response {} +} From 505721bdade3deb3e3276fd28ba576e6c63274fa Mon Sep 17 00:00:00 2001 From: Karlinde Date: Tue, 14 Jan 2020 21:58:28 +0100 Subject: [PATCH 192/350] Add endpoints for push notifications --- CHANGELOG.md | 1 + src/r0/push.rs | 326 ++++++++++++++++++++++ src/r0/push/delete_pushrule.rs | 32 +++ src/r0/push/get_notifications.rs | 74 +++++ src/r0/push/get_pushers.rs | 23 ++ src/r0/push/get_pushrule.rs | 36 +++ src/r0/push/get_pushrule_actions.rs | 35 +++ src/r0/push/get_pushrule_enabled.rs | 35 +++ src/r0/push/get_pushrules_all.rs | 25 ++ src/r0/push/get_pushrules_global_scope.rs | 26 ++ src/r0/push/set_pusher.rs | 30 ++ src/r0/push/set_pushrule.rs | 52 ++++ src/r0/push/set_pushrule_actions.rs | 35 +++ src/r0/push/set_pushrule_enabled.rs | 35 +++ 14 files changed, 765 insertions(+) create mode 100644 src/r0/push/delete_pushrule.rs create mode 100644 src/r0/push/get_notifications.rs create mode 100644 src/r0/push/get_pushers.rs create mode 100644 src/r0/push/get_pushrule.rs create mode 100644 src/r0/push/get_pushrule_actions.rs create mode 100644 src/r0/push/get_pushrule_enabled.rs create mode 100644 src/r0/push/get_pushrules_all.rs create mode 100644 src/r0/push/get_pushrules_global_scope.rs create mode 100644 src/r0/push/set_pusher.rs create mode 100644 src/r0/push/set_pushrule.rs create mode 100644 src/r0/push/set_pushrule_actions.rs create mode 100644 src/r0/push/set_pushrule_enabled.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f90e4328..612050cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Improvements: * Add `r0::account::bind_3pid` * Add `r0::account::delete_3pid` * Add `r0::account::unbind_3pid` +* Add `r0::push` endpoints # 0.5.0 diff --git a/src/r0/push.rs b/src/r0/push.rs index 31a27f48..6796d9ec 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -1 +1,327 @@ //! Endpoints for push notifications. + +use std::fmt::{Display, Formatter, Result as FmtResult}; + +use serde::{ + de::{Error as SerdeError, MapAccess, Unexpected, Visitor}, + ser::SerializeStruct, + Deserialize, Deserializer, Serialize, Serializer, +}; +use serde_json::Value as JsonValue; + +pub mod delete_pushrule; +pub mod get_notifications; +pub mod get_pushers; +pub mod get_pushrule; +pub mod get_pushrule_actions; +pub mod get_pushrule_enabled; +pub mod get_pushrules_all; +pub mod get_pushrules_global_scope; +pub mod set_pusher; +pub mod set_pushrule; +pub mod set_pushrule_actions; +pub mod set_pushrule_enabled; + +/// The kinds of push rules that are available +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] +#[serde(rename_all = "snake_case")] +pub enum RuleKind { + /// User-configured rules that override all other kinds + Override, + + /// Lowest priority user-defined rules + Underride, + + /// Sender-specific rules + Sender, + + /// Room-specific rules + Room, + + /// Content-specific rules + Content, +} + +impl Display for RuleKind { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + let s = match self { + RuleKind::Override => "override", + RuleKind::Underride => "underride", + RuleKind::Sender => "sender", + RuleKind::Room => "room", + RuleKind::Content => "content", + }; + write!(f, "{}", s) + } +} + +/// A push rule +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct PushRule { + /// The actions to perform when this rule is matched. + pub actions: Vec, + + /// Whether this is a default rule, or has been set explicitly. + pub default: bool, + + /// Whether the push rule is enabled or not. + pub enabled: bool, + + /// The ID of this rule. + pub rule_id: String, + + /// The conditions that must hold true for an event in order for a rule to be applied to an event. A rule with no conditions always matches. + /// Only applicable to underride and override rules. + #[serde(skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + + /// The glob-style pattern to match against. Only applicable to content rules. + #[serde(skip_serializing_if = "Option::is_none")] + pub pattern: Option, +} + +/// A condition for a push rule +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(tag = "kind", rename_all = "snake_case")] // Using internally tagged enum representation to match the spec +pub enum PushCondition { + /// This is a glob pattern match on a field of the event. + EventMatch { + /// The dot-separated field of the event to match, e.g. `content.body` + key: String, + /// The glob-style pattern to match against. + pattern: String, + }, + + /// This matches unencrypted messages where `content.body` contains + /// the owner's display name in that room. + ContainsDisplayName, + + /// This matches the current number of members in the room. + RoomMemberCount { + /// A decimal integer optionally prefixed by one of, ==, <, >, >= or <=. + /// Default prefix is ==. + is: String, + }, + + /// This takes into account the current power levels in the room, ensuring the + /// sender of the event has high enough power to trigger the notification. + SenderNotificationPermission { + /// A string that determines the power level the sender must have to + /// trigger notifications of a given type, such as `room`. + key: String, + }, +} + +/// Defines a pusher +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Pusher { + /// This is a unique identifier for this pusher. Max length, 512 bytes. + pub pushkey: String, + + /// The kind of the pusher. If set to None in a call to set_pusher, this + /// will delete the pusher + pub kind: Option, + + /// This is a reverse-DNS style identifier for the application. Max length, 64 chars. + pub app_id: String, + + /// A string that will allow the user to identify what application owns this pusher. + pub app_display_name: String, + + /// A string that will allow the user to identify what device owns this pusher. + pub device_display_name: String, + + /// This string determines which set of device specific rules this pusher executes. + #[serde(skip_serializing_if = "Option::is_none")] + pub profile_tag: Option, + + /// The preferred language for receiving notifications (e.g. 'en' or 'en-US') + pub lang: String, + + /// Information for the pusher implementation itself. + pub data: PusherData, +} + +/// Which kind a pusher is +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum PusherKind { + /// A pusher that sends HTTP pokes. + Http, + + /// A pusher that emails the user with unread notifications. + Email, +} + +/// Information for the pusher implementation itself. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct PusherData { + /// Required if the pusher's kind is http. The URL to use to send notifications to. + #[serde(skip_serializing_if = "Option::is_none")] + pub url: Option, + + /// The format to use when sending notifications to the Push Gateway. + #[serde(skip_serializing_if = "Option::is_none")] + pub format: Option, +} + +/// A special format that the homeserver should use when sending notifications to a Push Gateway. +/// Currently, only "event_id_only" is supported as of [Push Gateway API r0.1.1](https://matrix.org/docs/spec/push_gateway/r0.1.1#homeserver-behaviour) +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum PushFormat { + /// Require the homeserver to only send a reduced set of fields in the push. + EventIdOnly, +} + +/// This represents the different actions that should be taken when a rule is matched, and +/// controls how notifications are delivered to the client. +// See https://matrix.org/docs/spec/client_server/r0.6.0#actions for details. +#[derive(Clone, Debug)] +pub enum Action { + /// Causes matching events to generate a notification. + Notify, + + /// Prevents matching events from generating a notification. + DontNotify, + + /// Behaves like notify but homeservers may choose to coalesce multiple events + /// into a single notification. + Coalesce, + + /// Sets an entry in the 'tweaks' dictionary sent to the push gateway. + SetTweak { + /// The kind of this tweak + kind: TweakKind, + + /// The value of the tweak, if any + value: Option, + }, +} + +/// The different kinds of tweaks available +#[derive(Clone, Debug)] +pub enum TweakKind { + /// The "sound" tweak. + Sound, + + /// The "highlight" tweak. + Highlight, + + /// A name for a custom client-defined tweak. + Custom(String), +} + +impl Serialize for Action { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Action::Notify => serializer.serialize_unit_variant("Action", 0, "notify"), + Action::DontNotify => serializer.serialize_unit_variant("Action", 1, "dont_notify"), + Action::Coalesce => serializer.serialize_unit_variant("Action", 2, "coalesce"), + Action::SetTweak { kind, value } => { + let kind_name = match &kind { + TweakKind::Sound => "sound", + TweakKind::Highlight => "highlight", + TweakKind::Custom(name) => name, + }; + let num_fields = match value { + Some(_) => 2, + None => 1, + }; + let mut s = serializer.serialize_struct("Action", num_fields)?; + s.serialize_field("set_tweak", kind_name)?; + + match &value { + Some(value) => { + s.serialize_field("value", value)?; + } + None => {} + }; + s.end() + } + } + } +} + +impl<'de> Deserialize<'de> for Action { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ActionVisitor; + impl<'de> Visitor<'de> for ActionVisitor { + type Value = Action; + + fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult { + write!(formatter, "a valid action object") + } + + /// Match a simple action type + fn visit_str(self, v: &str) -> Result + where + E: SerdeError, + { + match v { + "notify" => Ok(Action::Notify), + "dont_notify" => Ok(Action::DontNotify), + "coalesce" => Ok(Action::Coalesce), + s => Err(E::unknown_variant( + &s, + &["notify", "dont_notify", "coalesce"], + )), + } + } + + /// Match the more complex set_tweaks action object as a key-value map + fn visit_map(self, mut map: A) -> Result + where + A: MapAccess<'de>, + { + let mut tweak_kind: Option = None; + let mut tweak_value: Option = None; + + // We loop over all entries in the map to find one with a "set_tweak" key to find + // which type of tweak is being set. + // Then we also try to find one with the "value" key if it exists. + while let Some((key, value)) = map.next_entry::<&str, JsonValue>()? { + match key { + "set_tweak" => { + let kind = match value.as_str() { + Some("sound") => TweakKind::Sound, + Some("highlight") => TweakKind::Highlight, + Some(s) => TweakKind::Custom(s.to_string()), + None => { + return Err(A::Error::invalid_type( + Unexpected::Other("non-string object"), + &"string", + )) + } + }; + tweak_kind = Some(kind); + } + "value" => { + tweak_value = Some(value); + } + _ => {} + } + } + + match tweak_kind { + Some(kind) => Ok(Action::SetTweak { + kind, + value: tweak_value, + }), + None => Err(A::Error::invalid_type( + Unexpected::Other("object without \"set_tweak\" key"), + &"valid \"set_tweak\" action object", + )), + } + } + } + + deserializer.deserialize_any(ActionVisitor) + } +} diff --git a/src/r0/push/delete_pushrule.rs b/src/r0/push/delete_pushrule.rs new file mode 100644 index 00000000..8062668f --- /dev/null +++ b/src/r0/push/delete_pushrule.rs @@ -0,0 +1,32 @@ +//! [DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-pushrules-scope-kind-ruleid) + +use ruma_api::ruma_api; + +use super::RuleKind; + +ruma_api! { + metadata { + description: "This endpoint removes the push rule defined in the path.", + method: DELETE, + name: "delete_pushrule", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to delete from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + } + + response {} +} diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs new file mode 100644 index 00000000..781dbcdd --- /dev/null +++ b/src/r0/push/get_notifications.rs @@ -0,0 +1,74 @@ +//! [GET /_matrix/client/r0/notifications](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-notifications) + +use js_int::UInt; +use ruma_api::{ruma_api, Outgoing}; +use ruma_events::{collections::all, EventResult}; +use ruma_identifiers::RoomId; +use serde::Serialize; + +use super::Action; + +ruma_api! { + metadata { + description: "Paginate through the list of events that the user has been, or would have been notified about.", + method: GET, + name: "get_notifications", + path: "/_matrix/client/r0/notifications", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Pagination token given to retrieve the next set of events. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub from: Option, + + /// Limit on the number of events to return in this request. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + + /// Allows basic filtering of events returned. Supply "highlight" to return only events where + /// the notification had the 'highlight' tweak set. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub only: Option + } + + response { + /// The token to supply in the from param of the next /notifications request in order + /// to request more events. If this is absent, there are no more results. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_token: Option, + + + /// The list of events that triggered notifications. + #[wrap_incoming(Notification)] + pub notifications: Vec, + } +} + +/// Represents a notification +#[derive(Clone, Debug, Serialize, Outgoing)] +pub struct Notification { + /// The actions to perform when the conditions for this rule are met. + pub actions: Vec, + + /// The event that triggered the notification. + #[wrap_incoming(with EventResult)] + pub event: all::Event, + + /// The profile tag of the rule that matched this event. + #[serde(skip_serializing_if = "Option::is_none")] + pub profile_tag: Option, + + /// Indicates whether the user has sent a read receipt indicating that they have read this message. + pub read: bool, + + /// The ID of the room in which the event was posted. + pub room_id: RoomId, + + /// The unix timestamp at which the event notification was sent, in milliseconds. + pub ts: UInt, +} diff --git a/src/r0/push/get_pushers.rs b/src/r0/push/get_pushers.rs new file mode 100644 index 00000000..b267c9ed --- /dev/null +++ b/src/r0/push/get_pushers.rs @@ -0,0 +1,23 @@ +//! [GET /_matrix/client/r0/pushers](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushers) + +use ruma_api::ruma_api; + +use super::Pusher; + +ruma_api! { + metadata { + description: "Gets all currently active pushers for the authenticated user.", + method: GET, + name: "get_pushers", + path: "/_matrix/client/r0/pushers", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// An array containing the current pushers for the user. + pub pushers: Vec + } +} diff --git a/src/r0/push/get_pushrule.rs b/src/r0/push/get_pushrule.rs new file mode 100644 index 00000000..c1377404 --- /dev/null +++ b/src/r0/push/get_pushrule.rs @@ -0,0 +1,36 @@ +//! [GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules-scope-kind-ruleid) + +use ruma_api::ruma_api; + +use super::{PushRule, RuleKind}; + +ruma_api! { + metadata { + description: "Retrieve a single specified push rule.", + method: GET, + name: "get_pushrule", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to fetch rules from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + } + + response { + /// The specific push rule. + #[ruma_api(body)] + pub rule: PushRule + } +} diff --git a/src/r0/push/get_pushrule_actions.rs b/src/r0/push/get_pushrule_actions.rs new file mode 100644 index 00000000..ca0ad899 --- /dev/null +++ b/src/r0/push/get_pushrule_actions.rs @@ -0,0 +1,35 @@ +//! [GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules-scope-kind-ruleid-actions) + +use ruma_api::ruma_api; + +use super::{Action, RuleKind}; + +ruma_api! { + metadata { + description: "This endpoint get the actions for the specified push rule.", + method: GET, + name: "get_pushrule_actions", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to fetch a rule from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + } + + response { + /// The actions to perform for this rule. + pub actions: Vec + } +} diff --git a/src/r0/push/get_pushrule_enabled.rs b/src/r0/push/get_pushrule_enabled.rs new file mode 100644 index 00000000..b0800888 --- /dev/null +++ b/src/r0/push/get_pushrule_enabled.rs @@ -0,0 +1,35 @@ +//! [GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules-scope-kind-ruleid-enabled) + +use ruma_api::ruma_api; + +use super::RuleKind; + +ruma_api! { + metadata { + description: "This endpoint gets whether the specified push rule is enabled.", + method: GET, + name: "get_pushrule_enabled", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to fetch a rule from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + } + + response { + /// Whether the push rule is enabled or not. + pub enabled: bool + } +} diff --git a/src/r0/push/get_pushrules_all.rs b/src/r0/push/get_pushrules_all.rs new file mode 100644 index 00000000..73273c25 --- /dev/null +++ b/src/r0/push/get_pushrules_all.rs @@ -0,0 +1,25 @@ +//! [GET /_matrix/client/r0/pushrules/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::{PushRule, RuleKind}; + +ruma_api! { + metadata { + description: "Retrieve all push rulesets for this user.", + method: GET, + name: "get_pushrules_all", + path: "/_matrix/client/r0/pushrules/", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// The global ruleset + pub global: HashMap> + } +} diff --git a/src/r0/push/get_pushrules_global_scope.rs b/src/r0/push/get_pushrules_global_scope.rs new file mode 100644 index 00000000..b8fdc2ff --- /dev/null +++ b/src/r0/push/get_pushrules_global_scope.rs @@ -0,0 +1,26 @@ +//! [GET /_matrix/client/r0/pushrules/global/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) + +use std::collections::HashMap; + +use ruma_api::ruma_api; + +use super::{PushRule, RuleKind}; + +ruma_api! { + metadata { + description: "Retrieve all push rulesets in the global scope for this user.", + method: GET, + name: "get_pushrules_global_scope", + path: "/_matrix/client/r0/pushrules/global/", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + /// The global ruleset. + #[ruma_api(body)] + pub global: HashMap>, + } +} diff --git a/src/r0/push/set_pusher.rs b/src/r0/push/set_pusher.rs new file mode 100644 index 00000000..53a48bda --- /dev/null +++ b/src/r0/push/set_pusher.rs @@ -0,0 +1,30 @@ +//! [POST /_matrix/client/r0/pushers/set](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-pushers-set) + +use ruma_api::ruma_api; + +use super::Pusher; + +ruma_api! { + metadata { + description: "This endpoint allows the creation, modification and deletion of pushers for this user ID.", + method: POST, + name: "set_pusher", + path: "/_matrix/client/r0/pushers/set", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The pusher to configure + #[serde(flatten)] + pub pusher: Pusher, + + /// Controls if another pusher with the same pushkey and app id should be created. + /// See the spec for details. + #[serde(default)] + pub append: bool + + } + + response {} +} diff --git a/src/r0/push/set_pushrule.rs b/src/r0/push/set_pushrule.rs new file mode 100644 index 00000000..acaf16a9 --- /dev/null +++ b/src/r0/push/set_pushrule.rs @@ -0,0 +1,52 @@ +//! [PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-pushrules-scope-kind-ruleid) + +use ruma_api::ruma_api; + +use super::{Action, PushCondition, RuleKind}; + +ruma_api! { + metadata { + description: "This endpoint allows the creation, modification and deletion of pushers for this user ID.", + method: PUT, + name: "set_pushrule", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The scope to set the rule in. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + + /// Use 'before' with a rule_id as its value to make the new rule the next-most important rule with respect to the given user defined rule. + #[ruma_api(query)] + pub before: Option, + + /// This makes the new rule the next-less important rule relative to the given user defined rule. + #[ruma_api(query)] + pub after: Option, + + /// The actions to perform when this rule is matched. + pub actions: Vec, + + /// The conditions that must hold true for an event in order for a rule to be applied to an event. A rule with no conditions always matches. + /// Only applicable to underride and override rules, empty Vec otherwise. + #[serde(default)] + pub conditions: Vec, + + /// The glob-style pattern to match against. Only applicable to content rules. + #[serde(skip_serializing_if = "Option::is_none")] + pub pattern: Option, + } + + response {} +} diff --git a/src/r0/push/set_pushrule_actions.rs b/src/r0/push/set_pushrule_actions.rs new file mode 100644 index 00000000..2b1a9be0 --- /dev/null +++ b/src/r0/push/set_pushrule_actions.rs @@ -0,0 +1,35 @@ +//! [PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-pushrules-scope-kind-ruleid-actions) + +use ruma_api::ruma_api; + +use super::{Action, RuleKind}; + +ruma_api! { + metadata { + description: "This endpoint allows clients to change the actions of a push rule. This can be used to change the actions of builtin rules.", + method: PUT, + name: "set_pushrule_actions", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to fetch a rule from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + + /// The actions to perform for this rule + pub actions: Vec + } + + response {} +} diff --git a/src/r0/push/set_pushrule_enabled.rs b/src/r0/push/set_pushrule_enabled.rs new file mode 100644 index 00000000..68638a83 --- /dev/null +++ b/src/r0/push/set_pushrule_enabled.rs @@ -0,0 +1,35 @@ +//! [PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-pushrules-scope-kind-ruleid-enabled) + +use ruma_api::ruma_api; + +use super::RuleKind; + +ruma_api! { + metadata { + description: "This endpoint allows clients to enable or disable the specified push rule.", + method: PUT, + name: "set_pushrule_enabled", + path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The scope to fetch a rule from. 'global' to specify global rules. + #[ruma_api(path)] + pub scope: String, + + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, + + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: String, + + /// Whether the push rule is enabled or not. + pub enabled: bool + } + + response {} +} From 8b752bba8575a89e886eee53b7d9707056cba8f8 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Sat, 18 Jan 2020 14:54:44 -0600 Subject: [PATCH 193/350] Add room upgrade endpoint. --- src/r0/room.rs | 1 + src/r0/room/upgrade_room.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/r0/room/upgrade_room.rs diff --git a/src/r0/room.rs b/src/r0/room.rs index c0ab2146..52853f4e 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -3,6 +3,7 @@ pub mod create_room; pub mod get_room_event; pub mod report_content; +pub mod upgrade_room; use serde::{Deserialize, Serialize}; diff --git a/src/r0/room/upgrade_room.rs b/src/r0/room/upgrade_room.rs new file mode 100644 index 00000000..85ab9ee3 --- /dev/null +++ b/src/r0/room/upgrade_room.rs @@ -0,0 +1,28 @@ +//! [POST /_matrix/client/r0/rooms/{roomId}/upgrade](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-upgrade) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +ruma_api! { + metadata { + description: "Upgrades a room to a particular version.", + method: POST, + name: "upgrade_room", + path: "/_matrix/client/r0/rooms/:room_id/upgrade", + rate_limited: false, + requires_authentication: true, + } + + request { + /// ID of the room to be upgraded. + #[ruma_api(path)] + room_id: RoomId, + /// New version for the room. + new_version: String, + } + + response { + /// ID of the new room. + replacement_room: RoomId, + } +} From b4692ec2a21c27c21bf78f6260d47daedf7311f6 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Sat, 18 Jan 2020 14:56:35 -0600 Subject: [PATCH 194/350] Update changelog for room upgrade endpoint. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 612050cb..36431c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ Improvements: * Add `r0::account::delete_3pid` * Add `r0::account::unbind_3pid` * Add `r0::push` endpoints +* Add `r0::room::upgrade_room` (introduced upstream in 0.5.0) # 0.5.0 From 01dd745a06b110105d2f0c3e429c2706898a9164 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 21 Apr 2019 01:07:49 +0200 Subject: [PATCH 195/350] Update login endpoint to r0.6.0 --- src/r0/session/get_login_types.rs | 14 ++- src/r0/session/login.rs | 184 +++++++++++++++++++++++++---- src/r0/session/login/user_serde.rs | 64 ++++++++++ src/r0/thirdparty.rs | 2 +- 4 files changed, 237 insertions(+), 27 deletions(-) create mode 100644 src/r0/session/login/user_serde.rs diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs index 7f0d0d4d..ba891343 100644 --- a/src/r0/session/get_login_types.rs +++ b/src/r0/session/get_login_types.rs @@ -3,8 +3,6 @@ use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; -use super::login::LoginType; - ruma_api! { metadata { description: "Gets the homeserver's supported login types to authenticate users. Clients should pick one of these and supply it as the type when logging in.", @@ -30,3 +28,15 @@ pub struct LoginFlow { #[serde(rename = "type")] pub login_type: LoginType, } + +/// The authentication mechanism. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(tag = "type")] +pub enum LoginType { + /// A password is supplied to authenticate. + #[serde(rename = "m.login.password")] + Password, + /// Token-based login. + #[serde(rename = "m.login.token")] + Token, +} diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 6e4a4b17..31e2ed99 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,9 +1,10 @@ -//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) +//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login) -use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +use crate::r0::thirdparty::Medium; ruma_api! { metadata { @@ -16,47 +17,182 @@ ruma_api! { } request { - /// The user's password. - pub password: String, - /// When logging in using a third party identifier, the medium of the identifier. - #[serde(skip_serializing_if = "Option::is_none")] - pub medium: Option, + /// Identification information for the user. + #[serde(flatten)] + pub user: UserInfo, /// The authentication mechanism. - #[serde(rename = "type")] - pub login_type: LoginType, - /// The fully qualified user ID or just local part of the user ID. - pub user: String, - /// Third party identifier for the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub address: Option, + #[serde(flatten)] + pub login_info: LoginInfo, /// ID of the client device #[serde(skip_serializing_if = "Option::is_none")] pub device_id: Option, + /// A display name to assign to the newly-created device. Ignored if device_id corresponds + /// to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option, } response { + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, /// An access token for the account. pub access_token: String, /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, - /// A refresh token may be exchanged for a new access token using the /tokenrefresh API - /// endpoint. + /// + /// Deprecated: Clients should extract the server_name from user_id (by splitting at the + /// first colon) if they require it. #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, + pub home_server: Option, /// ID of the logged-in device. /// /// Will be the same as the corresponging parameter in the request, if one was /// specified. pub device_id: String, + /// Client configuration provided by the server. + /// + /// If present, clients SHOULD use the provided object to reconfigure themselves. + pub well_known: Option, } } +/// Identification information for the user. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum UserInfo { + /// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier' + /// field, recommended since r0.4.0). + MatrixId(String), + /// Third party identifier (as part of the 'identifier' field, recommended since r0.4.0). + ThirdPartyId { + /// Third party identifier for the user. + address: String, + /// The medium of the identifier. + medium: Medium, + }, + /// Same as third-party identification with medium == msisdn, but with a non-canonicalised + /// phone number. + PhoneNumber { + /// The country that the phone number is from. + country: String, + /// The phone number. + phone: String, + }, +} + /// The authentication mechanism. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum LoginType { +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(tag = "type")] +pub enum LoginInfo { /// A password is supplied to authenticate. #[serde(rename = "m.login.password")] - Password, + Password { + /// The password. + password: String, + }, + /// Token-based login. + #[serde(rename = "m.login.token")] + Token { + /// The token. + token: String, + }, +} + +/// Client configuration provided by the server. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct DiscoveryInfo { + #[serde(rename = "m.homeserver")] + homeserver: HomeserverInfo, + #[serde(rename = "m.identity_server")] + identity_server: Option, +} + +/// Information about the homeserver to connect to. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct HomeserverInfo { + /// The base URL for the homeserver for client-server connections. + base_url: String, +} + +/// Information about the identity server to connect to. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct IdentityServerInfo { + /// The base URL for the identity server for client-server connections. + base_url: String, +} + +mod user_serde; + +impl Serialize for UserInfo { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + user_serde::UserInfo::from(self).serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for UserInfo { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + user_serde::UserInfo::deserialize(deserializer).map(Into::into) + } +} + +#[cfg(test)] +mod tests { + use serde_json; + + use super::{LoginInfo, UserInfo}; + + #[test] + fn deserialize_login_type() { + assert_eq!( + serde_json::from_str::( + r#" + { + "type": "m.login.password", + "password": "ilovebananas" + } + "#, + ) + .unwrap(), + LoginInfo::Password { + password: "ilovebananas".into() + } + ); + + assert_eq!( + serde_json::from_str::( + r#" + { + "type": "m.login.token", + "token": "1234567890abcdef" + } + "#, + ) + .unwrap(), + LoginInfo::Token { + token: "1234567890abcdef".into() + } + ); + } + + #[test] + fn deserialize_user() { + assert_eq!( + serde_json::from_str::( + r#" + { + "identifier": { + "type": "m.id.user", + "user": "cheeky_monkey" + } + } + "#, + ) + .unwrap(), + UserInfo::MatrixId("cheeky_monkey".into()) + ); + } } diff --git a/src/r0/session/login/user_serde.rs b/src/r0/session/login/user_serde.rs new file mode 100644 index 00000000..17202ce8 --- /dev/null +++ b/src/r0/session/login/user_serde.rs @@ -0,0 +1,64 @@ +//! Helper module for the Serialize / Deserialize impl's for the User struct +//! in the parent module. + +use serde::{Deserialize, Serialize}; + +use super::Medium; + +// The following three structs could just be used in place of the one in the parent module, but +// that one is arguably much easier to deal with. +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct UserInfo<'a> { + #[serde(borrow)] + identifier: UserIdentifier<'a>, +} + +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(tag = "type")] +pub enum UserIdentifier<'a> { + #[serde(rename = "m.id.user")] + MatrixId { user: &'a str }, + #[serde(rename = "m.id.thirdparty")] + ThirdPartyId { medium: Medium, address: &'a str }, + #[serde(rename = "m.id.phone")] + PhoneNumber { country: &'a str, phone: &'a str }, +} + +impl<'a> From<&'a super::UserInfo> for UserInfo<'a> { + fn from(su: &'a super::UserInfo) -> Self { + use super::UserInfo::*; + + match su { + MatrixId(user) => UserInfo { + identifier: UserIdentifier::MatrixId { user }, + }, + ThirdPartyId { address, medium } => UserInfo { + identifier: UserIdentifier::ThirdPartyId { + address, + medium: *medium, + }, + }, + PhoneNumber { country, phone } => UserInfo { + identifier: UserIdentifier::PhoneNumber { country, phone }, + }, + } + } +} + +impl Into for UserInfo<'_> { + fn into(self) -> super::UserInfo { + use super::UserInfo::*; + + match self.identifier { + UserIdentifier::MatrixId { user } => MatrixId(user.to_owned()), + UserIdentifier::ThirdPartyId { address, medium } => ThirdPartyId { + address: address.to_owned(), + medium: medium.to_owned(), + }, + UserIdentifier::PhoneNumber { country, phone } => PhoneNumber { + country: country.to_owned(), + phone: phone.to_owned(), + }, + } + } +} diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index 82b1012d..ad0796a9 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -74,7 +74,7 @@ pub struct User { } /// The medium of a third party identifier. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] #[serde(rename_all = "lowercase")] pub enum Medium { /// Email address identifier From 1e88e3f90c9c863dc0744ea3153ea3b213ea36d7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 Feb 2020 21:28:27 +0100 Subject: [PATCH 196/350] Remove redundant import --- src/r0/room/get_room_event.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs index 8fadde7b..78b4593e 100644 --- a/src/r0/room/get_room_event.rs +++ b/src/r0/room/get_room_event.rs @@ -3,7 +3,6 @@ use ruma_api::ruma_api; use ruma_events::{collections::all, EventResult}; use ruma_identifiers::{EventId, RoomId}; -use serde::Deserialize; ruma_api! { metadata { From 604795f99454bf178c3209d6bc16ed220935a622 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 Feb 2020 22:28:34 +0100 Subject: [PATCH 197/350] Update dependencies, changelog; bump version --- CHANGELOG.md | 7 +++++-- Cargo.toml | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36431c69..1283cfb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # [unreleased] +# 0.6.0 + Breaking changes: -* Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in 0.5.0) +* Update ruma-api to 0.13.0 +* Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in r0.5.0) * Refactor `r0::send` endpoints and remove module: * Move `r0::send::send_message_event` to `r0::message::create_message_event` * Move `r0::send::send_state_event_for_empty_key` to `r0::state:create_state_event_for_empty_key` @@ -38,7 +41,7 @@ Improvements: * Add `r0::account::delete_3pid` * Add `r0::account::unbind_3pid` * Add `r0::push` endpoints -* Add `r0::room::upgrade_room` (introduced upstream in 0.5.0) +* Add `r0::room::upgrade_room` (introduced upstream in r0.5.0) # 0.5.0 diff --git a/Cargo.toml b/Cargo.toml index d7da2448..67eb4225 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.12.1" +ruma-api = "0.13.0" ruma-events = "0.15.1" -ruma-identifiers = "0.14.0" -serde = { version = "1.0.103", features = ["derive"] } -serde_json = "1.0.42" -url = { version = "2.1.0", features = ["serde"] } +ruma-identifiers = "0.14.1" +serde = { version = "1.0.104", features = ["derive"] } +serde_json = "1.0.47" +url = { version = "2.1.1", features = ["serde"] } From 16de378bb25dbd81c4179a799977e0011ec8d9f1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 Feb 2020 22:39:37 +0100 Subject: [PATCH 198/350] Bump MSRV --- .travis.yml | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03e1dca1..5ab43695 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: "rust" cache: "cargo" rust: - - 1.39.0 + - 1.40.0 - stable - beta - nightly diff --git a/CHANGELOG.md b/CHANGELOG.md index 1283cfb7..4fc9a730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Breaking changes: * Update ruma-api to 0.13.0 +* Our Minimum Supported Rust Version is now 1.40.0 * Remove presence list endpoints `r0::presence::{get_subscribed_presences, update_presence_subscriptions}` (removed in r0.5.0) * Refactor `r0::send` endpoints and remove module: * Move `r0::send::send_message_event` to `r0::message::create_message_event` From fc2d6f354a22b91e0ae506860486f7f9df47ddf5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 Feb 2020 23:07:32 +0100 Subject: [PATCH 199/350] Actually bump the version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 67eb4225..f8a89317 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.5.0" +version = "0.6.0" edition = "2018" [dependencies] From 45b64aabf5298d98a25e2d0f4dfea67e14d71963 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 9 Feb 2020 21:20:43 +0100 Subject: [PATCH 200/350] Remove outdated parts from comments --- src/r0/session/login.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 31e2ed99..cfd045d2 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -59,9 +59,9 @@ ruma_api! { #[derive(Clone, Debug, PartialEq, Eq)] pub enum UserInfo { /// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier' - /// field, recommended since r0.4.0). + /// field). MatrixId(String), - /// Third party identifier (as part of the 'identifier' field, recommended since r0.4.0). + /// Third party identifier (as part of the 'identifier' field). ThirdPartyId { /// Third party identifier for the user. address: String, From 1c2ab9e7686d6deb054d1fd84c0a96a318b0a157 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 13 Feb 2020 23:12:51 +0000 Subject: [PATCH 201/350] Fix r0::session::get_login_types::Response The previous version was expecting one level of nesting too many, i.e.: {"type": {"type": "m.login.password"}} This is a breaking change, so bump the version number too. --- CHANGELOG.md | 4 ++++ src/r0/session/get_login_types.rs | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc9a730..f13b2663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Breaking changes: + +* Fix `r0::session::get_login_types` + # 0.6.0 Breaking changes: diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs index ba891343..764a3b25 100644 --- a/src/r0/session/get_login_types.rs +++ b/src/r0/session/get_login_types.rs @@ -17,19 +17,11 @@ ruma_api! { response { /// The homeserver's supported login types. - pub flows: Vec + pub flows: Vec } } -/// A supported login type in a homeserver -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub struct LoginFlow { - /// The login type. - #[serde(rename = "type")] - pub login_type: LoginType, -} - -/// The authentication mechanism. +/// An authentication mechanism. #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] #[serde(tag = "type")] pub enum LoginType { @@ -40,3 +32,16 @@ pub enum LoginType { #[serde(rename = "m.login.token")] Token, } + +#[cfg(test)] +mod tests { + use super::LoginType; + + #[test] + fn deserialize_login_type() { + assert_eq!( + serde_json::from_str::(r#" {"type": "m.login.password"} "#).unwrap(), + LoginType::Password, + ); + } +} From dffe376aeb2a71b15d5732c8c2835556d3e3abf4 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sun, 16 Feb 2020 13:00:54 +0100 Subject: [PATCH 202/350] feat: add MatrixError struct --- Cargo.toml | 1 + src/error.rs | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 150 insertions(+) create mode 100644 src/error.rs diff --git a/Cargo.toml b/Cargo.toml index f8a89317..349f9759 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.47" url = { version = "2.1.1", features = ["serde"] } +http = "0.2.0" diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 00000000..b7569d4d --- /dev/null +++ b/src/error.rs @@ -0,0 +1,148 @@ +//! Errors that can be sent from the homeserver. + +use serde::{Deserialize, Serialize}; + +/// An enum for the error kind. Items may contain additional information. +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[serde(tag = "errcode")] +pub enum ErrorKind { + /// M_FORBIDDEN + #[serde(rename = "M_FORBIDDEN")] + Forbidden, + /// M_UNKNOWN_TOKEN + #[serde(rename = "M_UNKNOWN_TOKEN")] + UnknownToken, + /// M_MISSING_TOKEN + #[serde(rename = "M_MISSING_TOKEN")] + MissingToken, + /// M_BAD_JSON + #[serde(rename = "M_BAD_JSON")] + BadJson, + /// M_NOT_JSON + #[serde(rename = "M_NOT_JSON")] + NotJson, + /// M_NOT_FOUND + #[serde(rename = "M_NOT_FOUND")] + NotFound, + /// M_LIMIT_EXCEEDED + #[serde(rename = "M_LIMIT_EXCEEDED")] + LimitExceeded, + /// M_UNKNOWN + #[serde(rename = "M_UNKNOWN")] + Unknown, + /// M_UNRECOGNIZED + #[serde(rename = "M_UNRECOGNIZED")] + Unrecognized, + /// M_UNAUTHORIZED + #[serde(rename = "M_UNAUTHORIZED")] + Unauthorized, + /// M_USER_IN_USE + #[serde(rename = "M_USER_IN_USE")] + UserInUse, + /// M_INVALID_USERNAME + #[serde(rename = "M_INVALID_USERNAME")] + InvalidUsername, + /// M_ROOM_IN_USE + #[serde(rename = "M_ROOM_IN_USE")] + RoomInUse, + /// M_INVALID_ROOM_STATE + #[serde(rename = "M_INVALID_ROOM_STATE")] + InvalidRoomState, + /// M_THREEPID_IN_USE + #[serde(rename = "M_THREEPID_IN_USE")] + ThreepidInUse, + /// M_THREEPID_NOT_FOUND + #[serde(rename = "M_THREEPID_NOT_FOUND")] + ThreepidNotFound, + /// M_THREEPID_AUTH_FAILED + #[serde(rename = "M_THREEPID_AUTH_FAILED")] + ThreepidAuthFailed, + /// M_THREEPID_DENIED + #[serde(rename = "M_THREEPID_DENIED")] + ThreepidDenied, + /// M_SERVER_NOT_TRUSTED + #[serde(rename = "M_SERVER_NOT_TRUSTED")] + ServerNotTrusted, + /// M_UNSUPPORTED_ROOM_VERSION + #[serde(rename = "M_UNSUPPORTED_ROOM_VERSION")] + UnsupportedRoomVersion, + /// M_INCOMPATIBLE_ROOM_VERSION + #[serde(rename = "M_INCOMPATIBLE_ROOM_VERSION")] + IncompatibleRoomVersion, + /// M_BAD_STATE + #[serde(rename = "M_BAD_STATE")] + BadState, + /// M_GUEST_ACCESS_FORBIDDEN + #[serde(rename = "M_GUEST_ACCESS_FORBIDDEN")] + GuestAccessForbidden, + /// M_CAPTCHA_NEEDED + #[serde(rename = "M_CAPTCHA_NEEDED")] + CaptchaNeeded, + /// M_CAPTCHA_INVALID + #[serde(rename = "M_CAPTCHA_INVALID")] + CaptchaInvalid, + /// M_MISSING_PARAM + #[serde(rename = "M_MISSING_PARAM")] + MissingParam, + /// M_INVALID_PARAM + #[serde(rename = "M_INVALID_PARAM")] + InvalidParam, + /// M_TOO_LARGE + #[serde(rename = "M_TOO_LARGE")] + TooLarge, + /// M_EXCLUSIVE + #[serde(rename = "M_EXCLUSIVE")] + Exclusive, +} + +/// A Matrix Error without a status code +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ErrorBody { + /// A value which can be used to handle an error message + #[serde(flatten)] + pub kind: ErrorKind, + /// A human-readable error message, usually a sentence explaining what went wrong. + #[serde(rename = "error")] + pub message: String, +} + +/// A Matrix Error +#[derive(Debug, Clone)] +pub struct Error { + /// A value which can be used to handle an error message + pub kind: ErrorKind, + /// A human-readable error message, usually a sentence explaining what went wrong. + pub message: String, + /// The http status code + pub status_code: http::StatusCode, +} + +impl From for ErrorBody { + fn from(error: Error) -> Self { + Self { + kind: error.kind, + message: error.message, + } + } +} + +impl ErrorBody { + /// Convert the ErrorBody into an Error by adding the http status code. + pub fn into_error(self, status_code: http::StatusCode) -> Error { + Error { + kind: self.kind, + message: self.message, + status_code, + } + } +} + +impl From for http::Response> { + fn from(error: Error) -> http::Response> { + http::Response::builder() + .header(http::header::CONTENT_TYPE, "application/json") + .status(error.status_code) + .body(serde_json::to_vec(&ErrorBody::from(error)).unwrap()) + .unwrap() + } +} diff --git a/src/lib.rs b/src/lib.rs index eb2423c6..4b08448a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,5 +8,6 @@ missing_docs )] +pub mod error; pub mod r0; pub mod unversioned; From a63e73a32dd535025e328cf59a9bde7274c3814d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 17 Feb 2020 01:12:28 +0100 Subject: [PATCH 203/350] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f13b2663..be170e04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Improvements: + +* Add an `Error` type that represents the well-known errors in the client-server API + Breaking changes: * Fix `r0::session::get_login_types` From 0139ebc41a425308e90a8416b57ae2c956d0e0b2 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Tue, 18 Feb 2020 12:15:32 -0600 Subject: [PATCH 204/350] Add OpenID request token endpoint --- CHANGELOG.md | 1 + src/r0/account.rs | 1 + src/r0/account/request_openid_token.rs | 41 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/r0/account/request_openid_token.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index be170e04..1826ebd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Improvements: * Add an `Error` type that represents the well-known errors in the client-server API +* Add OpenID token request endpoint. Breaking changes: diff --git a/src/r0/account.rs b/src/r0/account.rs index b16ab28f..bda1ecb0 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -8,6 +8,7 @@ pub mod get_username_availability; pub mod register; pub mod request_3pid_management_token_via_email; pub mod request_3pid_management_token_via_msisdn; +pub mod request_openid_token; pub mod request_password_change_token_via_email; pub mod request_password_change_token_via_msisdn; pub mod request_registration_token_via_email; diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs new file mode 100644 index 00000000..a62f7b09 --- /dev/null +++ b/src/r0/account/request_openid_token.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/user/{userId}/openid/request_token](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-userid-openid-request-token) + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::UserId; +use serde::{Deserialize, Serialize}; + +ruma_api! { + metadata { + description: "Request an OpenID 1.0 token to verify identity with a third party.", + name: "request_openid_token", + method: POST, + path: "/_matrix/client/r0/user/:user_id/openid/request_token", + rate_limited: true, + requires_authentication: true, + } + + request { + /// User ID of authenticated user. + #[ruma_api(path)] + user_id: UserId, + } + + response { + /// Access token for verifying user's identity. + access_token: String, + /// Access token type. + token_type: TokenType, + /// Homeserver domain for verification of user's identity. + matrix_server_name: String, + /// Seconds until token expiration. + expires_in: UInt, + } +} + +/// Access token types. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum TokenType { + /// Bearer token type + Bearer, +} From 6d8a6e8b2e973849e0d562ed7719a3fce21a9f3a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 17 Feb 2020 10:53:35 +0100 Subject: [PATCH 205/350] Sort dependencies in Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 349f9759..c5e42a88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ version = "0.6.0" edition = "2018" [dependencies] +http = "0.2.0" js_int = { version = "0.1.2", features = ["serde"] } ruma-api = "0.13.0" ruma-events = "0.15.1" @@ -20,4 +21,3 @@ ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.47" url = { version = "2.1.1", features = ["serde"] } -http = "0.2.0" From fc0d8ee8e725b351c1902dd7d0f92a8cc95b5048 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 17 Feb 2020 20:45:46 -0600 Subject: [PATCH 206/350] Add send-to-device endpoint --- CHANGELOG.md | 1 + src/r0.rs | 1 + src/r0/client_exchange.rs | 71 +++++++++++++++++++ .../client_exchange/send_event_to_device.rs | 36 ++++++++++ 4 files changed, 109 insertions(+) create mode 100644 src/r0/client_exchange.rs create mode 100644 src/r0/client_exchange/send_event_to_device.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1826ebd9..15cb638e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Improvements: * Add an `Error` type that represents the well-known errors in the client-server API * Add OpenID token request endpoint. +* Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) Breaking changes: diff --git a/src/r0.rs b/src/r0.rs index 79123f05..9ed2405f 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -4,6 +4,7 @@ pub mod account; pub mod alias; pub mod appservice; pub mod capabilities; +pub mod client_exchange; pub mod config; pub mod contact; pub mod context; diff --git a/src/r0/client_exchange.rs b/src/r0/client_exchange.rs new file mode 100644 index 00000000..033d0fd1 --- /dev/null +++ b/src/r0/client_exchange.rs @@ -0,0 +1,71 @@ +//! Endpoints for client devices to exchange information not persisted in room DAG. + +use std::{ + convert::TryFrom, + fmt::{Display, Formatter, Result as FmtResult}, +}; + +use ruma_identifiers::DeviceId; +use serde::{ + de::{self, Unexpected}, + Deserialize, Deserializer, Serialize, Serializer, +}; + +pub mod send_event_to_device; +/// Represents one or all of a user's devices. +#[derive(Clone, Debug, Hash, PartialEq, Eq)] +pub enum DeviceIdOrAllDevices { + /// Represents a device Id for one of a user's devices. + DeviceId(DeviceId), + /// Represents all devices for a user. + AllDevices, +} + +impl Display for DeviceIdOrAllDevices { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + match self { + DeviceIdOrAllDevices::DeviceId(device_id) => write!(f, "{}", device_id.to_string()), + DeviceIdOrAllDevices::AllDevices => write!(f, "*"), + } + } +} + +impl TryFrom<&str> for DeviceIdOrAllDevices { + type Error = &'static str; + fn try_from(device_id_or_all_devices: &str) -> Result { + if device_id_or_all_devices.is_empty() { + Err("Device identifier cannot be empty") + } else if "*" == device_id_or_all_devices { + Ok(DeviceIdOrAllDevices::AllDevices) + } else { + Ok(DeviceIdOrAllDevices::DeviceId( + device_id_or_all_devices.to_string(), + )) + } + } +} + +impl Serialize for DeviceIdOrAllDevices { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::DeviceId(ref device_id) => serializer.serialize_str(&device_id), + Self::AllDevices => serializer.serialize_str("*"), + } + } +} + +impl<'de> Deserialize<'de> for DeviceIdOrAllDevices { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value = &String::deserialize(deserializer)?; + + DeviceIdOrAllDevices::try_from(&value[..]).map_err(|_| { + de::Error::invalid_value(Unexpected::Str(&value), &"a valid device identifier or '*'") + }) + } +} diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs new file mode 100644 index 00000000..36aefd36 --- /dev/null +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -0,0 +1,36 @@ +//! [PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-sendtodevice-eventtype-txnid) + +use std::collections::HashMap; + +use ruma_api::ruma_api; +use ruma_events::{collections::all, EventResult}; +use ruma_identifiers::UserId; + +use super::DeviceIdOrAllDevices; + +ruma_api! { + metadata { + description: "Send an event to a device or devices.", + method: PUT, + name: "send_event_to_device", + path: "/_matrix/client/r0/sendToDevice/:event_type/:txn_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Type of event being sent to each device. + #[ruma_api(path)] + event_type: String, + /// A request identifier unique to the access token used to send the request. + #[ruma_api(path)] + txn_id: String, + /// A map of users to devices to a message event to be sent to the user's + /// device. Individual message events can be sent to devices, but all + /// events must be of the same type. + #[wrap_incoming(all::Event with EventResult)] + messages: HashMap> + } + + response {} +} From a7ca7b1e8dde77e76f24f62c86229316f1c5f387 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 18 Feb 2020 20:51:10 +0100 Subject: [PATCH 207/350] Remove redundant import --- src/r0/session/login.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index cfd045d2..239144cf 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -141,8 +141,6 @@ impl<'de> Deserialize<'de> for UserInfo { #[cfg(test)] mod tests { - use serde_json; - use super::{LoginInfo, UserInfo}; #[test] From 8e9a6ffededb89bc87c6ac5d067d8d4249eabf04 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 18 Feb 2020 21:26:41 +0100 Subject: [PATCH 208/350] Update ruma-api to 0.14.0 --- CHANGELOG.md | 1 + Cargo.toml | 3 ++- src/r0/push.rs | 24 ++++++++++++------------ src/r0/receipt/create_receipt.rs | 18 +++++++++--------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15cb638e..8679fff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Improvements: Breaking changes: +* Update ruma-api to 0.14.0 * Fix `r0::session::get_login_types` # 0.6.0 diff --git a/Cargo.toml b/Cargo.toml index c5e42a88..5ae8d212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,10 @@ edition = "2018" [dependencies] http = "0.2.0" js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.13.0" +ruma-api = "0.14.0" ruma-events = "0.15.1" ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.47" +strum = { version = "0.17.1", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } diff --git a/src/r0/push.rs b/src/r0/push.rs index 6796d9ec..d1856ff3 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -1,6 +1,9 @@ //! Endpoints for push notifications. -use std::fmt::{Display, Formatter, Result as FmtResult}; +use std::{ + convert::TryFrom, + fmt::{Formatter, Result as FmtResult}, +}; use serde::{ de::{Error as SerdeError, MapAccess, Unexpected, Visitor}, @@ -8,6 +11,7 @@ use serde::{ Deserialize, Deserializer, Serialize, Serializer, }; use serde_json::Value as JsonValue; +use strum::{Display, EnumString}; pub mod delete_pushrule; pub mod get_notifications; @@ -23,8 +27,9 @@ pub mod set_pushrule_actions; pub mod set_pushrule_enabled; /// The kinds of push rules that are available -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Display, EnumString)] #[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] pub enum RuleKind { /// User-configured rules that override all other kinds Override, @@ -42,16 +47,11 @@ pub enum RuleKind { Content, } -impl Display for RuleKind { - fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - let s = match self { - RuleKind::Override => "override", - RuleKind::Underride => "underride", - RuleKind::Sender => "sender", - RuleKind::Room => "room", - RuleKind::Content => "content", - }; - write!(f, "{}", s) +impl TryFrom<&'_ str> for RuleKind { + type Error = strum::ParseError; + + fn try_from(s: &str) -> Result { + s.parse() } } diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 02915540..d2e75699 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -1,10 +1,10 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) -use std::fmt::{Display, Error as FmtError, Formatter}; +use std::convert::TryFrom; use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; +use strum::{Display, EnumString}; ruma_api! { metadata { @@ -32,17 +32,17 @@ ruma_api! { } /// The type of receipt. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Display, EnumString)] pub enum ReceiptType { /// m.read - #[serde(rename = "m.read")] + #[strum(serialize = "m.read")] Read, } -impl Display for ReceiptType { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match *self { - ReceiptType::Read => write!(f, "m.read"), - } +impl TryFrom<&'_ str> for ReceiptType { + type Error = strum::ParseError; + + fn try_from(s: &str) -> Result { + s.parse() } } From 411c6e18b46f3d0d306c433a96dc675c7e21a3f3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 19 Feb 2020 00:49:46 +0100 Subject: [PATCH 209/350] Update dependencies --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ae8d212..a80ad4a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ edition = "2018" http = "0.2.0" js_int = { version = "0.1.2", features = ["serde"] } ruma-api = "0.14.0" -ruma-events = "0.15.1" +ruma-events = "0.16.0" ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } -serde_json = "1.0.47" +serde_json = "1.0.48" strum = { version = "0.17.1", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } From 959e10fd15ab80fa6ef58724abe78113fc3cb244 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Wed, 19 Feb 2020 04:00:12 -0600 Subject: [PATCH 210/350] Add client config retrieval endpoints --- CHANGELOG.md | 1 + src/r0/config.rs | 2 ++ src/r0/config/get_global_account_data.rs | 32 ++++++++++++++++++++++ src/r0/config/get_room_account_data.rs | 35 ++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/r0/config/get_global_account_data.rs create mode 100644 src/r0/config/get_room_account_data.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8679fff3..65349774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Improvements: * Add an `Error` type that represents the well-known errors in the client-server API * Add OpenID token request endpoint. * Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) +* Add endpoints to retrieve account_data (introduced in r0.5.0) Breaking changes: diff --git a/src/r0/config.rs b/src/r0/config.rs index 82b2df26..425c22ef 100644 --- a/src/r0/config.rs +++ b/src/r0/config.rs @@ -1,4 +1,6 @@ //! Endpoints for client configuration. +pub mod get_global_account_data; +pub mod get_room_account_data; pub mod set_global_account_data; pub mod set_room_account_data; diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs new file mode 100644 index 00000000..342fa1c0 --- /dev/null +++ b/src/r0/config/get_global_account_data.rs @@ -0,0 +1,32 @@ +//! [GET /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-account-data-type) + +use ruma_api::ruma_api; +use ruma_events::{collections::only, EventResult}; +use ruma_identifiers::UserId; + +ruma_api! { + metadata { + description: "Gets global account data for a user.", + name: "get_global_account_data", + method: GET, + path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, + } + + request { + /// User ID of user for whom to retrieve data. + #[ruma_api(path)] + user_id: UserId, + /// Type of data to retrieve. + #[ruma_api(path)] + event_type: String, + } + + response { + /// Account data content for the given type. + #[ruma_api(body)] + #[wrap_incoming(with EventResult)] + account_data: only::Event, + } +} diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs new file mode 100644 index 00000000..f2ea38e9 --- /dev/null +++ b/src/r0/config/get_room_account_data.rs @@ -0,0 +1,35 @@ +//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-rooms-roomid-account-data-type) + +use ruma_api::ruma_api; +use ruma_events::{collections::only, EventResult}; +use ruma_identifiers::{RoomId, UserId}; + +ruma_api! { + metadata { + description: "Gets account data room for a user for a given room", + name: "get_room_account_data", + method: GET, + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", + rate_limited: false, + requires_authentication: true, + } + + request { + /// User ID of user for whom to retrieve data. + #[ruma_api(path)] + user_id: UserId, + /// Room ID for which to retrieve data. + #[ruma_api(path)] + room_id: RoomId, + /// Type of data to retrieve. + #[ruma_api(path)] + event_type: String, + } + + response { + /// Account data content for the given type. + #[ruma_api(body)] + #[wrap_incoming(with EventResult)] + account_data: only::Event, + } +} From bb52edf1e0cf0f2232d725af7afb69fb1ebba7e8 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 19 Feb 2020 12:55:22 -0600 Subject: [PATCH 211/350] Add allow_remote parameter to content fetching endpoint. Fixes #92. --- src/r0/media/get_content.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 3374729a..338ffb50 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -21,6 +21,10 @@ ruma_api! { /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] pub server_name: String, + /// Whether to fetch media deemed remote. + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + pub allow_remote: Option, } response { From ed508c043e576cd2789254729b765e00dc639420 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 19 Feb 2020 13:21:34 -0600 Subject: [PATCH 212/350] Add missing media endpoints Fixes #73. --- src/r0/media.rs | 2 ++ src/r0/media/get_content.rs | 4 +-- src/r0/media/get_content_as_filename.rs | 42 +++++++++++++++++++++++++ src/r0/media/get_media_config.rs | 23 ++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/r0/media/get_content_as_filename.rs create mode 100644 src/r0/media/get_media_config.rs diff --git a/src/r0/media.rs b/src/r0/media.rs index 6fc18507..8eb4184c 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -2,4 +2,6 @@ pub mod create_content; pub mod get_content; +pub mod get_content_as_filename; pub mod get_content_thumbnail; +pub mod get_media_config; diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 338ffb50..accb0169 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -1,6 +1,4 @@ -//! Endpoints for the media repository. - -//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-download-servername-mediaid) +//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-media-r0-download-servername-mediaid) use ruma_api::ruma_api; diff --git a/src/r0/media/get_content_as_filename.rs b/src/r0/media/get_content_as_filename.rs new file mode 100644 index 00000000..140301ea --- /dev/null +++ b/src/r0/media/get_content_as_filename.rs @@ -0,0 +1,42 @@ +//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-download-servername-mediaid-filename) + +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Retrieve content from the media store, specifying a filename to return.", + method: GET, + name: "get_media_content_as_filename", + path: "/_matrix/media/r0/download/:server_name/:media_id/:filename", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: String, + /// The filename to return in the `Content-Disposition` header. + #[ruma_api(path)] + pub filename: String, + /// Whether to fetch media deemed remote. + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + pub allow_remote: Option, + } + + response { + /// The content that was previously uploaded. + #[ruma_api(raw_body)] + pub file: Vec, + /// The content type of the file that was previously uploaded. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, + /// The name of the file that was previously uploaded, if set. + #[ruma_api(header = CONTENT_DISPOSITION)] + pub content_disposition: String, + } +} diff --git a/src/r0/media/get_media_config.rs b/src/r0/media/get_media_config.rs new file mode 100644 index 00000000..2cc2f086 --- /dev/null +++ b/src/r0/media/get_media_config.rs @@ -0,0 +1,23 @@ +//! [GET /_matrix/media/r0/config](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-config) + +use js_int::UInt; +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Gets the config for the media repository.", + method: GET, + path: "/_matrix/media/r0/config", + name: "get_media_config", + rate_limited: true, + requires_authentication: true, + } + + request {} + + response { + /// Maximum size of upload in bytes. + #[serde(rename = "m.upload.size")] + upload_size: UInt, + } +} From 052b3a199db8793533a2608c7760ee75d61307ab Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 19 Feb 2020 13:51:46 -0600 Subject: [PATCH 213/350] Add media preview endpoint. Fixes #39. --- src/r0/media/get_media_preview.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/r0/media/get_media_preview.rs diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs new file mode 100644 index 00000000..126b7aba --- /dev/null +++ b/src/r0/media/get_media_preview.rs @@ -0,0 +1,34 @@ +//! [GET /_matrix/media/r0/preview_url](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-preview-url) + +use js_int::UInt; +use ruma_api::ruma_api; +use serde_json::Value; + +ruma_api! { + metadata { + description: "Get a preview for a URL.", + name: "get_media_preview", + method: GET, + path: "/_matrix/media/r0/preview_url", + rate_limited: true, + requires_authentication: true, + } + + request { + /// URL to get a preview of. + #[ruma_api(query)] + url: String, + /// Preferred point in time (in milliseconds) to return a preview for. + #[ruma_api(query)] + ts: UInt, + } + + response { + /// OpenGraph-like data for the URL. + /// + /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` + /// field, and `og:image` returns the MXC URI to the image, if any. + #[ruma_api(body)] + data: Option, + } +} From ab7cb329a4ef7fb4c159607067dae5628d30e89b Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Wed, 19 Feb 2020 19:54:17 -0600 Subject: [PATCH 214/350] Update changelog with media endpoints. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65349774..1adde991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,13 @@ Improvements: * Add OpenID token request endpoint. * Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) * Add endpoints to retrieve account_data (introduced in r0.5.0) +* Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` Breaking changes: * Update ruma-api to 0.14.0 * Fix `r0::session::get_login_types` +* Add `allow_remote` parameter to `r0::media::get_content` # 0.6.0 From fc59bf4b55e52c2b4dd445bdac0e3a933bc7941b Mon Sep 17 00:00:00 2001 From: iinuwa Date: Thu, 20 Feb 2020 18:15:17 -0600 Subject: [PATCH 215/350] Update create room endpoint --- CHANGELOG.md | 1 + src/r0/room/create_room.rs | 50 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1adde991..962c74e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Breaking changes: * Update ruma-api to 0.14.0 * Fix `r0::session::get_login_types` * Add `allow_remote` parameter to `r0::media::get_content` +* Add missing parameters for `r0::room::create_room` # 0.6.0 diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index fba3862c..0335921e 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,10 +1,13 @@ -//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-createroom) +//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom) use ruma_api::ruma_api; +use ruma_events::{room::power_levels::PowerLevelsEventContent, EventResult}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; +use serde_json::Value; use super::Visibility; +use crate::r0::thirdparty::Medium; ruma_api! { metadata { @@ -20,21 +23,40 @@ ruma_api! { /// Extra keys to be added to the content of the `m.room.create`. #[serde(skip_serializing_if = "Option::is_none")] pub creation_content: Option, + /// List of state events to send to the new room. + /// + /// Takes precedence over events set by preset, but gets overriden by + /// name and topic keys. + #[serde(skip_serializing_if = "Vec::is_empty")] + pub initial_state: Vec, /// A list of user IDs to invite to the room. /// /// This will tell the server to invite everyone in the list to the newly created room. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub invite: Vec, + /// List of third party IDs of users to invite. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub invite_3pid: Vec, + /// If set, this sets the `is_direct` flag on room invites. + #[serde(skip_serializing_if = "Option::is_none")] + pub is_direct: Option, /// If this is included, an `m.room.name` event will be sent into the room to indicate /// the name of the room. #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + /// Power level content to override in the default power level event. + #[serde(skip_serializing_if = "Option::is_none")] + #[wrap_incoming(PowerLevelsEventContent with EventResult)] + power_level_content_override: Option, /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, /// The desired room alias local part. #[serde(skip_serializing_if = "Option::is_none")] pub room_alias_name: Option, + /// Room version to set for the room. Defaults to homeserver's default if not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_version: Option, /// If this is included, an `m.room.topic` event will be sent into the room to indicate /// the topic for the room. #[serde(skip_serializing_if = "Option::is_none")] @@ -44,7 +66,6 @@ ruma_api! { /// default to private visibility if this key is not included. #[serde(skip_serializing_if = "Option::is_none")] pub visibility: Option, - // TODO: missing `invite_3pid`, `initial_state` } response { @@ -74,3 +95,28 @@ pub enum RoomPreset { /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. TrustedPrivateChat, } + +/// Represents third party IDs to invite to the room. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Invite3pid { + /// Hostname and port of identity server to be used for account lookups. + id_server: String, + /// An access token registered with the identity server. + id_access_token: String, + /// Type of third party ID. + medium: Medium, + /// Third party identifier. + address: String, +} + +/// Represents content of a state event to be used to initalize new room state. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct InitialStateEvent { + /// State event type. + #[serde(rename = "type")] + event_type: String, + /// `state_key` of the event to be sent. + state_key: Option, + /// JSON content of the state event. + content: Value, +} From aca4915e8c1981cfc3448a640b6bd6a6e53b4664 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 22 Feb 2020 01:27:46 +0100 Subject: [PATCH 216/350] Add a login request serialization test --- src/r0/session/login.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 239144cf..a6b53d6e 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -141,7 +141,11 @@ impl<'de> Deserialize<'de> for UserInfo { #[cfg(test)] mod tests { - use super::{LoginInfo, UserInfo}; + use std::convert::TryInto; + + use serde_json::json; + + use super::{LoginInfo, Medium, Request, UserInfo}; #[test] fn deserialize_login_type() { @@ -193,4 +197,36 @@ mod tests { UserInfo::MatrixId("cheeky_monkey".into()) ); } + + #[test] + fn serialize_login_request_body() { + let req: http::Request> = Request { + user: UserInfo::ThirdPartyId { + address: "hello@example.com".to_owned(), + medium: Medium::Email, + }, + login_info: LoginInfo::Token { + token: "0xdeadbeef".to_owned(), + }, + device_id: None, + initial_device_display_name: Some("test".to_string()), + } + .try_into() + .unwrap(); + + let req_body_value: serde_json::Value = serde_json::from_slice(req.body()).unwrap(); + assert_eq!( + req_body_value, + json!({ + "identifier": { + "type": "m.id.thirdparty", + "medium": "email", + "address": "hello@example.com" + }, + "type": "m.login.token", + "token": "0xdeadbeef", + "initial_device_display_name": "test", + }) + ) + } } From 59bbef5a35e3a4944f0843f2950904d274a12f1a Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Fri, 21 Feb 2020 17:49:14 -0600 Subject: [PATCH 217/350] Remove deprecate account bind endpoint. --- CHANGELOG.md | 1 + src/r0/contact.rs | 1 - src/r0/contact/create_contact.rs | 39 -------------------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 src/r0/contact/create_contact.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 962c74e2..44529876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Breaking changes: * Fix `r0::session::get_login_types` * Add `allow_remote` parameter to `r0::media::get_content` * Add missing parameters for `r0::room::create_room` +* Remove deprecated endpoint `r0::contact::create_contact` (deprecated in r0.6.0) # 0.6.0 diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 39bb1d10..41c13004 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -1,5 +1,4 @@ //! Endpoints for account contact information. -pub mod create_contact; pub mod get_contacts; pub mod request_contact_verification_token; diff --git a/src/r0/contact/create_contact.rs b/src/r0/contact/create_contact.rs deleted file mode 100644 index 5b246cd4..00000000 --- a/src/r0/contact/create_contact.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! [POST /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid) - -use ruma_api::ruma_api; -use serde::{Deserialize, Serialize}; - -ruma_api! { - metadata { - description: "Adds contact information to the user's account.", - method: POST, - name: "create_contact", - path: "/_matrix/client/r0/account/3pid", - rate_limited: false, - requires_authentication: true, - } - - request { - /// Whether the homeserver should also bind this third party identifier to the account's - /// Matrix ID with the passed identity server. - /// - /// Default to `false` if not supplied. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind: Option, - /// The third party credentials to associate with the account. - pub three_pid_creds: ThreePidCredentials, - } - - response {} -} - -/// The third party credentials to associate with the account. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ThreePidCredentials { - /// The client secret used in the session with the identity server. - pub client_secret: String, - /// The identity server to use. - pub id_server: String, - /// The session identifier given by the identity server. - pub sid: String, -} From 49390789547b28fd4489f1ad7a42af97301bbee1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 22 Feb 2020 01:47:28 +0100 Subject: [PATCH 218/350] Fix missing #[ruma_api(body)] --- src/r0/device/get_device.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs index 8f064083..98b88bd2 100644 --- a/src/r0/device/get_device.rs +++ b/src/r0/device/get_device.rs @@ -20,6 +20,7 @@ ruma_api! { } response { + #[ruma_api(body)] device: Device, } } From 9665abbaf243f659a2be83f4e3d84b975db5f520 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 22 Feb 2020 01:51:38 +0100 Subject: [PATCH 219/350] Make accidentally private things public --- src/r0/account.rs | 9 ++++++--- src/r0/account/delete_3pid.rs | 8 ++++---- src/r0/account/request_openid_token.rs | 10 +++++----- src/r0/account/unbind_3pid.rs | 9 ++++----- src/r0/client_exchange/send_event_to_device.rs | 6 +++--- src/r0/config/get_global_account_data.rs | 6 +++--- src/r0/config/get_room_account_data.rs | 8 ++++---- src/r0/device/delete_device.rs | 6 ++++-- src/r0/device/delete_devices.rs | 4 ++-- src/r0/device/get_device.rs | 6 ++++-- src/r0/device/update_device.rs | 7 +++++-- src/r0/directory/get_public_rooms.rs | 6 +++--- src/r0/directory/get_public_rooms_filtered.rs | 10 +++++----- src/r0/keys.rs | 2 +- src/r0/media/get_media_config.rs | 2 +- src/r0/media/get_media_preview.rs | 6 +++--- src/r0/room/create_room.rs | 16 ++++++++-------- src/r0/room/report_content.rs | 8 ++++---- src/r0/room/upgrade_room.rs | 6 +++--- src/r0/session/login.rs | 10 ++++++---- src/r0/session/login/user_serde.rs | 6 +++--- 21 files changed, 81 insertions(+), 70 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index bda1ecb0..4064aa37 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -24,9 +24,9 @@ use serde::{Deserialize, Serialize}; pub struct AuthenticationData { /// The login type that the client is attempting to complete. #[serde(rename = "type")] - kind: String, + pub kind: String, /// The value of the session key given by the homeserver. - session: Option, + pub session: Option, } /// Additional authentication information for requestToken endpoints. @@ -42,7 +42,10 @@ pub struct IdentityServerInfo { /// Possible values for deleting or unbinding 3PIDs #[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] -enum ThirdPartyIdRemovalStatus { +pub enum ThirdPartyIdRemovalStatus { + /// Either the homeserver couldn't determine the right identity server to contact, or the + /// identity server refused the operation. NoSupport, + /// Success. Success, } diff --git a/src/r0/account/delete_3pid.rs b/src/r0/account/delete_3pid.rs index b9109efe..4af420b6 100644 --- a/src/r0/account/delete_3pid.rs +++ b/src/r0/account/delete_3pid.rs @@ -18,16 +18,16 @@ ruma_api! { request { /// Identity server to delete from. #[serde(skip_serializing_if = "Option::is_none")] - id_server: Option, + pub id_server: Option, /// Medium of the 3PID to be removed. - medium: Medium, + pub medium: Medium, /// Third-party address being removed. - address: String, + pub address: String, } response { /// Result of unbind operation. - id_server_unbind_result: ThirdPartyIdRemovalStatus, + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } } diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs index a62f7b09..e4ac9362 100644 --- a/src/r0/account/request_openid_token.rs +++ b/src/r0/account/request_openid_token.rs @@ -18,18 +18,18 @@ ruma_api! { request { /// User ID of authenticated user. #[ruma_api(path)] - user_id: UserId, + pub user_id: UserId, } response { /// Access token for verifying user's identity. - access_token: String, + pub access_token: String, /// Access token type. - token_type: TokenType, + pub token_type: TokenType, /// Homeserver domain for verification of user's identity. - matrix_server_name: String, + pub matrix_server_name: String, /// Seconds until token expiration. - expires_in: UInt, + pub expires_in: UInt, } } diff --git a/src/r0/account/unbind_3pid.rs b/src/r0/account/unbind_3pid.rs index 69f68f8e..d493a179 100644 --- a/src/r0/account/unbind_3pid.rs +++ b/src/r0/account/unbind_3pid.rs @@ -18,16 +18,15 @@ ruma_api! { request { /// Identity server to unbind from. #[serde(skip_serializing_if = "Option::is_none")] - id_server: Option, + pub id_server: Option, /// Medium of the 3PID to be removed. - medium: Medium, + pub medium: Medium, /// Third-party address being removed. - address: String, + pub address: String, } response { /// Result of unbind operation. - id_server_unbind_result: ThirdPartyIdRemovalStatus, + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } - } diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index 36aefd36..0813ab3b 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -21,15 +21,15 @@ ruma_api! { request { /// Type of event being sent to each device. #[ruma_api(path)] - event_type: String, + pub event_type: String, /// A request identifier unique to the access token used to send the request. #[ruma_api(path)] - txn_id: String, + pub txn_id: String, /// A map of users to devices to a message event to be sent to the user's /// device. Individual message events can be sent to devices, but all /// events must be of the same type. #[wrap_incoming(all::Event with EventResult)] - messages: HashMap> + pub messages: HashMap> } response {} diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs index 342fa1c0..b5a01559 100644 --- a/src/r0/config/get_global_account_data.rs +++ b/src/r0/config/get_global_account_data.rs @@ -17,16 +17,16 @@ ruma_api! { request { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - user_id: UserId, + pub user_id: UserId, /// Type of data to retrieve. #[ruma_api(path)] - event_type: String, + pub event_type: String, } response { /// Account data content for the given type. #[ruma_api(body)] #[wrap_incoming(with EventResult)] - account_data: only::Event, + pub account_data: only::Event, } } diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs index f2ea38e9..dc76dd0e 100644 --- a/src/r0/config/get_room_account_data.rs +++ b/src/r0/config/get_room_account_data.rs @@ -17,19 +17,19 @@ ruma_api! { request { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - user_id: UserId, + pub user_id: UserId, /// Room ID for which to retrieve data. #[ruma_api(path)] - room_id: RoomId, + pub room_id: RoomId, /// Type of data to retrieve. #[ruma_api(path)] - event_type: String, + pub event_type: String, } response { /// Account data content for the given type. #[ruma_api(body)] #[wrap_incoming(with EventResult)] - account_data: only::Event, + pub account_data: only::Event, } } diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs index bea045e4..478a7064 100644 --- a/src/r0/device/delete_device.rs +++ b/src/r0/device/delete_device.rs @@ -15,10 +15,12 @@ ruma_api! { } request { + /// The device to delete. #[ruma_api(path)] - device_id: DeviceId, + pub device_id: DeviceId, + /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - auth: Option, + pub auth: Option, } response {} diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/delete_devices.rs index 2adf8ea5..3ce01871 100644 --- a/src/r0/device/delete_devices.rs +++ b/src/r0/device/delete_devices.rs @@ -16,11 +16,11 @@ ruma_api! { request { /// List of devices to delete. - devices: Vec, + pub devices: Vec, /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - auth: Option, + pub auth: Option, } response {} diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs index 98b88bd2..0b17c6b8 100644 --- a/src/r0/device/get_device.rs +++ b/src/r0/device/get_device.rs @@ -15,12 +15,14 @@ ruma_api! { } request { + /// The device to retrieve. #[ruma_api(path)] - device_id: DeviceId, + pub device_id: DeviceId, } response { + /// Information about the device. #[ruma_api(body)] - device: Device, + pub device: Device, } } diff --git a/src/r0/device/update_device.rs b/src/r0/device/update_device.rs index 2d3db701..9d4328ff 100644 --- a/src/r0/device/update_device.rs +++ b/src/r0/device/update_device.rs @@ -14,10 +14,13 @@ ruma_api! { } request { + /// The device to update. #[ruma_api(path)] - device_id: DeviceId, + pub device_id: DeviceId, + /// The new display name for this device. If this is `None`, the display name won't be + /// changed. #[serde(skip_serializing_if = "Option::is_none")] - display_name: Option, + pub display_name: Option, } response {} diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index dcf0cf98..2f565cda 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -19,17 +19,17 @@ ruma_api! { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - limit: Option, + pub limit: Option, /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - since: Option, + pub since: Option, /// The server to fetch the public room lists from. /// /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - server: Option, + pub server: Option, } response { diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index f6b5ad6e..b63b0347 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -22,16 +22,16 @@ ruma_api! { /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - server: Option, + pub server: Option, /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] - limit: Option, + pub limit: Option, /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] - since: Option, + pub since: Option, /// Filter to apply to the results. #[serde(skip_serializing_if = "Option::is_none")] - filter: Option, + pub filter: Option, } response { @@ -51,5 +51,5 @@ ruma_api! { pub struct Filter { /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. #[serde(skip_serializing_if = "Option::is_none")] - generic_search_term: Option, + pub generic_search_term: Option, } diff --git a/src/r0/keys.rs b/src/r0/keys.rs index e307d3b6..1fc91089 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -129,7 +129,7 @@ pub struct DeviceKeys { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UnsignedDeviceInfo { /// The display name which the user set on the device. - device_display_name: String, + pub device_display_name: String, } /// A key for the SignedCurve25519 algorithm diff --git a/src/r0/media/get_media_config.rs b/src/r0/media/get_media_config.rs index 2cc2f086..84008948 100644 --- a/src/r0/media/get_media_config.rs +++ b/src/r0/media/get_media_config.rs @@ -18,6 +18,6 @@ ruma_api! { response { /// Maximum size of upload in bytes. #[serde(rename = "m.upload.size")] - upload_size: UInt, + pub upload_size: UInt, } } diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index 126b7aba..c2fcdae8 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -17,10 +17,10 @@ ruma_api! { request { /// URL to get a preview of. #[ruma_api(query)] - url: String, + pub url: String, /// Preferred point in time (in milliseconds) to return a preview for. #[ruma_api(query)] - ts: UInt, + pub ts: UInt, } response { @@ -29,6 +29,6 @@ ruma_api! { /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` /// field, and `og:image` returns the MXC URI to the image, if any. #[ruma_api(body)] - data: Option, + pub data: Option, } } diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 0335921e..53d077f6 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -47,7 +47,7 @@ ruma_api! { /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] #[wrap_incoming(PowerLevelsEventContent with EventResult)] - power_level_content_override: Option, + pub power_level_content_override: Option, /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, @@ -100,13 +100,13 @@ pub enum RoomPreset { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Invite3pid { /// Hostname and port of identity server to be used for account lookups. - id_server: String, + pub id_server: String, /// An access token registered with the identity server. - id_access_token: String, + pub id_access_token: String, /// Type of third party ID. - medium: Medium, + pub medium: Medium, /// Third party identifier. - address: String, + pub address: String, } /// Represents content of a state event to be used to initalize new room state. @@ -114,9 +114,9 @@ pub struct Invite3pid { pub struct InitialStateEvent { /// State event type. #[serde(rename = "type")] - event_type: String, + pub event_type: String, /// `state_key` of the event to be sent. - state_key: Option, + pub state_key: Option, /// JSON content of the state event. - content: Value, + pub content: Value, } diff --git a/src/r0/room/report_content.rs b/src/r0/room/report_content.rs index 43713bea..ecb07ec6 100644 --- a/src/r0/room/report_content.rs +++ b/src/r0/room/report_content.rs @@ -17,14 +17,14 @@ ruma_api! { request { /// Room in which the event to be reported is located. #[ruma_api(path)] - room_id: RoomId, + pub room_id: RoomId, /// Event to report. #[ruma_api(path)] - event_id: EventId, + pub event_id: EventId, /// Integer between -100 and 0 rating offensivness. - score: Int, + pub score: Int, /// Reason to report content. May be blank. - reason: String, + pub reason: String, } response {} diff --git a/src/r0/room/upgrade_room.rs b/src/r0/room/upgrade_room.rs index 85ab9ee3..91b60b01 100644 --- a/src/r0/room/upgrade_room.rs +++ b/src/r0/room/upgrade_room.rs @@ -16,13 +16,13 @@ ruma_api! { request { /// ID of the room to be upgraded. #[ruma_api(path)] - room_id: RoomId, + pub room_id: RoomId, /// New version for the room. - new_version: String, + pub new_version: String, } response { /// ID of the new room. - replacement_room: RoomId, + pub replacement_room: RoomId, } } diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index a6b53d6e..d69fbe42 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -99,24 +99,26 @@ pub enum LoginInfo { /// Client configuration provided by the server. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DiscoveryInfo { + /// Information about the homeserver to connect to. #[serde(rename = "m.homeserver")] - homeserver: HomeserverInfo, + pub homeserver: HomeserverInfo, + /// Information about the identity server to connect to. #[serde(rename = "m.identity_server")] - identity_server: Option, + pub identity_server: Option, } /// Information about the homeserver to connect to. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct HomeserverInfo { /// The base URL for the homeserver for client-server connections. - base_url: String, + pub base_url: String, } /// Information about the identity server to connect to. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct IdentityServerInfo { /// The base URL for the identity server for client-server connections. - base_url: String, + pub base_url: String, } mod user_serde; diff --git a/src/r0/session/login/user_serde.rs b/src/r0/session/login/user_serde.rs index 17202ce8..f7568789 100644 --- a/src/r0/session/login/user_serde.rs +++ b/src/r0/session/login/user_serde.rs @@ -8,14 +8,14 @@ use super::Medium; // The following three structs could just be used in place of the one in the parent module, but // that one is arguably much easier to deal with. #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub struct UserInfo<'a> { +pub(crate) struct UserInfo<'a> { #[serde(borrow)] - identifier: UserIdentifier<'a>, + pub identifier: UserIdentifier<'a>, } #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[serde(tag = "type")] -pub enum UserIdentifier<'a> { +pub(crate) enum UserIdentifier<'a> { #[serde(rename = "m.id.user")] MatrixId { user: &'a str }, #[serde(rename = "m.id.thirdparty")] From 7d677f690e028dfe78b1d2f24dcec405d29da7af Mon Sep 17 00:00:00 2001 From: iinuwa Date: Sat, 22 Feb 2020 16:12:34 -0600 Subject: [PATCH 220/350] Add unstable_features to version endpoint --- CHANGELOG.md | 1 + src/unversioned/get_supported_versions.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44529876..4049b6c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Improvements: * Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) * Add endpoints to retrieve account_data (introduced in r0.5.0) * Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` +* Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) Breaking changes: diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 5d98b957..fdf98eb5 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,4 +1,6 @@ -//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-versions) +//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-versions) + +use std::collections::HashMap; use ruma_api::ruma_api; @@ -17,5 +19,8 @@ ruma_api! { response { /// A list of Matrix client API protocol versions supported by the homeserver. pub versions: Vec, + /// Experimental features supported by the server. + #[serde(default, skip_serializing_if = "HashMap::is_empty")] + pub unstable_features: HashMap } } From e16049b5b3378a6b8ed7b2a9300aac27e193008c Mon Sep 17 00:00:00 2001 From: iinuwa Date: Sat, 22 Feb 2020 16:14:10 -0600 Subject: [PATCH 221/350] Add invite-by-3pid endpoint --- CHANGELOG.md | 3 ++ src/r0/membership.rs | 15 +++++++ src/r0/membership/invite_user.rs | 68 ++++++++++++++++++++++++++++++-- src/r0/room/create_room.rs | 15 +------ 4 files changed, 84 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4049b6c7..5479e03c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Breaking changes: * Fix `r0::session::get_login_types` * Add `allow_remote` parameter to `r0::media::get_content` * Add missing parameters for `r0::room::create_room` +* Moved `r0::room::create_room::Invite3pid` to `r0::membership::Invite3pid` +* Replaced `user_id` parameter of `r0::membership::invite_user` with `recipient` + to allow invitation of users by either Matrix or third party identifiers. * Remove deprecated endpoint `r0::contact::create_contact` (deprecated in r0.6.0) # 0.6.0 diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 023965c7..37880957 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -16,6 +16,8 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; +use crate::r0::thirdparty::Medium; + // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } // for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? @@ -32,3 +34,16 @@ pub struct ThirdPartySigned { /// The state key of the m.third_party_invite event. pub token: String, } + +/// Represents third party IDs to invite to the room. +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Invite3pid { + /// Hostname and port of identity server to be used for account lookups. + pub id_server: String, + /// An access token registered with the identity server. + pub id_access_token: String, + /// Type of third party ID. + pub medium: Medium, + /// Third party identifier. + pub address: String, +} diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index f0d59871..bac550e8 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -1,7 +1,16 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-invite) - +//! [POST /_matrix/client/r0/rooms/{roomId}/invite][invite-by-user-id] +//! +//! This endpoint has two forms: one to invite a user +//! [by their Matrix identifier][invite-by-user-id], and one to invite a user +//! [by their third party identifier][invite-by-3pid]. +//! +//! [invite-by-user-id]: https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-rooms-roomid-invite +//! [invite-by-3pid]: https://matrix.org/docs/spec/client_server/r0.6.0#id101 use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; +use serde::{Deserialize, Serialize}; + +use super::Invite3pid; ruma_api! { metadata { @@ -18,8 +27,61 @@ ruma_api! { #[ruma_api(path)] pub room_id: RoomId, /// The user to invite. - pub user_id: UserId, + #[ruma_api(body)] + pub recipient: InvitationRecipient, } response {} } + +/// Distinguishes between invititations by Matrix or third party identifiers. +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[serde(untagged)] +pub enum InvitationRecipient { + /// Used to invite user by their Matrix identifer. + UserId { + /// Matrix identifier of user. + user_id: UserId, + }, + /// Used to invite user by a third party identifer. + ThirdPartyId(Invite3pid), +} + +#[cfg(test)] +mod tests { + use super::InvitationRecipient; + use crate::r0::{membership::Invite3pid, thirdparty::Medium}; + use ruma_identifiers::UserId; + use std::convert::TryFrom; + #[test] + fn deserialize_invite_by_user_id() { + let incoming = + serde_json::from_str::(r#" { "user_id": "@carl:example.org" } "#) + .unwrap(); + let user_id = UserId::try_from("@carl:example.org").unwrap(); + let recipient = InvitationRecipient::UserId { user_id }; + assert_eq!(incoming, recipient); + } + + #[test] + fn deserialize_invite_by_3pid() { + let incoming = serde_json::from_str::( + r#" + { + "id_server": "example.org", + "id_access_token": "abcdefghijklmnop", + "medium": "email", + "address": "carl@example.org" + } + "#, + ) + .unwrap(); + let recipient = InvitationRecipient::ThirdPartyId(Invite3pid { + id_server: "example.org".to_string(), + id_access_token: "abcdefghijklmnop".to_string(), + medium: Medium::Email, + address: "carl@example.org".to_string(), + }); + assert_eq!(incoming, recipient); + } +} diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 53d077f6..5b81627c 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use super::Visibility; -use crate::r0::thirdparty::Medium; +use crate::r0::membership::Invite3pid; ruma_api! { metadata { @@ -96,19 +96,6 @@ pub enum RoomPreset { TrustedPrivateChat, } -/// Represents third party IDs to invite to the room. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Invite3pid { - /// Hostname and port of identity server to be used for account lookups. - pub id_server: String, - /// An access token registered with the identity server. - pub id_access_token: String, - /// Type of third party ID. - pub medium: Medium, - /// Third party identifier. - pub address: String, -} - /// Represents content of a state event to be used to initalize new room state. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InitialStateEvent { From 4b05e7e361eb99235448fdbd8fabec8174f796c7 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 25 Feb 2020 19:57:48 -0600 Subject: [PATCH 222/350] Add request and response parameters for account deactiviation --- CHANGELOG.md | 1 + src/r0/account/deactivate.rs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5479e03c..3388b2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Improvements: * Add endpoints to retrieve account_data (introduced in r0.5.0) * Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` * Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) +* Add request and response parameters for `r0::account::deactivate` Breaking changes: diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 99fa8fcc..6e982bf3 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -1,8 +1,9 @@ -//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-deactivate) -// TODO: missing request parameters +//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-deactivate) use ruma_api::ruma_api; +use super::{AuthenticationData, ThirdPartyIdRemovalStatus}; + ruma_api! { metadata { description: "Deactivate the current user's account.", @@ -13,7 +14,18 @@ ruma_api! { requires_authentication: true, } - request {} + request { + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + /// Identity server from which to unbind the user's third party + /// identifier. + #[serde(skip_serializing_if = "Option::is_none")] + id_server: Option, + } - response {} + response { + /// Result of unbind operation. + id_server_unbind_result: ThirdPartyIdRemovalStatus + } } From d36ec95fb717991d2e7dc73326cbd7457d19f617 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Wed, 26 Feb 2020 07:39:41 -0600 Subject: [PATCH 223/350] Export request and response fields as public --- src/r0/account/deactivate.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 6e982bf3..173f9705 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -17,15 +17,15 @@ ruma_api! { request { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - auth: Option, + pub auth: Option, /// Identity server from which to unbind the user's third party /// identifier. #[serde(skip_serializing_if = "Option::is_none")] - id_server: Option, + pub id_server: Option, } response { /// Result of unbind operation. - id_server_unbind_result: ThirdPartyIdRemovalStatus + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } } From 19bf8dbd770656ce99ed19cd4e53512756116db4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 26 Feb 2020 15:02:07 +0100 Subject: [PATCH 224/350] Add trailing comma --- src/r0/keys/get_keys.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index e314ffba..704d8ee6 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -32,7 +32,7 @@ ruma_api! { /// this should be the 'since' token of that sync request, or any later sync token. /// This allows the server to ensure its response contains the keys advertised by the notification in that sync. #[serde(skip_serializing_if = "Option::is_none")] - pub token: Option + pub token: Option, } response { From 8fb01a193e9b8a457f43b35b35bd0e2957184aba Mon Sep 17 00:00:00 2001 From: iinuwa Date: Wed, 26 Feb 2020 08:11:32 -0600 Subject: [PATCH 225/350] Add SSO login endpoint --- CHANGELOG.md | 3 ++- src/r0/session.rs | 1 + src/r0/session/sso_login.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/r0/session/sso_login.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 3388b2aa..b6177234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Improvements: * Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` * Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) * Add request and response parameters for `r0::account::deactivate` +* Add `r0::session::sso_login` (introduced in r0.5.0) Breaking changes: @@ -17,7 +18,7 @@ Breaking changes: * Add `allow_remote` parameter to `r0::media::get_content` * Add missing parameters for `r0::room::create_room` * Moved `r0::room::create_room::Invite3pid` to `r0::membership::Invite3pid` -* Replaced `user_id` parameter of `r0::membership::invite_user` with `recipient` +* Replaced `user_id` parameter of `r0::membership::invite_user` with `recipient` to allow invitation of users by either Matrix or third party identifiers. * Remove deprecated endpoint `r0::contact::create_contact` (deprecated in r0.6.0) diff --git a/src/r0/session.rs b/src/r0/session.rs index 5096af71..e1df60b8 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -4,3 +4,4 @@ pub mod get_login_types; pub mod login; pub mod logout; pub mod logout_all; +pub mod sso_login; diff --git a/src/r0/session/sso_login.rs b/src/r0/session/sso_login.rs new file mode 100644 index 00000000..af6c42d9 --- /dev/null +++ b/src/r0/session/sso_login.rs @@ -0,0 +1,28 @@ +//! [GET /_matrix/client/r0/login/sso/redirect](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-login-sso-redirect) + +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "", + method: GET, + name: "sso_login", + path: "/_matrix/client/r0/login/sso/redirect", + rate_limited: false, + requires_authentication: false, + + } + + request { + /// URL to which the homeserver should return the user after completing + /// authentication with the SSO identity provider. + #[ruma_api(query)] + pub redirect_url: String, + } + + response { + /// Redirect URL to the SSO identity provider. + #[ruma_api(header = LOCATION)] + pub location: String, + } +} From 21f9922b9eeaaf0025b2030abeeffd9a93cfda7c Mon Sep 17 00:00:00 2001 From: iinuwa Date: Mon, 9 Mar 2020 16:00:03 -0500 Subject: [PATCH 226/350] Update r0::context::get_context::Request and r0::filter::RoomEventFilter * Add lazy-loading options to RoomEventFilter * Use UInt instead of u8 for get_context limit * Add filter option to get_context endpoint * Add more tests Co-authored-by: Jonas Platte --- CHANGELOG.md | 3 + src/r0/context/get_context.rs | 10 ++- src/r0/filter.rs | 154 +++++++++++++++++++++++++++++++++- 3 files changed, 165 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6177234..4d99c23e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Improvements: * Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) * Add request and response parameters for `r0::account::deactivate` * Add `r0::session::sso_login` (introduced in r0.5.0) +* Add `filter` type for `r0::context::get_context` Breaking changes: @@ -21,6 +22,8 @@ Breaking changes: * Replaced `user_id` parameter of `r0::membership::invite_user` with `recipient` to allow invitation of users by either Matrix or third party identifiers. * Remove deprecated endpoint `r0::contact::create_contact` (deprecated in r0.6.0) +* Add lazy-loading options to `r0::filter::RoomEventFilter` (introduced in r0.5.0) +* Change type for `limit` request parameter of `r0::context::get_context` from `u8` to `Option` # 0.6.0 diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index 566ac742..c0f753d3 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -1,9 +1,12 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) +use js_int::UInt; use ruma_api::ruma_api; use ruma_events::{collections::only, EventResult}; use ruma_identifiers::{EventId, RoomId}; +use crate::r0::filter::RoomEventFilter; + ruma_api! { metadata { description: "Get the events immediately preceding and following a given event.", @@ -22,10 +25,15 @@ ruma_api! { /// /// Defaults to 10 if not supplied. #[ruma_api(query)] - pub limit: u8, + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, /// The room to get events from. #[ruma_api(path)] pub room_id: RoomId, + /// A RoomEventFilter to filter returned events with. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub filter: Option, } response { diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 2de9de95..2b8de854 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -3,9 +3,15 @@ pub mod create_filter; pub mod get_filter; +use std::fmt; + use js_int::UInt; use ruma_identifiers::{RoomId, UserId}; -use serde::{Deserialize, Serialize}; +use serde::{ + de::{MapAccess, Visitor}, + ser::SerializeStruct, + Deserialize, Deserializer, Serialize, Serializer, +}; /// Format to use for returned events #[derive(Copy, Clone, Debug, Deserialize, Serialize)] @@ -64,6 +70,9 @@ pub struct RoomEventFilter { /// If this item is absent then all event types are included. #[serde(skip_serializing_if = "Option::is_none")] pub contains_url: Option, + /// Options to control lazy-loading of membership events. + #[serde(flatten)] + pub lazy_load_options: LazyLoadOptions, } impl RoomEventFilter { @@ -203,3 +212,146 @@ impl FilterDefinition { } } } + +/// Specifies options for [lazy-loading membership events][lazy-loading] on +/// supported endpoints +/// +/// [lazy-loading]: https://matrix.org/docs/spec/client_server/r0.6.0#lazy-loading-room-members +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum LazyLoadOptions { + /// Disables lazy-loading of membership events. + Disabled, + /// Enables lazy-loading of events. + Enabled { + /// If `true`, sends all membership events for all events, even if they have + /// already been sent to the client. Defaults to `false`. + include_redundant_members: bool, + }, +} + +impl Serialize for LazyLoadOptions { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut state; + match *self { + Self::Enabled { + include_redundant_members: true, + } => { + state = serializer.serialize_struct("LazyLoad", 2)?; + state.serialize_field("lazy_load_members", &true)?; + state.serialize_field("include_redundant_members", &true)?; + } + Self::Enabled { .. } => { + state = serializer.serialize_struct("LazyLoad", 1)?; + state.serialize_field("lazy_load_members", &true)?; + } + _ => { + state = serializer.serialize_struct("LazyLoad", 0)?; + } + } + state.end() + } +} + +impl Default for LazyLoadOptions { + fn default() -> Self { + Self::Disabled + } +} + +struct LazyLoadOptionsVisitor; + +impl<'de> Visitor<'de> for LazyLoadOptionsVisitor { + type Value = LazyLoadOptions; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Lazy load options") + } + + fn visit_map(self, mut access: M) -> Result + where + M: MapAccess<'de>, + { + let mut lazy_load_members = false; + let mut include_redundant_members = false; + while let Some((key, value)) = access.next_entry::()? { + match &*key { + "lazy_load_members" => lazy_load_members = value, + "include_redundant_members" => include_redundant_members = value, + _ => {} + }; + } + + Ok(if lazy_load_members { + LazyLoadOptions::Enabled { + include_redundant_members, + } + } else { + LazyLoadOptions::Disabled + }) + } +} + +impl<'de> Deserialize<'de> for LazyLoadOptions { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_map(LazyLoadOptionsVisitor) + } +} + +#[cfg(test)] +mod tests { + use serde_json::json; + + use super::LazyLoadOptions; + + #[test] + fn test_serializing_disabled_lazy_load() { + let lazy_load_options = LazyLoadOptions::Disabled; + assert_eq!(serde_json::to_value(lazy_load_options).unwrap(), json!({})); + } + + #[test] + fn test_serializing_lazy_load_no_redundant() { + let lazy_load_options = LazyLoadOptions::Enabled { + include_redundant_members: false, + }; + assert_eq!( + serde_json::to_value(lazy_load_options).unwrap(), + json!({ "lazy_load_members": true }) + ); + } + + #[test] + fn test_serializing_lazy_load_with_redundant() { + let lazy_load_options = LazyLoadOptions::Enabled { + include_redundant_members: true, + }; + assert_eq!( + serde_json::to_value(lazy_load_options).unwrap(), + json!({ "lazy_load_members": true, "include_redundant_members": true }) + ); + } + + #[test] + fn test_deserializing_no_lazy_load() { + let json = json!({}); + assert_eq!( + serde_json::from_value::(json).unwrap(), + LazyLoadOptions::Disabled, + ); + } + + #[test] + fn test_deserializing_ignore_redundant_members_when_no_lazy_load() { + let json = json!({ "include_redundant_members": true }); + assert_eq!( + serde_json::from_value::(json).unwrap(), + LazyLoadOptions::Disabled, + ); + } +} From e7526b88cb12779a248353de7536c291d35345dc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 12 Mar 2020 21:31:03 +0100 Subject: [PATCH 227/350] Update ruma-events to 0.17.0 --- Cargo.toml | 2 +- src/r0/sync/sync_events.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a80ad4a6..1aef59f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" http = "0.2.0" js_int = { version = "0.1.2", features = ["serde"] } ruma-api = "0.14.0" -ruma-events = "0.16.0" +ruma-events = "0.17.0" ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.48" diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 2abada9a..45b6f539 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -10,7 +10,7 @@ use ruma_events::{ only::Event as NonRoomEvent, }, presence::PresenceEvent, - stripped::StrippedState, + stripped::AnyStrippedStateEvent, EventResult, }; use ruma_identifiers::RoomId; @@ -228,8 +228,8 @@ pub struct InvitedRoom { #[derive(Clone, Debug, Serialize, Outgoing)] pub struct InviteState { /// A list of state events. - #[wrap_incoming(StrippedState with EventResult)] - pub events: Vec, + #[wrap_incoming(AnyStrippedStateEvent with EventResult)] + pub events: Vec, } /// Updates to the presence status of other users. From 7307c695e07a457615dbff5331d05ced500a5619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 12 Mar 2020 13:33:38 +0100 Subject: [PATCH 228/350] sync_events: Parse the to-device events. --- src/r0/sync/sync_events.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 45b6f539..e8593d6e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -11,6 +11,7 @@ use ruma_events::{ }, presence::PresenceEvent, stripped::AnyStrippedStateEvent, + to_device::AnyToDeviceEvent, EventResult, }; use ruma_identifiers::RoomId; @@ -60,6 +61,9 @@ ruma_api! { /// Updates to the presence status of other users. #[wrap_incoming] pub presence: Presence, + /// Messages sent dirrectly between devices. + #[wrap_incoming] + pub to_device: ToDevice, } } @@ -239,3 +243,11 @@ pub struct Presence { #[wrap_incoming(PresenceEvent with EventResult)] pub events: Vec, } + +/// Messages sent dirrectly between devices. +#[derive(Clone, Debug, Serialize, Outgoing)] +pub struct ToDevice { + /// A list of to-device events. + #[wrap_incoming(AnyToDeviceEvent with EventResult)] + pub events: Vec, +} From 122097cfef2b8ce0c9d771e55c427c745184e198 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Fri, 20 Mar 2020 05:29:51 -0500 Subject: [PATCH 229/350] Use Duration over UInt for timeouts and similar fields --- CHANGELOG.md | 11 ++++ Cargo.toml | 2 +- src/lib.rs | 2 + src/r0/account/request_openid_token.rs | 6 +- src/r0/keys/claim_keys.rs | 6 +- src/r0/keys/get_keys.rs | 6 +- src/r0/presence/get_presence.rs | 6 +- src/r0/sync/sync_events.rs | 5 +- src/r0/typing/create_typing_event.rs | 6 +- src/r0/voip/get_turn_server_info.rs | 6 +- src/serde.rs | 3 + src/serde/duration.rs | 4 ++ src/serde/duration/opt_ms.rs | 90 ++++++++++++++++++++++++++ src/serde/duration/secs.rs | 66 +++++++++++++++++++ 14 files changed, 203 insertions(+), 16 deletions(-) create mode 100644 src/serde.rs create mode 100644 src/serde/duration.rs create mode 100644 src/serde/duration/opt_ms.rs create mode 100644 src/serde/duration/secs.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d99c23e..da68bfe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,17 @@ Breaking changes: * Remove deprecated endpoint `r0::contact::create_contact` (deprecated in r0.6.0) * Add lazy-loading options to `r0::filter::RoomEventFilter` (introduced in r0.5.0) * Change type for `limit` request parameter of `r0::context::get_context` from `u8` to `Option` +* Use `std::time::Duration` for appropriate fields on several endpoints: + ``` + r0::{ + account::request_openid_token, + keys::{claim_keys, get_keys}, + presence::get_presence, + sync::sync_events, + typing::create_typing_event, + voip::get_turn_server_info + } + ``` # 0.6.0 diff --git a/Cargo.toml b/Cargo.toml index 1aef59f4..1b45821c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] http = "0.2.0" -js_int = { version = "0.1.2", features = ["serde"] } +js_int = { version = "0.1.3", features = ["serde"] } ruma-api = "0.14.0" ruma-events = "0.17.0" ruma-identifiers = "0.14.1" diff --git a/src/lib.rs b/src/lib.rs index 4b08448a..9d8e94f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,3 +11,5 @@ pub mod error; pub mod r0; pub mod unversioned; + +mod serde; diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs index e4ac9362..b3b96bcc 100644 --- a/src/r0/account/request_openid_token.rs +++ b/src/r0/account/request_openid_token.rs @@ -1,6 +1,7 @@ //! [POST /_matrix/client/r0/user/{userId}/openid/request_token](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-userid-openid-request-token) -use js_int::UInt; +use std::time::Duration; + use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; @@ -29,7 +30,8 @@ ruma_api! { /// Homeserver domain for verification of user's identity. pub matrix_server_name: String, /// Seconds until token expiration. - pub expires_in: UInt, + #[serde(with = "crate::serde::duration::secs")] + pub expires_in: Duration, } } diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index b21a62bd..3b14c0a2 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -2,7 +2,8 @@ use std::collections::HashMap; -use js_int::UInt; +use std::time::Duration; + use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; use serde_json::Value; @@ -23,7 +24,8 @@ ruma_api! { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + #[serde(default, with = "crate::serde::duration::opt_ms")] + pub timeout: Option, /// The keys to be claimed. pub one_time_keys: HashMap>, diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index 704d8ee6..526a3359 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -1,8 +1,7 @@ //! [POST /_matrix/client/r0/keys/query](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-query) -use std::collections::HashMap; +use std::{collections::HashMap, time::Duration}; -use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; use serde_json::Value; @@ -23,7 +22,8 @@ ruma_api! { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + #[serde(default, with = "crate::serde::duration::opt_ms")] + pub timeout: Option, /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. pub device_keys: HashMap>, diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 0d76d74c..2a32e1a4 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -1,6 +1,7 @@ //! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status) -use js_int::UInt; +use std::time::Duration; + use ruma_api::ruma_api; use ruma_events::presence::PresenceState; use ruma_identifiers::UserId; @@ -30,7 +31,8 @@ ruma_api! { pub currently_active: Option, /// The length of time in milliseconds since an action was performed by the user. #[serde(skip_serializing_if = "Option::is_none")] - pub last_active_ago: Option, + #[serde(default, with = "crate::serde::duration::opt_ms")] + pub last_active_ago: Option, /// The user's presence state. pub presence: PresenceState, } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index e8593d6e..4eb454d1 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-sync) -use std::collections::HashMap; +use std::{collections::HashMap, time::Duration}; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; @@ -48,8 +48,9 @@ ruma_api! { pub set_presence: Option, /// The maximum time to poll in milliseconds before returning this request. #[serde(skip_serializing_if = "Option::is_none")] + #[serde(with = "crate::serde::duration::opt_ms")] #[ruma_api(query)] - pub timeout: Option, + pub timeout: Option, } response { diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index 29356e12..3dad3ef2 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -1,6 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) -use js_int::UInt; +use std::time::Duration; + use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -20,7 +21,8 @@ ruma_api! { pub room_id: RoomId, /// The length of time in milliseconds to mark this user as typing. #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + #[serde(default, with = "crate::serde::duration::opt_ms")] + pub timeout: Option, /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. pub typing: bool, /// The user who has started to type. diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 15df4e77..91ce8597 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,6 +1,7 @@ //! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) -use js_int::UInt; +use std::time::Duration; + use ruma_api::ruma_api; ruma_api! { @@ -19,7 +20,8 @@ ruma_api! { /// The password to use. pub password: String, /// The time-to-live in seconds. - pub ttl: UInt, + #[serde(with = "crate::serde::duration::secs")] + pub ttl: Duration, /// A list of TURN URIs. pub uris: Vec, /// The username to use. diff --git a/src/serde.rs b/src/serde.rs new file mode 100644 index 00000000..4cb6139c --- /dev/null +++ b/src/serde.rs @@ -0,0 +1,3 @@ +//! Modules to hold functions for de-/serializing remote types + +pub mod duration; diff --git a/src/serde/duration.rs b/src/serde/duration.rs new file mode 100644 index 00000000..d8c895fa --- /dev/null +++ b/src/serde/duration.rs @@ -0,0 +1,4 @@ +//! De-/serialization functions for `std::time::Duration` objects + +pub mod opt_ms; +pub mod secs; diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs new file mode 100644 index 00000000..9e304eda --- /dev/null +++ b/src/serde/duration/opt_ms.rs @@ -0,0 +1,90 @@ +//! De-/serialization functions for `Option` objects represented as milliseconds. +//! Delegates to `js_int::UInt` to ensure integer size is within bounds. + +use std::{convert::TryFrom, time::Duration}; + +use js_int::UInt; +use serde::{ + de::{Deserialize, Deserializer}, + ser::{Error, Serialize, Serializer}, +}; + +/// Serialize an Option. +/// Will fail if integer is greater than the maximum integer that can be +/// unambiguously represented by an f64. +pub fn serialize(opt_duration: &Option, serializer: S) -> Result +where + S: Serializer, +{ + match opt_duration { + Some(duration) => match UInt::try_from(duration.as_millis()) { + Ok(uint) => uint.serialize(serializer), + Err(err) => Err(S::Error::custom(err)), + }, + None => serializer.serialize_none(), + } +} + +/// Deserializes an Option. +/// Will fail if integer is greater than the maximum integer that can be +/// unambiguously represented by an f64. +pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + Ok(Option::::deserialize(deserializer)? + .map(|millis| Duration::from_millis(millis.into()))) +} + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + use serde_json::json; + use std::time::Duration; + + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] + struct DurationTest { + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, with = "crate::serde::duration::opt_ms")] + timeout: Option, + } + + #[test] + fn test_deserialize_some_duration_as_milliseconds() { + let json = json!({ "timeout": 3000 }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + DurationTest { + timeout: Some(Duration::from_millis(3000)) + }, + ); + } + + #[test] + fn test_deserialize_empty_duration_as_milliseconds() { + let json = json!({}); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + DurationTest { timeout: None }, + ); + } + + #[test] + fn test_serialize_some_duration_as_milliseconds() { + let request = DurationTest { + timeout: Some(Duration::new(2, 0)), + }; + assert_eq!( + serde_json::to_value(&request).unwrap(), + json!({ "timeout": 2000 }) + ); + } + + #[test] + fn test_serialize_empty_duration_as_milliseconds() { + let request = DurationTest { timeout: None }; + assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); + } +} diff --git a/src/serde/duration/secs.rs b/src/serde/duration/secs.rs new file mode 100644 index 00000000..1e60052a --- /dev/null +++ b/src/serde/duration/secs.rs @@ -0,0 +1,66 @@ +//! De-/serialization functions for `Option` objects represented as milliseconds. +//! Delegates to `js_int::UInt` to ensure integer size is within bounds. + +use std::{convert::TryFrom, time::Duration}; + +use js_int::UInt; +use serde::{ + de::{Deserialize, Deserializer}, + ser::{Error, Serialize, Serializer}, +}; + +/// Serializes a Duration to an integer representing seconds. +/// Will fail if integer is greater than the maximum integer that can be +/// unambiguously represented by an f64. +pub fn serialize(duration: &Duration, serializer: S) -> Result +where + S: Serializer, +{ + match UInt::try_from(duration.as_secs()) { + Ok(uint) => uint.serialize(serializer), + Err(err) => Err(S::Error::custom(err)), + } +} + +/// Deserializes an integer representing seconds into a Duration. +/// Will fail if integer is greater than the maximum integer that can be +/// unambiguously represented by an f64. +pub fn deserialize<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + UInt::deserialize(deserializer).map(|secs| Duration::from_secs(secs.into())) +} + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + use serde_json::json; + use std::time::Duration; + + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] + struct DurationTest { + #[serde(with = "crate::serde::duration::secs")] + timeout: Duration, + } + + #[test] + fn test_deserialize_duration_as_seconds() { + let json = json!({ "timeout": 3 }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + DurationTest { + timeout: Duration::from_secs(3) + }, + ); + } + + #[test] + fn test_serialize_duration_as_seconds() { + let test = DurationTest { + timeout: Duration::from_millis(7000), + }; + assert_eq!(serde_json::to_value(test).unwrap(), json!({ "timeout": 7 }),); + } +} From 1e3769a0f17b31a962d878a2e0a893d1b20bc6a8 Mon Sep 17 00:00:00 2001 From: "Ragotzy.devin" Date: Sat, 21 Mar 2020 22:08:08 -0400 Subject: [PATCH 230/350] impl EndpointError for Error Co-authored-by: Jonas Platte --- CHANGELOG.md | 3 ++- Cargo.toml | 4 ++-- src/error.rs | 12 ++++++++++++ src/lib.rs | 2 ++ src/r0/account/bind_3pid.rs | 2 ++ src/r0/account/change_password.rs | 2 ++ src/r0/account/deactivate.rs | 2 ++ src/r0/account/delete_3pid.rs | 2 ++ src/r0/account/get_username_availability.rs | 2 ++ src/r0/account/register.rs | 2 ++ .../request_3pid_management_token_via_email.rs | 2 ++ .../request_3pid_management_token_via_msisdn.rs | 2 ++ src/r0/account/request_openid_token.rs | 2 ++ .../request_password_change_token_via_email.rs | 2 ++ .../request_password_change_token_via_msisdn.rs | 2 ++ .../account/request_registration_token_via_email.rs | 2 ++ .../account/request_registration_token_via_msisdn.rs | 2 ++ src/r0/account/unbind_3pid.rs | 2 ++ src/r0/account/whoami.rs | 2 ++ src/r0/alias/create_alias.rs | 2 ++ src/r0/alias/delete_alias.rs | 2 ++ src/r0/alias/get_alias.rs | 2 ++ src/r0/appservice/set_room_visibility.rs | 2 ++ src/r0/capabilities/get_capabilities.rs | 2 ++ src/r0/client_exchange/send_event_to_device.rs | 2 ++ src/r0/config/get_global_account_data.rs | 2 ++ src/r0/config/get_room_account_data.rs | 2 ++ src/r0/config/set_global_account_data.rs | 2 ++ src/r0/config/set_room_account_data.rs | 2 ++ src/r0/contact/get_contacts.rs | 2 ++ src/r0/contact/request_contact_verification_token.rs | 2 ++ src/r0/context/get_context.rs | 2 ++ src/r0/device/delete_device.rs | 2 ++ src/r0/device/delete_devices.rs | 2 ++ src/r0/device/get_device.rs | 2 ++ src/r0/device/get_devices.rs | 2 ++ src/r0/device/update_device.rs | 2 ++ src/r0/directory/get_public_rooms.rs | 2 ++ src/r0/directory/get_public_rooms_filtered.rs | 2 ++ src/r0/filter/create_filter.rs | 2 ++ src/r0/filter/get_filter.rs | 2 ++ src/r0/keys/claim_keys.rs | 2 ++ src/r0/keys/get_key_changes.rs | 2 ++ src/r0/keys/get_keys.rs | 2 ++ src/r0/keys/upload_keys.rs | 2 ++ src/r0/media/create_content.rs | 2 ++ src/r0/media/get_content.rs | 2 ++ src/r0/media/get_content_as_filename.rs | 2 ++ src/r0/media/get_content_thumbnail.rs | 2 ++ src/r0/media/get_media_config.rs | 2 ++ src/r0/media/get_media_preview.rs | 2 ++ src/r0/membership/ban_user.rs | 2 ++ src/r0/membership/forget_room.rs | 2 ++ src/r0/membership/get_member_events.rs | 2 ++ src/r0/membership/invite_user.rs | 2 ++ src/r0/membership/join_room_by_id.rs | 2 ++ src/r0/membership/join_room_by_id_or_alias.rs | 2 ++ src/r0/membership/joined_members.rs | 2 ++ src/r0/membership/joined_rooms.rs | 2 ++ src/r0/membership/kick_user.rs | 2 ++ src/r0/membership/leave_room.rs | 2 ++ src/r0/membership/unban_user.rs | 2 ++ src/r0/message/create_message_event.rs | 2 ++ src/r0/message/get_message_events.rs | 2 ++ src/r0/presence/get_presence.rs | 2 ++ src/r0/presence/set_presence.rs | 2 ++ src/r0/profile/get_avatar_url.rs | 2 ++ src/r0/profile/get_display_name.rs | 2 ++ src/r0/profile/get_profile.rs | 2 ++ src/r0/profile/set_avatar_url.rs | 2 ++ src/r0/profile/set_display_name.rs | 2 ++ src/r0/push/delete_pushrule.rs | 2 ++ src/r0/push/get_notifications.rs | 2 ++ src/r0/push/get_pushers.rs | 2 ++ src/r0/push/get_pushrule.rs | 2 ++ src/r0/push/get_pushrule_actions.rs | 2 ++ src/r0/push/get_pushrule_enabled.rs | 2 ++ src/r0/push/get_pushrules_all.rs | 2 ++ src/r0/push/get_pushrules_global_scope.rs | 2 ++ src/r0/push/set_pusher.rs | 2 ++ src/r0/push/set_pushrule.rs | 2 ++ src/r0/push/set_pushrule_actions.rs | 2 ++ src/r0/push/set_pushrule_enabled.rs | 2 ++ src/r0/read_marker/set_read_marker.rs | 2 ++ src/r0/receipt/create_receipt.rs | 2 ++ src/r0/redact/redact_event.rs | 2 ++ src/r0/room/create_room.rs | 2 ++ src/r0/room/get_room_event.rs | 2 ++ src/r0/room/report_content.rs | 2 ++ src/r0/room/upgrade_room.rs | 2 ++ src/r0/search/search_events.rs | 2 ++ src/r0/server/get_user_info.rs | 2 ++ src/r0/session/get_login_types.rs | 2 ++ src/r0/session/login.rs | 2 ++ src/r0/session/logout.rs | 2 ++ src/r0/session/logout_all.rs | 2 ++ src/r0/session/sso_login.rs | 2 ++ src/r0/state/create_state_event_for_empty_key.rs | 2 ++ src/r0/state/create_state_event_for_key.rs | 2 ++ src/r0/state/get_state_events.rs | 2 ++ src/r0/state/get_state_events_for_empty_key.rs | 2 ++ src/r0/state/get_state_events_for_key.rs | 2 ++ src/r0/sync/sync_events.rs | 2 ++ src/r0/tag/create_tag.rs | 2 ++ src/r0/tag/delete_tag.rs | 2 ++ src/r0/tag/get_tags.rs | 2 ++ src/r0/thirdparty/get_location_for_protocol.rs | 2 ++ src/r0/thirdparty/get_location_for_room_alias.rs | 2 ++ src/r0/thirdparty/get_protocol.rs | 2 ++ src/r0/thirdparty/get_protocols.rs | 2 ++ src/r0/thirdparty/get_user_for_protocol.rs | 2 ++ src/r0/thirdparty/get_user_for_user_id.rs | 2 ++ src/r0/typing/create_typing_event.rs | 2 ++ src/r0/user_directory/search_users.rs | 2 ++ src/r0/voip/get_turn_server_info.rs | 2 ++ src/unversioned/discover_homeserver.rs | 2 ++ src/unversioned/get_supported_versions.rs | 2 ++ 117 files changed, 244 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da68bfe2..1b657e04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Improvements: * Add an `Error` type that represents the well-known errors in the client-server API + * the response deserialization code will try to create an instance of this type from http responses that indicate an error * Add OpenID token request endpoint. * Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) * Add endpoints to retrieve account_data (introduced in r0.5.0) @@ -14,7 +15,7 @@ Improvements: Breaking changes: -* Update ruma-api to 0.14.0 +* Update ruma-api to 0.15.0 * Fix `r0::session::get_login_types` * Add `allow_remote` parameter to `r0::media::get_content` * Add missing parameters for `r0::room::create_room` diff --git a/Cargo.toml b/Cargo.toml index 1b45821c..3b152118 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,10 @@ edition = "2018" [dependencies] http = "0.2.0" js_int = { version = "0.1.3", features = ["serde"] } -ruma-api = "0.14.0" +ruma-api = "0.15.0-dev.1" ruma-events = "0.17.0" ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.48" -strum = { version = "0.17.1", features = ["derive"] } +strum = { version = "0.18.0", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } diff --git a/src/error.rs b/src/error.rs index b7569d4d..999f40aa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ //! Errors that can be sent from the homeserver. +use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; /// An enum for the error kind. Items may contain additional information. @@ -117,6 +118,17 @@ pub struct Error { pub status_code: http::StatusCode, } +impl EndpointError for Error { + fn try_from_response( + response: http::Response>, + ) -> Result { + match serde_json::from_slice::(response.body()) { + Ok(error_body) => Ok(error_body.into_error(response.status())), + Err(de_error) => Err(ResponseDeserializationError::new(de_error, response)), + } + } +} + impl From for ErrorBody { fn from(error: Error) -> Self { Self { diff --git a/src/lib.rs b/src/lib.rs index 9d8e94f7..7c2ed9c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,3 +13,5 @@ pub mod r0; pub mod unversioned; mod serde; + +pub use error::Error; diff --git a/src/r0/account/bind_3pid.rs b/src/r0/account/bind_3pid.rs index e8603f6e..81bd7c46 100644 --- a/src/r0/account/bind_3pid.rs +++ b/src/r0/account/bind_3pid.rs @@ -26,4 +26,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index 96989561..abb83411 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -22,4 +22,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 173f9705..33af8c3a 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -28,4 +28,6 @@ ruma_api! { /// Result of unbind operation. pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } + + error: crate::Error } diff --git a/src/r0/account/delete_3pid.rs b/src/r0/account/delete_3pid.rs index 4af420b6..ad95fd7b 100644 --- a/src/r0/account/delete_3pid.rs +++ b/src/r0/account/delete_3pid.rs @@ -30,4 +30,6 @@ ruma_api! { pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } + error: crate::Error + } diff --git a/src/r0/account/get_username_availability.rs b/src/r0/account/get_username_availability.rs index c2fc34ff..ffe1be74 100644 --- a/src/r0/account/get_username_availability.rs +++ b/src/r0/account/get_username_availability.rs @@ -23,4 +23,6 @@ ruma_api! { /// This should always be true when the server replies with 200 OK. pub available: bool } + + error: crate::Error } diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 3ab0a9c5..76b1fe6e 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -73,6 +73,8 @@ ruma_api! { /// Will be the same as the corresponding parameter in the request, if one was specified. pub device_id: DeviceId, } + + error: crate::Error } /// The kind of account being registered. diff --git a/src/r0/account/request_3pid_management_token_via_email.rs b/src/r0/account/request_3pid_management_token_via_email.rs index 5485c1fa..dc6ceb7e 100644 --- a/src/r0/account/request_3pid_management_token_via_email.rs +++ b/src/r0/account/request_3pid_management_token_via_email.rs @@ -38,4 +38,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/request_3pid_management_token_via_msisdn.rs b/src/r0/account/request_3pid_management_token_via_msisdn.rs index 0d0ef810..f7e04125 100644 --- a/src/r0/account/request_3pid_management_token_via_msisdn.rs +++ b/src/r0/account/request_3pid_management_token_via_msisdn.rs @@ -40,4 +40,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs index b3b96bcc..637524a5 100644 --- a/src/r0/account/request_openid_token.rs +++ b/src/r0/account/request_openid_token.rs @@ -33,6 +33,8 @@ ruma_api! { #[serde(with = "crate::serde::duration::secs")] pub expires_in: Duration, } + + error: crate::Error } /// Access token types. diff --git a/src/r0/account/request_password_change_token_via_email.rs b/src/r0/account/request_password_change_token_via_email.rs index 0ddbbf77..ae7096c6 100644 --- a/src/r0/account/request_password_change_token_via_email.rs +++ b/src/r0/account/request_password_change_token_via_email.rs @@ -38,4 +38,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/request_password_change_token_via_msisdn.rs b/src/r0/account/request_password_change_token_via_msisdn.rs index 35eaf27f..40f865a7 100644 --- a/src/r0/account/request_password_change_token_via_msisdn.rs +++ b/src/r0/account/request_password_change_token_via_msisdn.rs @@ -34,4 +34,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/request_registration_token_via_email.rs b/src/r0/account/request_registration_token_via_email.rs index 2b10eafc..38468bfd 100644 --- a/src/r0/account/request_registration_token_via_email.rs +++ b/src/r0/account/request_registration_token_via_email.rs @@ -38,4 +38,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/request_registration_token_via_msisdn.rs b/src/r0/account/request_registration_token_via_msisdn.rs index dc8dfa6d..cce91ba7 100644 --- a/src/r0/account/request_registration_token_via_msisdn.rs +++ b/src/r0/account/request_registration_token_via_msisdn.rs @@ -40,4 +40,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option } + + error: crate::Error } diff --git a/src/r0/account/unbind_3pid.rs b/src/r0/account/unbind_3pid.rs index d493a179..fec859cb 100644 --- a/src/r0/account/unbind_3pid.rs +++ b/src/r0/account/unbind_3pid.rs @@ -29,4 +29,6 @@ ruma_api! { /// Result of unbind operation. pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } + + error: crate::Error } diff --git a/src/r0/account/whoami.rs b/src/r0/account/whoami.rs index 8ae9414f..0f4f3ea5 100644 --- a/src/r0/account/whoami.rs +++ b/src/r0/account/whoami.rs @@ -18,4 +18,6 @@ ruma_api! { /// The id of the user that owns the access token. pub user_id: String, } + + error: crate::Error } diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index 55a9e30c..9770d22e 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -22,4 +22,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index dc8dfd5f..cebc3cd7 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -20,4 +20,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index 93dca32a..d2d49fb4 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -25,4 +25,6 @@ ruma_api! { /// A list of servers that are aware of this room ID. pub servers: Vec, } + + error: crate::Error } diff --git a/src/r0/appservice/set_room_visibility.rs b/src/r0/appservice/set_room_visibility.rs index ea188fca..5df0c5d7 100644 --- a/src/r0/appservice/set_room_visibility.rs +++ b/src/r0/appservice/set_room_visibility.rs @@ -27,4 +27,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs index b657e207..9345280c 100644 --- a/src/r0/capabilities/get_capabilities.rs +++ b/src/r0/capabilities/get_capabilities.rs @@ -21,6 +21,8 @@ ruma_api! { /// The capabilities the server supports pub capabilities: Capabilities, } + + error: crate::Error } /// Contains information about all the capabilities that the server supports. diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index 0813ab3b..afef7244 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -33,4 +33,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs index b5a01559..611781c8 100644 --- a/src/r0/config/get_global_account_data.rs +++ b/src/r0/config/get_global_account_data.rs @@ -29,4 +29,6 @@ ruma_api! { #[wrap_incoming(with EventResult)] pub account_data: only::Event, } + + error: crate::Error } diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs index dc76dd0e..7c79bad3 100644 --- a/src/r0/config/get_room_account_data.rs +++ b/src/r0/config/get_room_account_data.rs @@ -32,4 +32,6 @@ ruma_api! { #[wrap_incoming(with EventResult)] pub account_data: only::Event, } + + error: crate::Error } diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index 0c9a4751..363f7f6d 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -31,4 +31,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 86e3c343..82cc64c4 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -34,4 +34,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 5c7837c6..a67b2994 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -21,6 +21,8 @@ ruma_api! { /// account. pub threepids: Vec, } + + error: crate::Error } /// An identifier external to Matrix. diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index eb12902c..ef8e4903 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -26,4 +26,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index c0f753d3..dc6ff9a1 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -56,4 +56,6 @@ ruma_api! { #[wrap_incoming(only::StateEvent with EventResult)] pub state: Vec, } + + error: crate::Error } diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs index 478a7064..b99b8592 100644 --- a/src/r0/device/delete_device.rs +++ b/src/r0/device/delete_device.rs @@ -24,4 +24,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/delete_devices.rs index 3ce01871..ef74419a 100644 --- a/src/r0/device/delete_devices.rs +++ b/src/r0/device/delete_devices.rs @@ -24,4 +24,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs index 0b17c6b8..7095162b 100644 --- a/src/r0/device/get_device.rs +++ b/src/r0/device/get_device.rs @@ -25,4 +25,6 @@ ruma_api! { #[ruma_api(body)] pub device: Device, } + + error: crate::Error } diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs index 4419d369..b9f8d474 100644 --- a/src/r0/device/get_devices.rs +++ b/src/r0/device/get_devices.rs @@ -18,4 +18,6 @@ ruma_api! { response { devices: Vec, } + + error: crate::Error } diff --git a/src/r0/device/update_device.rs b/src/r0/device/update_device.rs index 9d4328ff..239dd07d 100644 --- a/src/r0/device/update_device.rs +++ b/src/r0/device/update_device.rs @@ -24,4 +24,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 2f565cda..c7a54495 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -42,4 +42,6 @@ ruma_api! { /// An estimate on the total number of public rooms, if the server has an estimate. pub total_room_count_estimate: Option, } + + error: crate::Error } diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index b63b0347..95d4d152 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -44,6 +44,8 @@ ruma_api! { /// An estimate on the total number of public rooms, if the server has an estimate. pub total_room_count_estimate: Option, } + + error: crate::Error } /// A filter for public rooms lists diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs index e6486860..b11d324c 100644 --- a/src/r0/filter/create_filter.rs +++ b/src/r0/filter/create_filter.rs @@ -30,4 +30,6 @@ ruma_api! { /// The ID of the filter that was created. pub filter_id: String, } + + error: crate::Error } diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index e074b15c..0209d6c3 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -29,4 +29,6 @@ ruma_api! { #[ruma_api(body)] pub filter: FilterDefinition, } + + error: crate::Error } diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 3b14c0a2..0275fd1b 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -39,4 +39,6 @@ ruma_api! { /// One-time keys for the queried devices. pub one_time_keys: HashMap>>, } + + error: crate::Error } diff --git a/src/r0/keys/get_key_changes.rs b/src/r0/keys/get_key_changes.rs index f8b8c22a..fb979f8d 100644 --- a/src/r0/keys/get_key_changes.rs +++ b/src/r0/keys/get_key_changes.rs @@ -33,4 +33,6 @@ ruma_api! { /// encrypted rooms they previously shared with the user. pub left: Vec } + + error: crate::Error } diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index 526a3359..b6049a39 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -43,4 +43,6 @@ ruma_api! { /// Information on the queried devices. pub device_keys: HashMap>, } + + error: crate::Error } diff --git a/src/r0/keys/upload_keys.rs b/src/r0/keys/upload_keys.rs index 64b692ac..d99074b6 100644 --- a/src/r0/keys/upload_keys.rs +++ b/src/r0/keys/upload_keys.rs @@ -32,4 +32,6 @@ ruma_api! { /// type currently held on the server for this device. pub one_time_key_counts: HashMap } + + error: crate::Error } diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index 2a9f8eea..959e8611 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -29,4 +29,6 @@ ruma_api! { /// The MXC URI for the uploaded content. pub content_uri: String, } + + error: crate::Error } diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index accb0169..22ec5d2f 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -36,4 +36,6 @@ ruma_api! { #[ruma_api(header = CONTENT_DISPOSITION)] pub content_disposition: String, } + + error: crate::Error } diff --git a/src/r0/media/get_content_as_filename.rs b/src/r0/media/get_content_as_filename.rs index 140301ea..f97692d1 100644 --- a/src/r0/media/get_content_as_filename.rs +++ b/src/r0/media/get_content_as_filename.rs @@ -39,4 +39,6 @@ ruma_api! { #[ruma_api(header = CONTENT_DISPOSITION)] pub content_disposition: String, } + + error: crate::Error } diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 532f153f..567631d9 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -57,4 +57,6 @@ ruma_api! { #[ruma_api(body)] pub file: Vec, } + + error: crate::Error } diff --git a/src/r0/media/get_media_config.rs b/src/r0/media/get_media_config.rs index 84008948..ff4aba2a 100644 --- a/src/r0/media/get_media_config.rs +++ b/src/r0/media/get_media_config.rs @@ -20,4 +20,6 @@ ruma_api! { #[serde(rename = "m.upload.size")] pub upload_size: UInt, } + + error: crate::Error } diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index c2fcdae8..13dd4a5c 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -31,4 +31,6 @@ ruma_api! { #[ruma_api(body)] pub data: Option, } + + error: crate::Error } diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs index 01f6636c..20ccacbc 100644 --- a/src/r0/membership/ban_user.rs +++ b/src/r0/membership/ban_user.rs @@ -25,4 +25,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs index 360a4a51..ffabe3cd 100644 --- a/src/r0/membership/forget_room.rs +++ b/src/r0/membership/forget_room.rs @@ -20,4 +20,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/membership/get_member_events.rs b/src/r0/membership/get_member_events.rs index c4b589d2..bddbf71d 100644 --- a/src/r0/membership/get_member_events.rs +++ b/src/r0/membership/get_member_events.rs @@ -25,4 +25,6 @@ ruma_api! { #[wrap_incoming(MemberEvent with EventResult)] pub chunk: Vec } + + error: crate::Error } diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index bac550e8..0d0de7bf 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -32,6 +32,8 @@ ruma_api! { } response {} + + error: crate::Error } /// Distinguishes between invititations by Matrix or third party identifiers. diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs index 81fdca02..6555f6fc 100644 --- a/src/r0/membership/join_room_by_id.rs +++ b/src/r0/membership/join_room_by_id.rs @@ -29,4 +29,6 @@ ruma_api! { /// The room that the user joined. pub room_id: RoomId, } + + error: crate::Error } diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index bd0bf5e8..1dfd2f68 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -29,4 +29,6 @@ ruma_api! { /// The room that the user joined. pub room_id: RoomId, } + + error: crate::Error } diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index 614c0809..e4727d27 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -27,6 +27,8 @@ ruma_api! { /// the ID of each room in which the user has joined membership. pub joined: HashMap, } + + error: crate::Error } // TODO: Find out whether display_name and avatar_url are optional diff --git a/src/r0/membership/joined_rooms.rs b/src/r0/membership/joined_rooms.rs index c1266525..e9f84431 100644 --- a/src/r0/membership/joined_rooms.rs +++ b/src/r0/membership/joined_rooms.rs @@ -20,4 +20,6 @@ ruma_api! { /// the ID of each room in which the user has joined membership. pub joined_rooms: Vec, } + + error: crate::Error } diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs index 1d70a8e0..d9276324 100644 --- a/src/r0/membership/kick_user.rs +++ b/src/r0/membership/kick_user.rs @@ -25,4 +25,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs index 50e2a398..d9487759 100644 --- a/src/r0/membership/leave_room.rs +++ b/src/r0/membership/leave_room.rs @@ -20,4 +20,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index 20eda03f..27bd9e93 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -22,4 +22,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index da5f2f76..4849641d 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -38,4 +38,6 @@ ruma_api! { /// A unique identifier for the event. pub event_id: EventId, } + + error: crate::Error } diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index c7851020..cd8fa749 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -61,6 +61,8 @@ ruma_api! { /// The token the pagination ends at. pub end: String, } + + error: crate::Error } /// The direction to return events from. diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 2a32e1a4..9e344566 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -36,4 +36,6 @@ ruma_api! { /// The user's presence state. pub presence: PresenceState, } + + error: crate::Error } diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs index 5d0aa325..b295b5a5 100644 --- a/src/r0/presence/set_presence.rs +++ b/src/r0/presence/set_presence.rs @@ -26,4 +26,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs index 8f91296c..d6fa0cb5 100644 --- a/src/r0/profile/get_avatar_url.rs +++ b/src/r0/profile/get_avatar_url.rs @@ -24,4 +24,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option } + + error: crate::Error } diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs index 47d033a4..9f4aa150 100644 --- a/src/r0/profile/get_display_name.rs +++ b/src/r0/profile/get_display_name.rs @@ -24,4 +24,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } + + error: crate::Error } diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index 54a2326f..2aa014b2 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -27,4 +27,6 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, } + + error: crate::Error } diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index c78edd32..6333f516 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -22,4 +22,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs index 37bf8230..93898a7e 100644 --- a/src/r0/profile/set_display_name.rs +++ b/src/r0/profile/set_display_name.rs @@ -23,4 +23,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/push/delete_pushrule.rs b/src/r0/push/delete_pushrule.rs index 8062668f..a5a35377 100644 --- a/src/r0/push/delete_pushrule.rs +++ b/src/r0/push/delete_pushrule.rs @@ -29,4 +29,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs index 781dbcdd..6774e8a2 100644 --- a/src/r0/push/get_notifications.rs +++ b/src/r0/push/get_notifications.rs @@ -47,6 +47,8 @@ ruma_api! { #[wrap_incoming(Notification)] pub notifications: Vec, } + + error: crate::Error } /// Represents a notification diff --git a/src/r0/push/get_pushers.rs b/src/r0/push/get_pushers.rs index b267c9ed..729a62e7 100644 --- a/src/r0/push/get_pushers.rs +++ b/src/r0/push/get_pushers.rs @@ -20,4 +20,6 @@ ruma_api! { /// An array containing the current pushers for the user. pub pushers: Vec } + + error: crate::Error } diff --git a/src/r0/push/get_pushrule.rs b/src/r0/push/get_pushrule.rs index c1377404..482e8dd5 100644 --- a/src/r0/push/get_pushrule.rs +++ b/src/r0/push/get_pushrule.rs @@ -33,4 +33,6 @@ ruma_api! { #[ruma_api(body)] pub rule: PushRule } + + error: crate::Error } diff --git a/src/r0/push/get_pushrule_actions.rs b/src/r0/push/get_pushrule_actions.rs index ca0ad899..0fd7b048 100644 --- a/src/r0/push/get_pushrule_actions.rs +++ b/src/r0/push/get_pushrule_actions.rs @@ -32,4 +32,6 @@ ruma_api! { /// The actions to perform for this rule. pub actions: Vec } + + error: crate::Error } diff --git a/src/r0/push/get_pushrule_enabled.rs b/src/r0/push/get_pushrule_enabled.rs index b0800888..ae9fcfbf 100644 --- a/src/r0/push/get_pushrule_enabled.rs +++ b/src/r0/push/get_pushrule_enabled.rs @@ -32,4 +32,6 @@ ruma_api! { /// Whether the push rule is enabled or not. pub enabled: bool } + + error: crate::Error } diff --git a/src/r0/push/get_pushrules_all.rs b/src/r0/push/get_pushrules_all.rs index 73273c25..6954811f 100644 --- a/src/r0/push/get_pushrules_all.rs +++ b/src/r0/push/get_pushrules_all.rs @@ -22,4 +22,6 @@ ruma_api! { /// The global ruleset pub global: HashMap> } + + error: crate::Error } diff --git a/src/r0/push/get_pushrules_global_scope.rs b/src/r0/push/get_pushrules_global_scope.rs index b8fdc2ff..fbefecfc 100644 --- a/src/r0/push/get_pushrules_global_scope.rs +++ b/src/r0/push/get_pushrules_global_scope.rs @@ -23,4 +23,6 @@ ruma_api! { #[ruma_api(body)] pub global: HashMap>, } + + error: crate::Error } diff --git a/src/r0/push/set_pusher.rs b/src/r0/push/set_pusher.rs index 53a48bda..17c90599 100644 --- a/src/r0/push/set_pusher.rs +++ b/src/r0/push/set_pusher.rs @@ -27,4 +27,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/push/set_pushrule.rs b/src/r0/push/set_pushrule.rs index acaf16a9..f1066c3f 100644 --- a/src/r0/push/set_pushrule.rs +++ b/src/r0/push/set_pushrule.rs @@ -49,4 +49,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/push/set_pushrule_actions.rs b/src/r0/push/set_pushrule_actions.rs index 2b1a9be0..d3088b63 100644 --- a/src/r0/push/set_pushrule_actions.rs +++ b/src/r0/push/set_pushrule_actions.rs @@ -32,4 +32,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/push/set_pushrule_enabled.rs b/src/r0/push/set_pushrule_enabled.rs index 68638a83..d0a04002 100644 --- a/src/r0/push/set_pushrule_enabled.rs +++ b/src/r0/push/set_pushrule_enabled.rs @@ -32,4 +32,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/read_marker/set_read_marker.rs b/src/r0/read_marker/set_read_marker.rs index e7dbd31d..5ef38743 100644 --- a/src/r0/read_marker/set_read_marker.rs +++ b/src/r0/read_marker/set_read_marker.rs @@ -32,4 +32,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index d2e75699..9a963dc9 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -29,6 +29,8 @@ ruma_api! { } response {} + + error: crate::Error } /// The type of receipt. diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs index b79f813c..fde2818c 100644 --- a/src/r0/redact/redact_event.rs +++ b/src/r0/redact/redact_event.rs @@ -34,4 +34,6 @@ ruma_api! { /// The ID of the redacted event. pub event_id: EventId, } + + error: crate::Error } diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 5b81627c..7af56f2d 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -72,6 +72,8 @@ ruma_api! { /// The created room's ID. pub room_id: RoomId, } + + error: crate::Error } /// Extra options to be added to the `m.room.create` event. diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs index 78b4593e..29450ae4 100644 --- a/src/r0/room/get_room_event.rs +++ b/src/r0/room/get_room_event.rs @@ -28,4 +28,6 @@ ruma_api! { #[wrap_incoming(with EventResult)] pub event: all::RoomEvent, } + + error: crate::Error } diff --git a/src/r0/room/report_content.rs b/src/r0/room/report_content.rs index ecb07ec6..40ef14d1 100644 --- a/src/r0/room/report_content.rs +++ b/src/r0/room/report_content.rs @@ -28,4 +28,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/room/upgrade_room.rs b/src/r0/room/upgrade_room.rs index 91b60b01..5a152b3e 100644 --- a/src/r0/room/upgrade_room.rs +++ b/src/r0/room/upgrade_room.rs @@ -25,4 +25,6 @@ ruma_api! { /// ID of the new room. pub replacement_room: RoomId, } + + error: crate::Error } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index e9b74a9f..441cb58e 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -35,6 +35,8 @@ ruma_api! { #[wrap_incoming] pub search_categories: ResultCategories, } + + error: crate::Error } /// Categories of events that can be searched for. diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index c5a59d64..1cb6aef2 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -29,6 +29,8 @@ ruma_api! { /// A map of the user's device identifiers to information about that device. pub devices: HashMap, } + + error: crate::Error } /// Information about a connection in a user session. diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs index 764a3b25..8e323a08 100644 --- a/src/r0/session/get_login_types.rs +++ b/src/r0/session/get_login_types.rs @@ -19,6 +19,8 @@ ruma_api! { /// The homeserver's supported login types. pub flows: Vec } + + error: crate::Error } /// An authentication mechanism. diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index d69fbe42..ab7af74d 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -53,6 +53,8 @@ ruma_api! { /// If present, clients SHOULD use the provided object to reconfigure themselves. pub well_known: Option, } + + error: crate::Error } /// Identification information for the user. diff --git a/src/r0/session/logout.rs b/src/r0/session/logout.rs index 5f3b5090..1c33d716 100644 --- a/src/r0/session/logout.rs +++ b/src/r0/session/logout.rs @@ -15,4 +15,6 @@ ruma_api! { request {} response {} + + error: crate::Error } diff --git a/src/r0/session/logout_all.rs b/src/r0/session/logout_all.rs index b8613c05..b70493b9 100644 --- a/src/r0/session/logout_all.rs +++ b/src/r0/session/logout_all.rs @@ -15,4 +15,6 @@ ruma_api! { request {} response {} + + error: crate::Error } diff --git a/src/r0/session/sso_login.rs b/src/r0/session/sso_login.rs index af6c42d9..b043698d 100644 --- a/src/r0/session/sso_login.rs +++ b/src/r0/session/sso_login.rs @@ -25,4 +25,6 @@ ruma_api! { #[ruma_api(header = LOCATION)] pub location: String, } + + error: crate::Error } diff --git a/src/r0/state/create_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs index 935d473f..e0c0decb 100644 --- a/src/r0/state/create_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -31,4 +31,6 @@ ruma_api! { /// A unique identifier for the event. pub event_id: EventId, } + + error: crate::Error } diff --git a/src/r0/state/create_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs index c77e9ad7..d377cb98 100644 --- a/src/r0/state/create_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -34,4 +34,6 @@ ruma_api! { /// A unique identifier for the event. pub event_id: EventId, } + + error: crate::Error } diff --git a/src/r0/state/get_state_events.rs b/src/r0/state/get_state_events.rs index 3b81e3d4..d45ddd43 100644 --- a/src/r0/state/get_state_events.rs +++ b/src/r0/state/get_state_events.rs @@ -28,4 +28,6 @@ ruma_api! { #[wrap_incoming(StateEvent with EventResult)] pub room_state: Vec, } + + error: crate::Error } diff --git a/src/r0/state/get_state_events_for_empty_key.rs b/src/r0/state/get_state_events_for_empty_key.rs index 88a0554d..ae8a3619 100644 --- a/src/r0/state/get_state_events_for_empty_key.rs +++ b/src/r0/state/get_state_events_for_empty_key.rs @@ -29,4 +29,6 @@ ruma_api! { #[ruma_api(body)] pub content: Value, } + + error: crate::Error } diff --git a/src/r0/state/get_state_events_for_key.rs b/src/r0/state/get_state_events_for_key.rs index 085b334c..815980b3 100644 --- a/src/r0/state/get_state_events_for_key.rs +++ b/src/r0/state/get_state_events_for_key.rs @@ -32,4 +32,6 @@ ruma_api! { #[ruma_api(body)] pub content: Value, } + + error: crate::Error } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 4eb454d1..dcf9c28a 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -66,6 +66,8 @@ ruma_api! { #[wrap_incoming] pub to_device: ToDevice, } + + error: crate::Error } /// Whether to set presence or not during sync. diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs index 4aef78dc..e0337918 100644 --- a/src/r0/tag/create_tag.rs +++ b/src/r0/tag/create_tag.rs @@ -30,4 +30,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs index ffe3adbe..633903d9 100644 --- a/src/r0/tag/delete_tag.rs +++ b/src/r0/tag/delete_tag.rs @@ -26,4 +26,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index a9448802..14e30112 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -28,4 +28,6 @@ ruma_api! { #[wrap_incoming(with EventResult)] pub tags: TagEventContent, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_location_for_protocol.rs b/src/r0/thirdparty/get_location_for_protocol.rs index 4ae94589..7cf5633c 100644 --- a/src/r0/thirdparty/get_location_for_protocol.rs +++ b/src/r0/thirdparty/get_location_for_protocol.rs @@ -31,4 +31,6 @@ ruma_api! { #[ruma_api(body)] pub locations: Vec, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_location_for_room_alias.rs b/src/r0/thirdparty/get_location_for_room_alias.rs index a9c8a4e2..b1038afc 100644 --- a/src/r0/thirdparty/get_location_for_room_alias.rs +++ b/src/r0/thirdparty/get_location_for_room_alias.rs @@ -26,4 +26,6 @@ ruma_api! { #[ruma_api(body)] pub locations: Vec, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_protocol.rs b/src/r0/thirdparty/get_protocol.rs index ea94b348..61cf67fb 100644 --- a/src/r0/thirdparty/get_protocol.rs +++ b/src/r0/thirdparty/get_protocol.rs @@ -25,4 +25,6 @@ ruma_api! { #[ruma_api(body)] pub protocol: Protocol, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_protocols.rs b/src/r0/thirdparty/get_protocols.rs index c17124e4..e563ab61 100644 --- a/src/r0/thirdparty/get_protocols.rs +++ b/src/r0/thirdparty/get_protocols.rs @@ -23,4 +23,6 @@ ruma_api! { #[ruma_api(body)] pub protocols: HashMap, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_user_for_protocol.rs b/src/r0/thirdparty/get_user_for_protocol.rs index 4f34e7dc..557f1232 100644 --- a/src/r0/thirdparty/get_user_for_protocol.rs +++ b/src/r0/thirdparty/get_user_for_protocol.rs @@ -31,4 +31,6 @@ ruma_api! { #[ruma_api(body)] pub users: Vec, } + + error: crate::Error } diff --git a/src/r0/thirdparty/get_user_for_user_id.rs b/src/r0/thirdparty/get_user_for_user_id.rs index 10653609..476f69c3 100644 --- a/src/r0/thirdparty/get_user_for_user_id.rs +++ b/src/r0/thirdparty/get_user_for_user_id.rs @@ -26,4 +26,6 @@ ruma_api! { #[ruma_api(body)] pub users: Vec, } + + error: crate::Error } diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index 3dad3ef2..d24dc82c 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -31,4 +31,6 @@ ruma_api! { } response {} + + error: crate::Error } diff --git a/src/r0/user_directory/search_users.rs b/src/r0/user_directory/search_users.rs index 403e3eed..a0b54cee 100644 --- a/src/r0/user_directory/search_users.rs +++ b/src/r0/user_directory/search_users.rs @@ -31,6 +31,8 @@ ruma_api! { /// Indicates if the result list has been truncated by the limit. pub limited: bool, } + + error: crate::Error } /// User data as result of a search. diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 91ce8597..5e83b58f 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -27,4 +27,6 @@ ruma_api! { /// The username to use. pub username: String, } + + error: crate::Error } diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index 96b66769..3c3dd557 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -39,4 +39,6 @@ ruma_api! { #[serde(rename = "m.identity_server")] pub identity_server: Option, } + + error: crate::Error } diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index fdf98eb5..b8fc8308 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -23,4 +23,6 @@ ruma_api! { #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub unstable_features: HashMap } + + error: crate::Error } From ea94bab93e641752d2bb84f4fe275b680dc1bccd Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 27 Mar 2020 19:54:04 +0530 Subject: [PATCH 231/350] Remove outdated comment --- src/r0/membership.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 37880957..03af3e75 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -18,9 +18,6 @@ use serde::{Deserialize, Serialize}; use crate::r0::thirdparty::Medium; -// TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } -// for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? - /// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// identity which has been invited to the room. #[derive(Clone, Debug, Deserialize, Serialize)] From 57f5e8d66168a54128426c8e34b26fa78f739c3e Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 27 Mar 2020 21:10:40 +0530 Subject: [PATCH 232/350] Add missing query parameters to members list endpoint --- src/r0/membership/get_member_events.rs | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/r0/membership/get_member_events.rs b/src/r0/membership/get_member_events.rs index bddbf71d..f4fb29bd 100644 --- a/src/r0/membership/get_member_events.rs +++ b/src/r0/membership/get_member_events.rs @@ -1,8 +1,9 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-members) +//! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members) use ruma_api::ruma_api; use ruma_events::{room::member::MemberEvent, EventResult}; use ruma_identifiers::RoomId; +use serde::{Deserialize, Serialize}; ruma_api! { metadata { @@ -18,6 +19,25 @@ ruma_api! { /// The room to get the member events for. #[ruma_api(path)] pub room_id: RoomId, + + /// The point in time (pagination token) to return members for in the room. This token can + /// be obtained from a prev_batch token returned for each room by the sync API. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub at: Option, + + /// The kind of memberships to filter for. Defaults to no filtering if unspecified. When + /// specified alongside not_membership, the two parameters create an 'or' condition: either + /// the membership is the same as membership or is not the same as not_membership. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub membership: Option, + + /// The kind of memberships to *exclude* from the results. Defaults to no filtering if + /// unspecified. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub not_membership: Option, } response { @@ -28,3 +48,17 @@ ruma_api! { error: crate::Error } + +/// The kind of membership events to filter for. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum MembershipEventFilter { + /// The user has joined. + Join, + /// The user has been invited. + Invite, + /// The user has left. + Leave, + /// The user has been banned. + Ban, +} From 2cced78edf077653d796a82dadf5bb84a0795b64 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 17 Mar 2020 20:01:56 -0500 Subject: [PATCH 233/350] Update sync endpoint --- src/r0/sync/sync_events.rs | 66 +++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index dcf9c28a..ab70df1e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-sync) +//! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-sync) use std::{collections::HashMap, time::Duration}; @@ -17,7 +17,10 @@ use ruma_events::{ use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; -use crate::r0::filter::FilterDefinition; +use crate::r0::{ + filter::FilterDefinition, + keys::KeyAlgorithm, +}; ruma_api! { metadata { @@ -35,6 +38,8 @@ ruma_api! { #[ruma_api(query)] pub filter: Option, /// A point in time to continue a sync from. + /// Should be a token from the `next_batch` field of a previous `/sync` + /// request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub since: Option, @@ -65,6 +70,14 @@ ruma_api! { /// Messages sent dirrectly between devices. #[wrap_incoming] pub to_device: ToDevice, + /// Information on E2E device updates. + /// Only present on an incremental sync. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_lists: Option, + /// For each key algorithm, the number of unclaimed one-time keys + /// currently held on the server for a device. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_one_time_keys_count: Option> } error: crate::Error @@ -72,10 +85,14 @@ ruma_api! { /// Whether to set presence or not during sync. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] pub enum SetPresence { /// Do not set the presence of the user calling this API. - #[serde(rename = "offline")] Offline, + /// Mark client as online explicitly. Assumed by default. + Online, + /// Mark client as being idle. + Unavailable, } /// A filter represented either as its full JSON definition or the ID of a saved filter. @@ -150,11 +167,17 @@ pub struct LeftRoom { /// The state updates for the room up to the start of the timeline. #[wrap_incoming] pub state: State, + /// The private data that this user has attached to this room. + #[wrap_incoming] + pub account_data: AccountData, } /// Updates to joined rooms. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct JoinedRoom { + /// Information about the room which clients may need to correctly render it + /// to users. + pub summary: RoomSummary, /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, /// The timeline of messages and state changes in the room. @@ -189,10 +212,12 @@ pub struct UnreadNotificationsCount { #[derive(Clone, Debug, Serialize, Outgoing)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. - pub limited: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub limited: Option, /// A token that can be supplied to to the `from` parameter of the /// `/rooms/{roomId}/messages` endpoint. - pub prev_batch: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, /// A list of events. #[wrap_incoming(RoomEvent with EventResult)] pub events: Vec, @@ -223,6 +248,23 @@ pub struct Ephemeral { pub events: Vec, } +/// Information about room for rendering to clients. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomSummary { + /// Users which can be used to generate a room name if the room does not have + /// one. Required if room name or canonical aliases are not set or empty. + #[serde(skip_serializing_if = "Vec::is_empty")] + pub heroes: Vec, + /// Number of users whose membership status is `join`. + /// Required if field has changed since last sync; otherwise, it may be + /// omitted. + pub joined_member_count: Option, + /// Number of users whose membership status is `invite`. + /// Required if field has changed since last sync; otherwise, it may be + /// omitted. + pub invited_member_count: Option, +} + /// Updates to the rooms that the user has been invited to. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct InvitedRoom { @@ -254,3 +296,17 @@ pub struct ToDevice { #[wrap_incoming(AnyToDeviceEvent with EventResult)] pub events: Vec, } + +/// Information on E2E device udpates. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct DeviceLists { + /// List of users who have updated their device identity keys or who now + /// share an encrypted room with the client since the previous sync + #[serde(skip_serializing_if = "Vec::is_empty")] + pub changed: Vec, + /// List of users who no longer share encrypted rooms since the previous sync + /// response. + #[serde(skip_serializing_if = "Vec::is_empty")] + pub left: Vec, + +} \ No newline at end of file From e607587a67fa0b5b23845c2f81e8a6f993db8ed1 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 17 Mar 2020 21:05:04 -0500 Subject: [PATCH 234/350] Format code --- src/r0/sync/sync_events.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index ab70df1e..33ceb155 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -17,10 +17,7 @@ use ruma_events::{ use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; -use crate::r0::{ - filter::FilterDefinition, - keys::KeyAlgorithm, -}; +use crate::r0::{filter::FilterDefinition, keys::KeyAlgorithm}; ruma_api! { metadata { @@ -308,5 +305,4 @@ pub struct DeviceLists { /// response. #[serde(skip_serializing_if = "Vec::is_empty")] pub left: Vec, - -} \ No newline at end of file +} From 78744a3a98c7494a5bb323708dc8a73e3bb71487 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 29 Mar 2020 18:40:50 +0200 Subject: [PATCH 235/350] Further refine the sync endpoint's types --- src/r0/sync/sync_events.rs | 47 ++++++++++++++++++++++++++++---------- src/serde.rs | 4 ++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 33ceb155..c6de6a98 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -17,7 +17,10 @@ use ruma_events::{ use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; -use crate::r0::{filter::FilterDefinition, keys::KeyAlgorithm}; +use crate::{ + r0::{filter::FilterDefinition, keys::KeyAlgorithm}, + serde::is_default, +}; ruma_api! { metadata { @@ -35,22 +38,22 @@ ruma_api! { #[ruma_api(query)] pub filter: Option, /// A point in time to continue a sync from. + /// /// Should be a token from the `next_batch` field of a previous `/sync` /// request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub since: Option, /// Controls whether to include the full state for all rooms the user is a member of. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "is_default")] #[ruma_api(query)] - pub full_state: Option, + pub full_state: bool, /// Controls whether the client is automatically marked as online by polling this API. - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "is_default")] #[ruma_api(query)] - pub set_presence: Option, + pub set_presence: SetPresence, /// The maximum time to poll in milliseconds before returning this request. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(with = "crate::serde::duration::opt_ms")] + #[serde(with = "crate::serde::duration::opt_ms", skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub timeout: Option, } @@ -65,23 +68,25 @@ ruma_api! { #[wrap_incoming] pub presence: Presence, /// Messages sent dirrectly between devices. + #[serde(default, skip_serializing_if = "ToDevice::is_empty")] #[wrap_incoming] pub to_device: ToDevice, /// Information on E2E device updates. + /// /// Only present on an incremental sync. #[serde(skip_serializing_if = "Option::is_none")] pub device_lists: Option, /// For each key algorithm, the number of unclaimed one-time keys /// currently held on the server for a device. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_one_time_keys_count: Option> + #[serde(skip_serializing_if = "HashMap::is_empty")] + pub device_one_time_keys_count: HashMap, } error: crate::Error } /// Whether to set presence or not during sync. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "lowercase")] pub enum SetPresence { /// Do not set the presence of the user calling this API. @@ -92,6 +97,12 @@ pub enum SetPresence { Unavailable, } +impl Default for SetPresence { + fn default() -> Self { + Self::Online + } +} + /// A filter represented either as its full JSON definition or the ID of a saved filter. #[derive(Clone, Debug, Deserialize, Serialize)] #[allow(clippy::large_enum_variant)] @@ -294,15 +305,27 @@ pub struct ToDevice { pub events: Vec, } +impl ToDevice { + fn is_empty(&self) -> bool { + self.events.is_empty() + } +} + +impl Default for IncomingToDevice { + fn default() -> Self { + Self { events: Vec::new() } + } +} + /// Information on E2E device udpates. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DeviceLists { /// List of users who have updated their device identity keys or who now /// share an encrypted room with the client since the previous sync - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub changed: Vec, /// List of users who no longer share encrypted rooms since the previous sync /// response. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub left: Vec, } diff --git a/src/serde.rs b/src/serde.rs index 4cb6139c..6ca75b9b 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -1,3 +1,7 @@ //! Modules to hold functions for de-/serializing remote types pub mod duration; + +pub fn is_default(val: &T) -> bool { + val == &T::default() +} From 67257e15e8a1c6a65be135486e941a1e67258d6d Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Tue, 17 Mar 2020 21:11:38 -0500 Subject: [PATCH 236/350] Remove stray TODO comment --- src/r0/sync/sync_events.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index c6de6a98..532fd08c 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -243,7 +243,6 @@ pub struct State { #[derive(Clone, Debug, Serialize, Outgoing)] pub struct AccountData { /// A list of events. - // TODO: Create #[wrap_incoming(NonRoomEvent with EventResult)] pub events: Vec, } From 472ab64a864b87b8c8670020eb89fad530c838cf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 29 Mar 2020 19:28:28 +0200 Subject: [PATCH 237/350] Update dependencies --- CHANGELOG.md | 1 + Cargo.toml | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b657e04..be494a1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Improvements: Breaking changes: * Update ruma-api to 0.15.0 +* Update ruma-events to 0.18.0 * Fix `r0::session::get_login_types` * Add `allow_remote` parameter to `r0::media::get_content` * Add missing parameters for `r0::room::create_room` diff --git a/Cargo.toml b/Cargo.toml index 3b152118..389f3342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,12 +13,12 @@ version = "0.6.0" edition = "2018" [dependencies] -http = "0.2.0" +http = "0.2.1" js_int = { version = "0.1.3", features = ["serde"] } -ruma-api = "0.15.0-dev.1" -ruma-events = "0.17.0" +ruma-api = "0.15.0" +ruma-events = "0.18.0" ruma-identifiers = "0.14.1" -serde = { version = "1.0.104", features = ["derive"] } -serde_json = "1.0.48" +serde = { version = "1.0.105", features = ["derive"] } +serde_json = "1.0.50" strum = { version = "0.18.0", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } From e2ba8f2d4ad4d29fb195548e0eef1cdddef7818f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 29 Mar 2020 19:28:57 +0200 Subject: [PATCH 238/350] Bump version --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be494a1a..12f75a83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [unreleased] +# 0.7.0 + Improvements: * Add an `Error` type that represents the well-known errors in the client-server API diff --git a/Cargo.toml b/Cargo.toml index 389f3342..06fccb94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.6.0" +version = "0.7.0" edition = "2018" [dependencies] From ea9b752da957082b836ab053bbf701cb2641c2f7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 29 Mar 2020 19:44:14 +0200 Subject: [PATCH 239/350] Reorder sections in change log --- CHANGELOG.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f75a83..4ec8265f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,6 @@ # 0.7.0 -Improvements: - -* Add an `Error` type that represents the well-known errors in the client-server API - * the response deserialization code will try to create an instance of this type from http responses that indicate an error -* Add OpenID token request endpoint. -* Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) -* Add endpoints to retrieve account_data (introduced in r0.5.0) -* Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` -* Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) -* Add request and response parameters for `r0::account::deactivate` -* Add `r0::session::sso_login` (introduced in r0.5.0) -* Add `filter` type for `r0::context::get_context` - Breaking changes: * Update ruma-api to 0.15.0 @@ -40,6 +27,19 @@ Breaking changes: } ``` +Improvements: + +* Add an `Error` type that represents the well-known errors in the client-server API + * the response deserialization code will try to create an instance of this type from http responses that indicate an error +* Add OpenID token request endpoint. +* Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) +* Add endpoints to retrieve account_data (introduced in r0.5.0) +* Add media endpoints: `r0::media::{get_media_config, get_media_preview, get_content_as_filename}` +* Add `unstable_features` to `unversioned::get_supported_versions` (introduced in r0.5.0) +* Add request and response parameters for `r0::account::deactivate` +* Add `r0::session::sso_login` (introduced in r0.5.0) +* Add `filter` type for `r0::context::get_context` + # 0.6.0 Breaking changes: From 09ac2404dece5328b9abba60d127ea5918342d53 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 11:56:49 +0200 Subject: [PATCH 240/350] Add a test for sync_events::Request serialization --- src/r0/sync/sync_events.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 532fd08c..9c5a8f38 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -328,3 +328,33 @@ pub struct DeviceLists { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub left: Vec, } + +#[cfg(test)] +mod tests { + use std::{convert::TryInto, time::Duration}; + + use super::{Filter, Request, SetPresence}; + + #[test] + fn serialize_sync_request() { + let req: http::Request> = Request { + filter: Some(Filter::FilterId("66696p746572".into())), + since: Some("s72594_4483_1934".into()), + full_state: true, + set_presence: SetPresence::Offline, + timeout: Some(Duration::from_millis(30000)), + } + .try_into() + .unwrap(); + + let uri = req.uri(); + let query = uri.query().unwrap(); + + assert_eq!(uri.path(), "/_matrix/client/r0/sync"); + assert!(query.contains("filter=66696p746572")); + assert!(query.contains("since=s72594_4483_1934")); + assert!(query.contains("full_state=true")); + assert!(query.contains("set_presence=offline")); + assert!(query.contains("timeout=30000")) + } +} From 3dfb500bbab42957eae7001b649a0e4adc064679 Mon Sep 17 00:00:00 2001 From: poljar Date: Fri, 3 Apr 2020 14:01:12 +0200 Subject: [PATCH 241/350] sync_events: Fix RoomSummary serde attributes * Create an empty heroes vector if the response doesn't contain it. The heroes map is strictly optional and as is deserialization might fail for the whole response unless we allow it to be optional. * Rename the room summary fields during (de)serialization. --- src/r0/sync/sync_events.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 9c5a8f38..cd5740ff 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -260,15 +260,17 @@ pub struct Ephemeral { pub struct RoomSummary { /// Users which can be used to generate a room name if the room does not have /// one. Required if room name or canonical aliases are not set or empty. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(rename = "m.heroes", default, skip_serializing_if = "Vec::is_empty")] pub heroes: Vec, /// Number of users whose membership status is `join`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. + #[serde(rename = "m.joined_member_count")] pub joined_member_count: Option, /// Number of users whose membership status is `invite`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. + #[serde(rename = "m.invited_member_count")] pub invited_member_count: Option, } From 9db26e1dda38d52cfaab4c903476fd778902282f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 14:02:12 +0200 Subject: [PATCH 242/350] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ec8265f..dc069c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Improvements: + +* Fix (de)serialization of `sync_events::RoomSummary` + # 0.7.0 Breaking changes: From 0c44e73a780566e236876a7dec6c1fa75c36405b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 18:22:52 +0200 Subject: [PATCH 243/350] Bump js_int, add regression test The version bump fixes an issue where `UInt`s or `Duration`s in the query string would fail to deserialize --- Cargo.toml | 2 +- src/r0/sync/sync_events.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 06fccb94..8258b075 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] http = "0.2.1" -js_int = { version = "0.1.3", features = ["serde"] } +js_int = { version = "0.1.4", features = ["serde"] } ruma-api = "0.15.0" ruma-events = "0.18.0" ruma-identifiers = "0.14.1" diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index cd5740ff..c7357b1b 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -359,4 +359,32 @@ mod tests { assert!(query.contains("set_presence=offline")); assert!(query.contains("timeout=30000")) } + + #[test] + fn deserialize_sync_request_with_query_params() { + let uri = http::Uri::builder() + .scheme("https") + .authority("matrix.org") + .path_and_query("/_matrix/client/r0/sync?filter=myfilter&since=myts&full_state=false&set_presence=offline&timeout=5000") + .build() + .unwrap(); + + let req: Request = http::Request::builder() + .uri(uri) + .body(Vec::::new()) + .unwrap() + .try_into() + .unwrap(); + + match req.filter { + Some(Filter::FilterId(id)) if id == "myfilter" => {} + _ => { + panic!("Not the expected filter ID."); + } + } + assert_eq!(req.since, Some("myts".into())); + assert_eq!(req.full_state, false); + assert_eq!(req.set_presence, SetPresence::Offline); + assert_eq!(req.timeout, Some(Duration::from_millis(5000))); + } } From cf40608b7821bb4c0500ceb8112613c9cb811f66 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 18:37:20 +0200 Subject: [PATCH 244/350] Add missing attribute to timeout field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … in sync_events' Request type, plus a regression test --- src/r0/sync/sync_events.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index c7357b1b..4220759e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -53,7 +53,11 @@ ruma_api! { #[ruma_api(query)] pub set_presence: SetPresence, /// The maximum time to poll in milliseconds before returning this request. - #[serde(with = "crate::serde::duration::opt_ms", skip_serializing_if = "Option::is_none")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + )] #[ruma_api(query)] pub timeout: Option, } @@ -387,4 +391,27 @@ mod tests { assert_eq!(req.set_presence, SetPresence::Offline); assert_eq!(req.timeout, Some(Duration::from_millis(5000))); } + + #[test] + fn deserialize_sync_request_without_query_params() { + let uri = http::Uri::builder() + .scheme("https") + .authority("matrix.org") + .path_and_query("/_matrix/client/r0/sync") + .build() + .unwrap(); + + let req: Request = http::Request::builder() + .uri(uri) + .body(Vec::::new()) + .unwrap() + .try_into() + .unwrap(); + + assert!(req.filter.is_none()); + assert!(req.since.is_none()); + assert_eq!(req.full_state, false); + assert_eq!(req.set_presence, SetPresence::Online); + assert!(req.timeout.is_none()); + } } From abc5b5d446fe7997182e8c731402dff7eaabb390 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 18:38:16 +0200 Subject: [PATCH 245/350] Merge serde attributes --- src/r0/keys/claim_keys.rs | 7 +++++-- src/r0/keys/get_keys.rs | 7 +++++-- src/r0/presence/get_presence.rs | 7 +++++-- src/r0/typing/create_typing_event.rs | 7 +++++-- src/serde/duration/opt_ms.rs | 7 +++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 0275fd1b..3b4dd450 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -23,8 +23,11 @@ ruma_api! { request { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default, with = "crate::serde::duration::opt_ms")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + )] pub timeout: Option, /// The keys to be claimed. diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index b6049a39..98628261 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -21,8 +21,11 @@ ruma_api! { request { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default, with = "crate::serde::duration::opt_ms")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + )] pub timeout: Option, /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 9e344566..6424435b 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -30,8 +30,11 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub currently_active: Option, /// The length of time in milliseconds since an action was performed by the user. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default, with = "crate::serde::duration::opt_ms")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + )] pub last_active_ago: Option, /// The user's presence state. pub presence: PresenceState, diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index d24dc82c..3731ad02 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -20,8 +20,11 @@ ruma_api! { #[ruma_api(path)] pub room_id: RoomId, /// The length of time in milliseconds to mark this user as typing. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default, with = "crate::serde::duration::opt_ms")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + )] pub timeout: Option, /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. pub typing: bool, diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs index 9e304eda..0704324d 100644 --- a/src/serde/duration/opt_ms.rs +++ b/src/serde/duration/opt_ms.rs @@ -44,8 +44,11 @@ mod tests { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] struct DurationTest { - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default, with = "crate::serde::duration::opt_ms")] + #[serde( + with = "crate::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] timeout: Option, } From 4782739b0fc66fcdee708a1aefa2eced92fb11db Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 18:38:51 +0200 Subject: [PATCH 246/350] Update change log --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc069c9c..dfff095f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # [unreleased] -Improvements: +Bug fixes: +* Fix deserialization of `sync_events::Request` * Fix (de)serialization of `sync_events::RoomSummary` # 0.7.0 From 041b737ca32a8d3456aac339d1db4b1bf5258aa7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 19:11:57 +0200 Subject: [PATCH 247/350] Bump version --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfff095f..d5e25598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [unreleased] +# 0.7.1 + Bug fixes: * Fix deserialization of `sync_events::Request` diff --git a/Cargo.toml b/Cargo.toml index 8258b075..66ed1ae6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.7.0" +version = "0.7.1" edition = "2018" [dependencies] From 6fba4a5617df2f739fa2c7c478b121d1a4264e39 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Apr 2020 19:12:14 +0200 Subject: [PATCH 248/350] CI: Disable IRC notifications --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ab43695..51cc2c60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,9 +31,3 @@ script: - cargo build --verbose - cargo test --verbose if: "type != push OR (tag IS blank AND branch = master)" -notifications: - email: false - irc: - channels: - - secure: "WtuFMaASfrKlPbXWg7cAzxTLSggrix/jqizB3bdGbZTWg8MR0qoa90U9St6h5ELWMc+7mQjJSky0/KXD9BOVLSlok8E12xb8H5soPMW6GjYAek4+JzUeXPYSKNYkP29ZQc26Z9P9TyN/WvJoXIQbaWfMoPmr/g3Rn4z5PyeQgp1+AC54w5zLPtLLjh+WHPYhRoCT7iAsYlx0UazEw3i+aGyN+UdogimDD9ISUKFHOWyXJGyBzFxSpAYaRESnT4I0rJo6ETBkUbEopXvTRyClOsgEk1HRb82+kVNqkampeSDZyb2aCGLbRESd16xVbcE5J2HYu59p5zc00PINMf2nApDEkN/RHERZ4w9lMaxi/fH1TMQZwoNPEd/5n1EU/SLjKi7o/kLdTKEcZyTMd7IZA+TqXjFhKHQlYouOEv742TcWz3jg5+AEhKqjkcpDZTEuNHyMAS4onHg1M9pK2rVh3xmVQ1V2iYM8yY2+73SefJzigkhtXwgnJEv6fJc8IFSPOHtEUBx2KkZps6sRwUxVz5zMgV+4t1h9l4Mt8wOSojoKSxgtAhsHj8pqPysT7vUJPhY6hzzW2nhVHd8IUt49xRNktUr9s+B7yS1Up6+84GTmPmR3lUa+dbZ1PaI2K8VVyctiA4tbkk/n+EFqXL9FY2Gh8XbaWnb7fpWHrJRuZL4=" - use_notice: true From d6e4bd9ddc90b59d45d7475f9cd5b8cf789dbf3e Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 6 Apr 2020 12:23:17 +0200 Subject: [PATCH 249/350] Fix create_room and sync_events deserialization --- src/r0/room/create_room.rs | 2 +- src/r0/sync/sync_events.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 7af56f2d..7dc1be99 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -27,7 +27,7 @@ ruma_api! { /// /// Takes precedence over events set by preset, but gets overriden by /// name and topic keys. - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub initial_state: Vec, /// A list of user IDs to invite to the room. /// diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 4220759e..455f26b3 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -82,7 +82,7 @@ ruma_api! { pub device_lists: Option, /// For each key algorithm, the number of unclaimed one-time keys /// currently held on the server for a device. - #[serde(skip_serializing_if = "HashMap::is_empty")] + #[serde(default, skip_serializing_if = "HashMap::is_empty")] pub device_one_time_keys_count: HashMap, } From fe92c2940a2db80509e9a9f162c0f68f3ec3d0a4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 6 Apr 2020 12:35:38 +0200 Subject: [PATCH 250/350] Update change log, bump version --- CHANGELOG.md | 7 +++++++ Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5e25598..570cfb60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # [unreleased] +# 0.7.2 + +Bug fixes: + +* Fix `create_room` requests without an `initial_state` field failing deserialization +* Fix `sync_events` responses without a `device_one_time_keys_count` field failing deserialization + # 0.7.1 Bug fixes: diff --git a/Cargo.toml b/Cargo.toml index 66ed1ae6..0018c5b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.7.1" +version = "0.7.2" edition = "2018" [dependencies] From dc582758e4f846b3751d84d21eb321e8eb4faf51 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Mon, 6 Apr 2020 10:28:55 -0500 Subject: [PATCH 251/350] Add server_name parameter to join_room_by_id_or_alias --- CHANGELOG.md | 4 ++++ src/r0/membership/join_room_by_id_or_alias.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 570cfb60..99bf3940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Breaking changes: + +* Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` + # 0.7.2 Bug fixes: diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index 1dfd2f68..4def0344 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-join-roomidoralias) +//! [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-join-roomidoralias) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, RoomIdOrAliasId}; @@ -19,6 +19,11 @@ ruma_api! { /// The room where the user should be invited. #[ruma_api(path)] pub room_id_or_alias: RoomIdOrAliasId, + /// The servers to attempt to join the room through. One of the servers + /// must be participating in the room. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub server_name: Vec, /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] From abcc8ec1d2955406bcc1397592c173a085a56562 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 6 Apr 2020 14:10:35 -0500 Subject: [PATCH 252/350] Update register endpoint to r0.6.0 --- CHANGELOG.md | 4 ++++ src/r0/account/register.rs | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99bf3940..cd72d8ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Breaking changes: * Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` +* Update `r0::account::register` endpoint: + * Remove `bind_email` request field (removed in r0.6.0) + * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) + * Remove deprecated `home_server` response field (removed in r0.4.0) # 0.7.2 diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 76b1fe6e..9644624b 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register) +//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register) use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; @@ -17,10 +17,6 @@ ruma_api! { } request { - /// If true, the server binds the email used for authentication - /// to the Matrix ID with the ID Server. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind_email: Option, /// The desired password for the account. /// /// Should only be empty for guest accounts. @@ -53,25 +49,28 @@ ruma_api! { pub auth: Option, /// Kind of account to register /// - /// Defaults to `User` if ommited. + /// Defaults to `User` if omitted. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, + /// If `true`, an `access_token` and `device_id` should not be returned + /// from this call, therefore preventing an automatic login. + #[serde(default, skip_serializing_if = "crate::serde::is_default")] + pub inhibit_login: bool, } response { /// An access token for the account. /// /// This access token can then be used to authorize other requests. - pub access_token: String, - /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub access_token: Option, /// The fully-qualified Matrix ID that has been registered. pub user_id: UserId, /// ID of the registered device. /// /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: DeviceId, + pub device_id: Option, } error: crate::Error From ff8427cb934e001b3c7c7d48627f30925ef89015 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 6 Apr 2020 14:39:07 -0500 Subject: [PATCH 253/350] Add auth_parameters field to AuthenticationData. --- CHANGELOG.md | 1 + src/r0/account.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd72d8ff..35ec1476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Breaking changes: * Remove `bind_email` request field (removed in r0.6.0) * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) * Remove deprecated `home_server` response field (removed in r0.4.0) +* Add `auth_parameters` to `r0::account::AuthenticationData` # 0.7.2 diff --git a/src/r0/account.rs b/src/r0/account.rs index 4064aa37..8b870bae 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -17,6 +17,8 @@ pub mod unbind_3pid; pub mod whoami; +use std::collections::BTreeMap; + use serde::{Deserialize, Serialize}; /// Additional authentication information for the user-interactive authentication API. @@ -27,6 +29,9 @@ pub struct AuthenticationData { pub kind: String, /// The value of the session key given by the homeserver. pub session: Option, + /// Parameters submitted for a particular authentication stage. + #[serde(flatten)] + pub auth_parameters: BTreeMap, } /// Additional authentication information for requestToken endpoints. From 9198a549e7bbec73d90df42ec4e6c2209e738448 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 6 Apr 2020 14:47:26 -0500 Subject: [PATCH 254/350] Add structs for User-Interactive Authentication API. --- CHANGELOG.md | 4 ++++ src/r0/account.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ec1476..57fed245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Breaking changes: * Remove deprecated `home_server` response field (removed in r0.4.0) * Add `auth_parameters` to `r0::account::AuthenticationData` +Improvements: + +* Add types for User-Interactive Authentication API: `r0::account::{UserInteractiveAuthenticationInfo, AuthenticationFlow}` + # 0.7.2 Bug fixes: diff --git a/src/r0/account.rs b/src/r0/account.rs index 8b870bae..6598d76d 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -34,6 +34,31 @@ pub struct AuthenticationData { pub auth_parameters: BTreeMap, } +/// Information about available authentication flows and status for +/// User-Interactive Authenticiation API. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct UserInteractiveAuthenticationInfo { + /// List of authentication flows available for this endpoint. + pub flows: Vec, + /// List of stages in the current flow completed by the client. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub completed: Vec, + /// Authentication parameters required for the client to complete authentication. + pub params: serde_json::Value, + /// Session key for client to use to complete authentication. + #[serde(skip_serializing_if = "Option::is_none")] + pub session: Option, +} + +/// Description of steps required to authenticate via the User-Interactive +/// Authentication API. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct AuthenticationFlow { + /// Ordered list of stages required to complete authentication. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub stages: Vec, +} + /// Additional authentication information for requestToken endpoints. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct IdentityServerInfo { From aeb4e237b7f13a068a92929fdb5c5adac4f346e1 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 6 Apr 2020 15:09:03 -0500 Subject: [PATCH 255/350] Clarify whether password is optional in registration endpoint. --- src/r0/account/register.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 9644624b..9b11340d 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -19,8 +19,8 @@ ruma_api! { request { /// The desired password for the account. /// - /// Should only be empty for guest accounts. - // TODO: the spec says nothing about when it is actually required. + /// May be empty for accounts that should not be able to log in again + /// with a password, e.g., for guest or application service accounts. #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, /// local part of the desired Matrix ID. From bcc06ddd49cca6a8c22891f3f531e4c34e5c7755 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Wed, 8 Apr 2020 16:49:59 -0500 Subject: [PATCH 256/350] Update public rooms endpoint --- CHANGELOG.md | 2 + src/r0/directory.rs | 4 +- src/r0/directory/get_public_rooms_filtered.rs | 190 +++++++++++++++++- 3 files changed, 193 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57fed245..cb2d249c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Breaking changes: * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) * Remove deprecated `home_server` response field (removed in r0.4.0) * Add `auth_parameters` to `r0::account::AuthenticationData` +* Add `room_network` parameter to `r0::directory::get_public_rooms_filtered` to + represent `include_all_networks` and `third_party_instance_id` Matrix fields. Improvements: diff --git a/src/r0/directory.rs b/src/r0/directory.rs index bd5ebff9..a0bdcc1d 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { /// Aliases of the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub aliases: Option>, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub aliases: Vec, /// The canonical alias of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] pub canonical_alias: Option, diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index 95d4d152..b3302f58 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -1,8 +1,15 @@ //! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-publicrooms) +use std::fmt; + use js_int::UInt; use ruma_api::ruma_api; -use serde::{Deserialize, Serialize}; +use serde::{ + de::{MapAccess, Visitor}, + ser::SerializeStruct, + Deserialize, Deserializer, Serialize, Serializer, +}; +use serde_json::Value; use super::PublicRoomsChunk; @@ -32,6 +39,9 @@ ruma_api! { /// Filter to apply to the results. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "crate::serde::is_default")] + pub room_network: RoomNetwork, } response { @@ -55,3 +65,181 @@ pub struct Filter { #[serde(skip_serializing_if = "Option::is_none")] pub generic_search_term: Option, } + +/// Information about which networks/protocols from application services on the +/// homeserver from which to request rooms. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum RoomNetwork { + /// Return rooms from the Matrix network. + Matrix, + /// Return rooms from all the networks/protocols the homeserver knows about. + All, + /// Return rooms from a specific third party network/protocol. + ThirdParty(String), +} + +impl Default for RoomNetwork { + fn default() -> Self { + RoomNetwork::Matrix + } +} + +impl Serialize for RoomNetwork { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut state; + match self { + Self::Matrix => { + state = serializer.serialize_struct("RoomNetwork", 0)?; + } + Self::All => { + state = serializer.serialize_struct("RoomNetwork", 1)?; + state.serialize_field("include_all_networks", &true)?; + } + Self::ThirdParty(network) => { + state = serializer.serialize_struct("RoomNetwork", 1)?; + state.serialize_field("third_party_instance_id", network)?; + } + } + state.end() + } +} + +impl<'de> Deserialize<'de> for RoomNetwork { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_map(RoomNetworkVisitor) + } +} + +struct RoomNetworkVisitor; +impl<'de> Visitor<'de> for RoomNetworkVisitor { + type Value = RoomNetwork; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Network selection") + } + + fn visit_map(self, mut access: M) -> Result + where + M: MapAccess<'de>, + { + let mut include_all_networks = false; + let mut third_party_instance_id = None; + while let Some((key, value)) = access.next_entry::()? { + match key.as_str() { + "include_all_networks" => { + include_all_networks = match value.as_bool() { + Some(b) => b, + _ => false, + } + } + "third_party_instance_id" => { + third_party_instance_id = value.as_str().map(|v| v.to_owned()) + } + _ => {} + }; + } + + if include_all_networks { + if third_party_instance_id.is_none() { + Ok(RoomNetwork::All) + } else { + Err(M::Error::custom( + "`include_all_networks = true` and `third_party_instance_id` are mutually exclusive.", + )) + } + } else { + Ok(match third_party_instance_id { + Some(network) => RoomNetwork::ThirdParty(network), + None => RoomNetwork::Matrix, + }) + } + } +} + +#[cfg(test)] +mod tests { + use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; + + use super::RoomNetwork; + + #[test] + fn test_serialize_matrix_network_only() { + let json = json!({}); + assert_eq!(to_json_value(RoomNetwork::Matrix).unwrap(), json); + } + + #[test] + fn test_deserialize_matrix_network_only() { + let json = json!({ "include_all_networks": false }); + assert_eq!( + from_json_value::(json).unwrap(), + RoomNetwork::Matrix + ); + } + + #[test] + fn test_serialize_default_network_is_empty() { + let json = json!({}); + assert_eq!(to_json_value(RoomNetwork::default()).unwrap(), json); + } + + #[test] + fn test_deserialize_empty_network_is_default() { + let json = json!({}); + assert_eq!( + from_json_value::(json).unwrap(), + RoomNetwork::default() + ); + } + + #[test] + fn test_serialize_include_all_networks() { + let json = json!({ "include_all_networks": true }); + assert_eq!(to_json_value(RoomNetwork::All).unwrap(), json); + } + + #[test] + fn test_deserialize_include_all_networks() { + let json = json!({ "include_all_networks": true }); + assert_eq!( + from_json_value::(json).unwrap(), + RoomNetwork::All + ); + } + + #[test] + fn test_serialize_third_party_network() { + let json = json!({ "third_party_instance_id": "freenode" }); + assert_eq!( + to_json_value(RoomNetwork::ThirdParty("freenode".to_string())).unwrap(), + json + ); + } + + #[test] + fn test_deserialize_third_party_network() { + let json = json!({ "third_party_instance_id": "freenode" }); + assert_eq!( + from_json_value::(json).unwrap(), + RoomNetwork::ThirdParty("freenode".to_string()) + ); + } + + #[test] + fn test_deserialize_include_all_networks_and_third_party_exclusivity() { + let json = json!({ "include_all_networks": true, "third_party_instance_id": "freenode" }); + assert_eq!( + from_json_value::(json) + .unwrap_err() + .to_string() + .as_str(), + "`include_all_networks = true` and `third_party_instance_id` are mutually exclusive." + ); + } +} From e310c39f158274e59a255875dce7380684ac34d2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 10 Apr 2020 00:04:31 +0200 Subject: [PATCH 257/350] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 18757086..1f4bc8f8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # ruma-client-api -[![Build Status](https://travis-ci.org/ruma/ruma-client-api.svg?branch=master)](https://travis-ci.org/ruma/ruma-client-api) +[![crates.io page](https://img.shields.io/crates/v/ruma-client-api.svg)](https://crates.io/crates/ruma-client-api) +[![docs.rs page](https://docs.rs/ruma-client-api/badge.svg)](https://docs.rs/ruma-client-api/) +[![build status](https://travis-ci.org/ruma/ruma-client-api.svg?branch=master)](https://travis-ci.org/ruma/ruma-client-api) +![license: MIT](https://img.shields.io/crates/l/ruma-client-api.svg) **ruma-client-api** contains serializable types for the requests and responses for each endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be shared by client and server code. @@ -12,7 +15,3 @@ ruma-client-api requires Rust 1.39.0 or later. ## Status This project is currently experimental and is very likely to change drastically. - -## License - -[MIT](http://opensource.org/licenses/MIT) From d94279efaf6940d37bba5a8860aeb012f926657d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 10 Apr 2020 17:08:03 +0200 Subject: [PATCH 258/350] Update README.md again --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f4bc8f8..ca76cd0b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ These types can be shared by client and server code. ruma-client-api requires Rust 1.39.0 or later. -## Status +## Contributing -This project is currently experimental and is very likely to change drastically. +See [CONTRIBUTING.md](CONTRIBUTING.md). From 9b5b90686809a40eb838ba5f3259518c289aa7ee Mon Sep 17 00:00:00 2001 From: "Ragotzy.devin" Date: Tue, 14 Apr 2020 07:44:16 -0400 Subject: [PATCH 259/350] sync_events/get_message_events: ser/de filters to string --- src/r0/message/get_message_events.rs | 83 +++++++++++++++++++++++++++- src/r0/sync/sync_events.rs | 28 +--------- src/serde.rs | 1 + src/serde/json_string.rs | 24 ++++++++ 4 files changed, 108 insertions(+), 28 deletions(-) create mode 100644 src/serde/json_string.rs diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index cd8fa749..3d7923ff 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -47,8 +47,12 @@ ruma_api! { #[ruma_api(query)] pub limit: Option, /// A RoomEventFilter to filter returned events with. - #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] + #[serde( + with = "crate::serde::json_string", + default, + skip_serializing_if = "Option::is_none" + )] pub filter: Option, } @@ -75,3 +79,80 @@ pub enum Direction { #[serde(rename = "f")] Forward, } + +#[cfg(test)] +mod tests { + use super::{Direction, Request}; + + use std::convert::{TryFrom, TryInto}; + + use ruma_identifiers::RoomId; + + use crate::r0::filter::{LazyLoadOptions, RoomEventFilter}; + + #[test] + fn test_serialize_some_room_event_filter() { + let room_id = RoomId::try_from("!roomid:example.org").unwrap(); + let filter = RoomEventFilter { + lazy_load_options: LazyLoadOptions::Enabled { + include_redundant_members: true, + }, + rooms: Some(vec![room_id.clone()]), + not_rooms: vec!["room".into(), "room2".into(), "room3".into()], + not_types: vec!["type".into()], + ..Default::default() + }; + let req = Request { + room_id, + from: "token".into(), + to: Some("token2".into()), + dir: Direction::Backward, + limit: Some(js_int::UInt::min_value()), + filter: Some(filter), + }; + + let request: http::Request> = req.try_into().unwrap(); + assert_eq!( + "from=token&to=token2&dir=b&limit=0&filter=%7B%22not_types%22%3A%5B%22type%22%5D%2C%22not_rooms%22%3A%5B%22room%22%2C%22room2%22%2C%22room3%22%5D%2C%22rooms%22%3A%5B%22%21roomid%3Aexample.org%22%5D%2C%22lazy_load_members%22%3Atrue%2C%22include_redundant_members%22%3Atrue%7D", + request.uri().query().unwrap() + ); + } + + #[test] + fn test_serialize_none_room_event_filter() { + let room_id = RoomId::try_from("!roomid:example.org").unwrap(); + let req = Request { + room_id, + from: "token".into(), + to: Some("token2".into()), + dir: Direction::Backward, + limit: Some(js_int::UInt::min_value()), + filter: None, + }; + + let request: http::Request> = req.try_into().unwrap(); + assert_eq!( + "from=token&to=token2&dir=b&limit=0", + request.uri().query().unwrap(), + ); + } + + #[test] + fn test_serialize_default_room_event_filter() { + let room_id = RoomId::try_from("!roomid:example.org").unwrap(); + let req = Request { + room_id, + from: "token".into(), + to: Some("token2".into()), + dir: Direction::Backward, + limit: Some(js_int::UInt::min_value()), + filter: Some(RoomEventFilter::default()), + }; + + let request: http::Request> = req.try_into().unwrap(); + assert_eq!( + "from=token&to=token2&dir=b&limit=0&filter=%7B%7D", + request.uri().query().unwrap(), + ); + } +} diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 455f26b3..c95e934b 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -122,39 +122,13 @@ pub enum Filter { // FilterDefinition is the first variant, JSON decoding is attempted first which is almost // functionally equivalent to looking at whether the first symbol is a '{' as the spec says. // (there are probably some corner cases like leading whitespace) - #[serde(with = "filter_def_serde")] + #[serde(with = "crate::serde::json_string")] /// A complete filter definition serialized to JSON. FilterDefinition(FilterDefinition), /// The ID of a filter saved on the server. FilterId(String), } -/// Serialization and deserialization logic for filter definitions. -mod filter_def_serde { - use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer}; - - use crate::r0::filter::FilterDefinition; - - /// Serialization logic for filter definitions. - pub fn serialize(filter_def: &FilterDefinition, serializer: S) -> Result - where - S: Serializer, - { - let string = serde_json::to_string(filter_def).map_err(S::Error::custom)?; - serializer.serialize_str(&string) - } - - /// Deserialization logic for filter definitions. - pub fn deserialize<'de, D>(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let filter_str = <&str>::deserialize(deserializer)?; - - serde_json::from_str(filter_str).map_err(D::Error::custom) - } -} - /// Updates to rooms. #[derive(Clone, Debug, Serialize, Outgoing)] pub struct Rooms { diff --git a/src/serde.rs b/src/serde.rs index 6ca75b9b..e89573d3 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -1,6 +1,7 @@ //! Modules to hold functions for de-/serializing remote types pub mod duration; +pub mod json_string; pub fn is_default(val: &T) -> bool { val == &T::default() diff --git a/src/serde/json_string.rs b/src/serde/json_string.rs new file mode 100644 index 00000000..e5fabe70 --- /dev/null +++ b/src/serde/json_string.rs @@ -0,0 +1,24 @@ +//! De-/serialization functions to and from json strings, allows the type to be used as a query string. + +use serde::{ + de::{Deserialize, DeserializeOwned, Deserializer, Error as _}, + ser::{Error as _, Serialize, Serializer}, +}; + +pub fn serialize(filter: T, serializer: S) -> Result +where + T: Serialize, + S: Serializer, +{ + let json = serde_json::to_string(&filter).map_err(S::Error::custom)?; + serializer.serialize_str(&json) +} + +pub fn deserialize<'de, T, D>(deserializer: D) -> Result +where + T: DeserializeOwned, + D: Deserializer<'de>, +{ + let s = String::deserialize(deserializer)?; + serde_json::from_str(&s).map_err(D::Error::custom) +} From c35d38c95f601d74ef4267d7e2bc12c79074d690 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Apr 2020 23:00:14 +0200 Subject: [PATCH 260/350] Fix minor style inconsistencies in serde::duration --- src/serde/duration/opt_ms.rs | 11 +++++------ src/serde/duration/secs.rs | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs index 0704324d..47d14b9a 100644 --- a/src/serde/duration/opt_ms.rs +++ b/src/serde/duration/opt_ms.rs @@ -10,6 +10,7 @@ use serde::{ }; /// Serialize an Option. +/// /// Will fail if integer is greater than the maximum integer that can be /// unambiguously represented by an f64. pub fn serialize(opt_duration: &Option, serializer: S) -> Result @@ -26,6 +27,7 @@ where } /// Deserializes an Option. +/// /// Will fail if integer is greater than the maximum integer that can be /// unambiguously represented by an f64. pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> @@ -38,17 +40,14 @@ where #[cfg(test)] mod tests { + use std::time::Duration; + use serde::{Deserialize, Serialize}; use serde_json::json; - use std::time::Duration; #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] struct DurationTest { - #[serde( - with = "crate::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none" - )] + #[serde(with = "super", default, skip_serializing_if = "Option::is_none")] timeout: Option, } diff --git a/src/serde/duration/secs.rs b/src/serde/duration/secs.rs index 1e60052a..f8940092 100644 --- a/src/serde/duration/secs.rs +++ b/src/serde/duration/secs.rs @@ -10,6 +10,7 @@ use serde::{ }; /// Serializes a Duration to an integer representing seconds. +/// /// Will fail if integer is greater than the maximum integer that can be /// unambiguously represented by an f64. pub fn serialize(duration: &Duration, serializer: S) -> Result @@ -23,6 +24,7 @@ where } /// Deserializes an integer representing seconds into a Duration. +/// /// Will fail if integer is greater than the maximum integer that can be /// unambiguously represented by an f64. pub fn deserialize<'de, D>(deserializer: D) -> Result @@ -34,13 +36,14 @@ where #[cfg(test)] mod tests { + use std::time::Duration; + use serde::{Deserialize, Serialize}; use serde_json::json; - use std::time::Duration; #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] struct DurationTest { - #[serde(with = "crate::serde::duration::secs")] + #[serde(with = "super")] timeout: Duration, } From 214d6521ef03acea4d04a460c0f771a0fe0e30da Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Apr 2020 23:19:00 +0200 Subject: [PATCH 261/350] Update tests for serde::duration --- src/serde/duration/opt_ms.rs | 18 ++++++++++++++---- src/serde/duration/secs.rs | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs index 47d14b9a..1e8d6462 100644 --- a/src/serde/duration/opt_ms.rs +++ b/src/serde/duration/opt_ms.rs @@ -52,7 +52,7 @@ mod tests { } #[test] - fn test_deserialize_some_duration_as_milliseconds() { + fn test_deserialize_some() { let json = json!({ "timeout": 3000 }); assert_eq!( @@ -64,7 +64,7 @@ mod tests { } #[test] - fn test_deserialize_empty_duration_as_milliseconds() { + fn test_deserialize_none_by_absence() { let json = json!({}); assert_eq!( @@ -74,7 +74,17 @@ mod tests { } #[test] - fn test_serialize_some_duration_as_milliseconds() { + fn test_deserialize_none_by_null() { + let json = json!({ "timeout": null }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + DurationTest { timeout: None }, + ); + } + + #[test] + fn test_serialize_some() { let request = DurationTest { timeout: Some(Duration::new(2, 0)), }; @@ -85,7 +95,7 @@ mod tests { } #[test] - fn test_serialize_empty_duration_as_milliseconds() { + fn test_serialize_none() { let request = DurationTest { timeout: None }; assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); } diff --git a/src/serde/duration/secs.rs b/src/serde/duration/secs.rs index f8940092..830eb4d5 100644 --- a/src/serde/duration/secs.rs +++ b/src/serde/duration/secs.rs @@ -48,7 +48,7 @@ mod tests { } #[test] - fn test_deserialize_duration_as_seconds() { + fn test_deserialize() { let json = json!({ "timeout": 3 }); assert_eq!( @@ -60,7 +60,7 @@ mod tests { } #[test] - fn test_serialize_duration_as_seconds() { + fn test_serialize() { let test = DurationTest { timeout: Duration::from_millis(7000), }; From befc55e43abc61870305c87648a379384777b14e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Apr 2020 23:28:35 +0200 Subject: [PATCH 262/350] Update get_contact endpoint to r0.6.0 --- src/r0/contact/get_contacts.rs | 50 ++++++++++++++++- src/serde.rs | 1 + src/serde/time.rs | 3 ++ src/serde/time/ms_since_unix_epoch.rs | 78 +++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/serde/time.rs create mode 100644 src/serde/time/ms_since_unix_epoch.rs diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index a67b2994..f033ce10 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,9 +1,12 @@ -//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid) +//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-account-3pid) + +use std::time::SystemTime; -use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; +use crate::r0::thirdparty::Medium; + ruma_api! { metadata { description: "Get a list of 3rd party contacts associated with the user's account.", @@ -19,6 +22,7 @@ ruma_api! { response { /// A list of third party identifiers the homeserver has associated with the user's /// account. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub threepids: Vec, } @@ -27,9 +31,51 @@ ruma_api! { /// An identifier external to Matrix. #[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct ThirdPartyIdentifier { /// The third party identifier address. pub address: String, /// The medium of third party identifier. pub medium: Medium, + /// The time when the identifier was validated by the identity server. + #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + pub validated_at: SystemTime, + /// The time when the homeserver associated the third party identifier with the user. + #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + pub added_at: SystemTime, +} + +#[cfg(test)] +mod tests { + use std::time::{Duration, UNIX_EPOCH}; + + use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; + + use super::{Medium, ThirdPartyIdentifier}; + + #[test] + fn third_party_identifier_serde() { + let third_party_id = ThirdPartyIdentifier { + address: "monkey@banana.island".into(), + medium: Medium::Email, + validated_at: UNIX_EPOCH + Duration::from_millis(1535176800000), + added_at: UNIX_EPOCH + Duration::from_millis(1535336848756), + }; + + let third_party_id_serialized = json!({ + "medium": "email", + "address": "monkey@banana.island", + "validated_at": 1535176800000u64, + "added_at": 1535336848756u64 + }); + + assert_eq!( + to_json_value(third_party_id.clone()).unwrap(), + third_party_id_serialized.clone() + ); + assert_eq!( + third_party_id, + from_json_value(third_party_id_serialized).unwrap() + ); + } } diff --git a/src/serde.rs b/src/serde.rs index e89573d3..79c08e92 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -2,6 +2,7 @@ pub mod duration; pub mod json_string; +pub mod time; pub fn is_default(val: &T) -> bool { val == &T::default() diff --git a/src/serde/time.rs b/src/serde/time.rs new file mode 100644 index 00000000..8605814c --- /dev/null +++ b/src/serde/time.rs @@ -0,0 +1,3 @@ +//! De-/serialization functions for `std::time::SystemTime` objects + +pub mod ms_since_unix_epoch; diff --git a/src/serde/time/ms_since_unix_epoch.rs b/src/serde/time/ms_since_unix_epoch.rs new file mode 100644 index 00000000..ea1b79cc --- /dev/null +++ b/src/serde/time/ms_since_unix_epoch.rs @@ -0,0 +1,78 @@ +//! De-/serialization functions for `std::time::SystemTime` objects represented as milliseconds +//! since the UNIX epoch. Delegates to `js_int::UInt` to ensure integer size is within bounds. + +use std::{ + convert::TryFrom, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; + +use js_int::UInt; +use serde::{ + de::{Deserialize, Deserializer}, + ser::{Error, Serialize, Serializer}, +}; + +/// Serialize a SystemTime. +/// +/// Will fail if integer is greater than the maximum integer that can be unambiguously represented +/// by an f64. +pub fn serialize(time: &SystemTime, serializer: S) -> Result +where + S: Serializer, +{ + // If this unwrap fails, the system this is executed is completely broken. + let time_since_epoch = time.duration_since(UNIX_EPOCH).unwrap(); + match UInt::try_from(time_since_epoch.as_millis()) { + Ok(uint) => uint.serialize(serializer), + Err(err) => Err(S::Error::custom(err)), + } +} + +/// Deserializes a SystemTime. +/// +/// Will fail if integer is greater than the maximum integer that can be unambiguously represented +/// by an f64. +pub fn deserialize<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let millis = UInt::deserialize(deserializer)?; + Ok(UNIX_EPOCH + Duration::from_millis(millis.into())) +} + +#[cfg(test)] +mod tests { + use std::time::{Duration, SystemTime, UNIX_EPOCH}; + + use serde::{Deserialize, Serialize}; + use serde_json::json; + + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] + struct SystemTimeTest { + #[serde(with = "super")] + timestamp: SystemTime, + } + + #[test] + fn test_deserialize() { + let json = json!({ "timestamp": 3000 }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + SystemTimeTest { + timestamp: UNIX_EPOCH + Duration::from_millis(3000), + }, + ); + } + + #[test] + fn test_serialize() { + let request = SystemTimeTest { + timestamp: UNIX_EPOCH + Duration::new(2, 0), + }; + assert_eq!( + serde_json::to_value(&request).unwrap(), + json!({ "timestamp": 2000 }) + ); + } +} From 206530e10dacc674d205ef9219b59df9d5a7ed04 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Apr 2020 23:29:03 +0200 Subject: [PATCH 263/350] Update change log --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb2d249c..fcd131ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,15 @@ Breaking changes: -* Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` +* Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` +* Add `auth_parameters` to `r0::account::AuthenticationData` +* Add `room_network` parameter to `r0::directory::get_public_rooms_filtered` to + represent `include_all_networks` and `third_party_instance_id` Matrix fields. * Update `r0::account::register` endpoint: * Remove `bind_email` request field (removed in r0.6.0) * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) * Remove deprecated `home_server` response field (removed in r0.4.0) -* Add `auth_parameters` to `r0::account::AuthenticationData` -* Add `room_network` parameter to `r0::directory::get_public_rooms_filtered` to - represent `include_all_networks` and `third_party_instance_id` Matrix fields. +* Update `r0::contact::get_contacts` endpoint to r0.6.0 Improvements: From 207b77b53da89c36fe3db7e075292dc259a26c8b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 16 Apr 2020 00:19:11 +0200 Subject: [PATCH 264/350] Update most timestampts to SystemTime --- CHANGELOG.md | 4 ++++ src/r0/media/get_media_preview.rs | 6 ++++-- src/r0/push/get_notifications.rs | 7 +++++-- src/r0/server/get_user_info.rs | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd131ce..fa449ab0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Breaking changes: * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) * Remove deprecated `home_server` response field (removed in r0.4.0) * Update `r0::contact::get_contacts` endpoint to r0.6.0 +* Change `UInt` timestamps to `SystemTime` in: + * `media::get_media_preview` + * `push::get_notifications` + * `server::get_user_info` Improvements: diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index 13dd4a5c..118c09b6 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -1,6 +1,7 @@ //! [GET /_matrix/media/r0/preview_url](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-preview-url) -use js_int::UInt; +use std::time::SystemTime; + use ruma_api::ruma_api; use serde_json::Value; @@ -20,7 +21,8 @@ ruma_api! { pub url: String, /// Preferred point in time (in milliseconds) to return a preview for. #[ruma_api(query)] - pub ts: UInt, + #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + pub ts: SystemTime, } response { diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs index 6774e8a2..f26a60fd 100644 --- a/src/r0/push/get_notifications.rs +++ b/src/r0/push/get_notifications.rs @@ -1,5 +1,7 @@ //! [GET /_matrix/client/r0/notifications](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-notifications) +use std::time::SystemTime; + use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; use ruma_events::{collections::all, EventResult}; @@ -71,6 +73,7 @@ pub struct Notification { /// The ID of the room in which the event was posted. pub room_id: RoomId, - /// The unix timestamp at which the event notification was sent, in milliseconds. - pub ts: UInt, + /// The time at which the event notification was sent, in milliseconds. + #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + pub ts: SystemTime, } diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 1cb6aef2..c07d1985 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-admin-whois-userid) -use std::collections::HashMap; +use std::{collections::HashMap, time::SystemTime}; -use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; @@ -38,8 +37,9 @@ ruma_api! { pub struct ConnectionInfo { /// Most recently seen IP address of the session. pub ip: String, - /// Unix timestamp that the session was last active. - pub last_seen: UInt, + /// Time when that the session was last active. + #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + pub last_seen: SystemTime, /// User agent string last seen in the session. pub user_agent: String, } From 6ddb9eca8b5e06e72a4453c383262e93feaf19c2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 16 Apr 2020 00:28:09 +0200 Subject: [PATCH 265/350] Add serde::opt_ms_since_unix_epoch, use it in device::Device --- CHANGELOG.md | 7 +- src/r0/device.rs | 10 ++- src/serde/time.rs | 1 + src/serde/time/opt_ms_since_unix_epoch.rs | 100 ++++++++++++++++++++++ 4 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 src/serde/time/opt_ms_since_unix_epoch.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index fa449ab0..4c9ce527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,10 @@ Breaking changes: * Remove deprecated `home_server` response field (removed in r0.4.0) * Update `r0::contact::get_contacts` endpoint to r0.6.0 * Change `UInt` timestamps to `SystemTime` in: - * `media::get_media_preview` - * `push::get_notifications` - * `server::get_user_info` + * `media::get_media_preview::Request` + * `push::get_notifications::Notification` + * `server::get_user_info::ConnectionInfo` + * `device::Device` Improvements: diff --git a/src/r0/device.rs b/src/r0/device.rs index 11c27344..39523f2e 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -1,6 +1,7 @@ //! Endpoints for managing devices. -use js_int::UInt; +use std::time::SystemTime; + use ruma_identifiers::DeviceId; use serde::{Deserialize, Serialize}; @@ -20,5 +21,10 @@ pub struct Device { /// Most recently seen IP address of the session. pub ip: Option, /// Unix timestamp that the session was last active. - pub last_seen: Option, + #[serde( + with = "crate::serde::time::opt_ms_since_unix_epoch", + default, + skip_serializing_if = "Option::is_none" + )] + pub last_seen: Option, } diff --git a/src/serde/time.rs b/src/serde/time.rs index 8605814c..e60bb839 100644 --- a/src/serde/time.rs +++ b/src/serde/time.rs @@ -1,3 +1,4 @@ //! De-/serialization functions for `std::time::SystemTime` objects pub mod ms_since_unix_epoch; +pub mod opt_ms_since_unix_epoch; diff --git a/src/serde/time/opt_ms_since_unix_epoch.rs b/src/serde/time/opt_ms_since_unix_epoch.rs new file mode 100644 index 00000000..787455ac --- /dev/null +++ b/src/serde/time/opt_ms_since_unix_epoch.rs @@ -0,0 +1,100 @@ +//! De-/serialization functions for `Option` objects represented as +//! milliseconds since the UNIX epoch. Delegates to `js_int::UInt` to ensure integer size is within +//! bounds. + +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use js_int::UInt; +use serde::{ + de::{Deserialize, Deserializer}, + ser::{Serialize, Serializer}, +}; + +/// Serialize an `Option`. +/// +/// Will fail if integer is greater than the maximum integer that can be unambiguously represented +/// by an f64. +pub fn serialize(opt_time: &Option, serializer: S) -> Result +where + S: Serializer, +{ + match opt_time { + Some(time) => super::ms_since_unix_epoch::serialize(time, serializer), + None => Option::::serialize(&None, serializer), + } +} + +/// Deserializes an `Option`. +/// +/// Will fail if integer is greater than the maximum integer that can be unambiguously represented +/// by an f64. +pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + Ok(Option::::deserialize(deserializer)? + .map(|millis| UNIX_EPOCH + Duration::from_millis(millis.into()))) +} + +#[cfg(test)] +mod tests { + use std::time::{Duration, SystemTime, UNIX_EPOCH}; + + use serde::{Deserialize, Serialize}; + use serde_json::json; + + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] + struct SystemTimeTest { + #[serde(with = "super", default, skip_serializing_if = "Option::is_none")] + timestamp: Option, + } + + #[test] + fn test_deserialize_some() { + let json = json!({ "timestamp": 3000 }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + SystemTimeTest { + timestamp: Some(UNIX_EPOCH + Duration::from_millis(3000)) + }, + ); + } + + #[test] + fn test_deserialize_none_by_absence() { + let json = json!({}); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + SystemTimeTest { timestamp: None }, + ); + } + + #[test] + fn test_deserialize_none_by_null() { + let json = json!({ "timestamp": null }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + SystemTimeTest { timestamp: None }, + ); + } + + #[test] + fn test_serialize_some() { + let request = SystemTimeTest { + timestamp: Some(UNIX_EPOCH + Duration::new(2, 0)), + }; + assert_eq!( + serde_json::to_value(&request).unwrap(), + json!({ "timestamp": 2000 }) + ); + } + + #[test] + fn test_serialize_none() { + let request = SystemTimeTest { timestamp: None }; + assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); + } +} From adfb5c82fafd2dbb01e4eced28dead01b61b05a2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 16 Apr 2020 01:26:34 +0200 Subject: [PATCH 266/350] Fix unreadable literals --- src/r0/contact/get_contacts.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index f033ce10..d9fbf68e 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -58,15 +58,15 @@ mod tests { let third_party_id = ThirdPartyIdentifier { address: "monkey@banana.island".into(), medium: Medium::Email, - validated_at: UNIX_EPOCH + Duration::from_millis(1535176800000), - added_at: UNIX_EPOCH + Duration::from_millis(1535336848756), + validated_at: UNIX_EPOCH + Duration::from_millis(1_535_176_800_000), + added_at: UNIX_EPOCH + Duration::from_millis(1_535_336_848_756), }; let third_party_id_serialized = json!({ "medium": "email", "address": "monkey@banana.island", - "validated_at": 1535176800000u64, - "added_at": 1535336848756u64 + "validated_at": 1_535_176_800_000u64, + "added_at": 1_535_336_848_756u64 }); assert_eq!( From 5ac26cc641d543b892e43cc100c01c322e1171bb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 16 Apr 2020 01:28:35 +0200 Subject: [PATCH 267/350] Fix redundant clone --- src/r0/contact/get_contacts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index d9fbf68e..63b31303 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -71,7 +71,7 @@ mod tests { assert_eq!( to_json_value(third_party_id.clone()).unwrap(), - third_party_id_serialized.clone() + third_party_id_serialized ); assert_eq!( third_party_id, From 23dbea1f56144062d218dc722a31ac9ec4bd1bb3 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Fri, 17 Apr 2020 11:32:37 +0200 Subject: [PATCH 268/350] Make join_room_by_id_or_alias deserialization work --- src/r0/membership/join_room_by_id_or_alias.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index 4def0344..287ae7c9 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -22,8 +22,8 @@ ruma_api! { /// The servers to attempt to join the room through. One of the servers /// must be participating in the room. #[ruma_api(query)] - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub server_name: Vec, + #[serde(default)] + pub server_name: String, // TODO: Vec once it is supported (#146, ruma-api#48) /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] From 6ff7d3710b1340e27fc7d5eddfe7c2aa6302df2a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 17 Apr 2020 23:54:13 +0200 Subject: [PATCH 269/350] Replace serde module with ruma-serde, update deps --- Cargo.toml | 11 +- src/lib.rs | 2 - src/r0/account/register.rs | 2 +- src/r0/account/request_openid_token.rs | 2 +- src/r0/contact/get_contacts.rs | 4 +- src/r0/device.rs | 2 +- src/r0/directory/get_public_rooms_filtered.rs | 2 +- src/r0/keys/claim_keys.rs | 2 +- src/r0/keys/get_keys.rs | 2 +- src/r0/media/get_media_preview.rs | 2 +- src/r0/message/get_message_events.rs | 2 +- src/r0/presence/get_presence.rs | 2 +- src/r0/push/get_notifications.rs | 2 +- src/r0/server/get_user_info.rs | 2 +- src/r0/sync/sync_events.rs | 13 +-- src/r0/typing/create_typing_event.rs | 2 +- src/r0/voip/get_turn_server_info.rs | 2 +- src/serde.rs | 9 -- src/serde/duration.rs | 4 - src/serde/duration/opt_ms.rs | 102 ------------------ src/serde/duration/secs.rs | 69 ------------ src/serde/json_string.rs | 24 ----- src/serde/time.rs | 4 - src/serde/time/ms_since_unix_epoch.rs | 78 -------------- src/serde/time/opt_ms_since_unix_epoch.rs | 100 ----------------- 25 files changed, 26 insertions(+), 420 deletions(-) delete mode 100644 src/serde.rs delete mode 100644 src/serde/duration.rs delete mode 100644 src/serde/duration/opt_ms.rs delete mode 100644 src/serde/duration/secs.rs delete mode 100644 src/serde/json_string.rs delete mode 100644 src/serde/time.rs delete mode 100644 src/serde/time/ms_since_unix_epoch.rs delete mode 100644 src/serde/time/opt_ms_since_unix_epoch.rs diff --git a/Cargo.toml b/Cargo.toml index 0018c5b0..66426a6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,11 @@ edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } -ruma-api = "0.15.0" -ruma-events = "0.18.0" -ruma-identifiers = "0.14.1" -serde = { version = "1.0.105", features = ["derive"] } -serde_json = "1.0.50" +ruma-api = "0.16.0-rc.1" +ruma-events = "0.19.0-rc.1" +ruma-identifiers = "0.15.1" +ruma-serde = "0.1.0" +serde = { version = "1.0.106", features = ["derive"] } +serde_json = "1.0.51" strum = { version = "0.18.0", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } diff --git a/src/lib.rs b/src/lib.rs index 7c2ed9c0..375c159b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,4 @@ pub mod error; pub mod r0; pub mod unversioned; -mod serde; - pub use error::Error; diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 9b11340d..f517f4ca 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -55,7 +55,7 @@ ruma_api! { pub kind: Option, /// If `true`, an `access_token` and `device_id` should not be returned /// from this call, therefore preventing an automatic login. - #[serde(default, skip_serializing_if = "crate::serde::is_default")] + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] pub inhibit_login: bool, } diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs index 637524a5..ee5166d5 100644 --- a/src/r0/account/request_openid_token.rs +++ b/src/r0/account/request_openid_token.rs @@ -30,7 +30,7 @@ ruma_api! { /// Homeserver domain for verification of user's identity. pub matrix_server_name: String, /// Seconds until token expiration. - #[serde(with = "crate::serde::duration::secs")] + #[serde(with = "ruma_serde::duration::secs")] pub expires_in: Duration, } diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 63b31303..06834c64 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -38,10 +38,10 @@ pub struct ThirdPartyIdentifier { /// The medium of third party identifier. pub medium: Medium, /// The time when the identifier was validated by the identity server. - #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub validated_at: SystemTime, /// The time when the homeserver associated the third party identifier with the user. - #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub added_at: SystemTime, } diff --git a/src/r0/device.rs b/src/r0/device.rs index 39523f2e..6e0a8620 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -22,7 +22,7 @@ pub struct Device { pub ip: Option, /// Unix timestamp that the session was last active. #[serde( - with = "crate::serde::time::opt_ms_since_unix_epoch", + with = "ruma_serde::time::opt_ms_since_unix_epoch", default, skip_serializing_if = "Option::is_none" )] diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index b3302f58..3deb6565 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -40,7 +40,7 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "crate::serde::is_default")] + #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] pub room_network: RoomNetwork, } diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 3b4dd450..70b5a7ec 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -24,7 +24,7 @@ ruma_api! { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. #[serde( - with = "crate::serde::duration::opt_ms", + with = "ruma_serde::duration::opt_ms", default, skip_serializing_if = "Option::is_none", )] diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index 98628261..b9e3ecb4 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -22,7 +22,7 @@ ruma_api! { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// 10 seconds is the recommended default. #[serde( - with = "crate::serde::duration::opt_ms", + with = "ruma_serde::duration::opt_ms", default, skip_serializing_if = "Option::is_none", )] diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index 118c09b6..b517d21d 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -21,7 +21,7 @@ ruma_api! { pub url: String, /// Preferred point in time (in milliseconds) to return a preview for. #[ruma_api(query)] - #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub ts: SystemTime, } diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index 3d7923ff..e5220d2a 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -49,7 +49,7 @@ ruma_api! { /// A RoomEventFilter to filter returned events with. #[ruma_api(query)] #[serde( - with = "crate::serde::json_string", + with = "ruma_serde::json_string", default, skip_serializing_if = "Option::is_none" )] diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index 6424435b..b6e02d6e 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -31,7 +31,7 @@ ruma_api! { pub currently_active: Option, /// The length of time in milliseconds since an action was performed by the user. #[serde( - with = "crate::serde::duration::opt_ms", + with = "ruma_serde::duration::opt_ms", default, skip_serializing_if = "Option::is_none", )] diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs index f26a60fd..de263b96 100644 --- a/src/r0/push/get_notifications.rs +++ b/src/r0/push/get_notifications.rs @@ -74,6 +74,6 @@ pub struct Notification { pub room_id: RoomId, /// The time at which the event notification was sent, in milliseconds. - #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub ts: SystemTime, } diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index c07d1985..5c3a5dd9 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -38,7 +38,7 @@ pub struct ConnectionInfo { /// Most recently seen IP address of the session. pub ip: String, /// Time when that the session was last active. - #[serde(with = "crate::serde::time::ms_since_unix_epoch")] + #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub last_seen: SystemTime, /// User agent string last seen in the session. pub user_agent: String, diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index c95e934b..cb6200e2 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -17,10 +17,7 @@ use ruma_events::{ use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; -use crate::{ - r0::{filter::FilterDefinition, keys::KeyAlgorithm}, - serde::is_default, -}; +use crate::r0::{filter::FilterDefinition, keys::KeyAlgorithm}; ruma_api! { metadata { @@ -45,16 +42,16 @@ ruma_api! { #[ruma_api(query)] pub since: Option, /// Controls whether to include the full state for all rooms the user is a member of. - #[serde(default, skip_serializing_if = "is_default")] + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_api(query)] pub full_state: bool, /// Controls whether the client is automatically marked as online by polling this API. - #[serde(default, skip_serializing_if = "is_default")] + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_api(query)] pub set_presence: SetPresence, /// The maximum time to poll in milliseconds before returning this request. #[serde( - with = "crate::serde::duration::opt_ms", + with = "ruma_serde::duration::opt_ms", default, skip_serializing_if = "Option::is_none", )] @@ -122,7 +119,7 @@ pub enum Filter { // FilterDefinition is the first variant, JSON decoding is attempted first which is almost // functionally equivalent to looking at whether the first symbol is a '{' as the spec says. // (there are probably some corner cases like leading whitespace) - #[serde(with = "crate::serde::json_string")] + #[serde(with = "ruma_serde::json_string")] /// A complete filter definition serialized to JSON. FilterDefinition(FilterDefinition), /// The ID of a filter saved on the server. diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index 3731ad02..6d1a4d84 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -21,7 +21,7 @@ ruma_api! { pub room_id: RoomId, /// The length of time in milliseconds to mark this user as typing. #[serde( - with = "crate::serde::duration::opt_ms", + with = "ruma_serde::duration::opt_ms", default, skip_serializing_if = "Option::is_none", )] diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 5e83b58f..420a3382 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -20,7 +20,7 @@ ruma_api! { /// The password to use. pub password: String, /// The time-to-live in seconds. - #[serde(with = "crate::serde::duration::secs")] + #[serde(with = "ruma_serde::duration::secs")] pub ttl: Duration, /// A list of TURN URIs. pub uris: Vec, diff --git a/src/serde.rs b/src/serde.rs deleted file mode 100644 index 79c08e92..00000000 --- a/src/serde.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! Modules to hold functions for de-/serializing remote types - -pub mod duration; -pub mod json_string; -pub mod time; - -pub fn is_default(val: &T) -> bool { - val == &T::default() -} diff --git a/src/serde/duration.rs b/src/serde/duration.rs deleted file mode 100644 index d8c895fa..00000000 --- a/src/serde/duration.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! De-/serialization functions for `std::time::Duration` objects - -pub mod opt_ms; -pub mod secs; diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs deleted file mode 100644 index 1e8d6462..00000000 --- a/src/serde/duration/opt_ms.rs +++ /dev/null @@ -1,102 +0,0 @@ -//! De-/serialization functions for `Option` objects represented as milliseconds. -//! Delegates to `js_int::UInt` to ensure integer size is within bounds. - -use std::{convert::TryFrom, time::Duration}; - -use js_int::UInt; -use serde::{ - de::{Deserialize, Deserializer}, - ser::{Error, Serialize, Serializer}, -}; - -/// Serialize an Option. -/// -/// Will fail if integer is greater than the maximum integer that can be -/// unambiguously represented by an f64. -pub fn serialize(opt_duration: &Option, serializer: S) -> Result -where - S: Serializer, -{ - match opt_duration { - Some(duration) => match UInt::try_from(duration.as_millis()) { - Ok(uint) => uint.serialize(serializer), - Err(err) => Err(S::Error::custom(err)), - }, - None => serializer.serialize_none(), - } -} - -/// Deserializes an Option. -/// -/// Will fail if integer is greater than the maximum integer that can be -/// unambiguously represented by an f64. -pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - Ok(Option::::deserialize(deserializer)? - .map(|millis| Duration::from_millis(millis.into()))) -} - -#[cfg(test)] -mod tests { - use std::time::Duration; - - use serde::{Deserialize, Serialize}; - use serde_json::json; - - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] - struct DurationTest { - #[serde(with = "super", default, skip_serializing_if = "Option::is_none")] - timeout: Option, - } - - #[test] - fn test_deserialize_some() { - let json = json!({ "timeout": 3000 }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - DurationTest { - timeout: Some(Duration::from_millis(3000)) - }, - ); - } - - #[test] - fn test_deserialize_none_by_absence() { - let json = json!({}); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - DurationTest { timeout: None }, - ); - } - - #[test] - fn test_deserialize_none_by_null() { - let json = json!({ "timeout": null }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - DurationTest { timeout: None }, - ); - } - - #[test] - fn test_serialize_some() { - let request = DurationTest { - timeout: Some(Duration::new(2, 0)), - }; - assert_eq!( - serde_json::to_value(&request).unwrap(), - json!({ "timeout": 2000 }) - ); - } - - #[test] - fn test_serialize_none() { - let request = DurationTest { timeout: None }; - assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); - } -} diff --git a/src/serde/duration/secs.rs b/src/serde/duration/secs.rs deleted file mode 100644 index 830eb4d5..00000000 --- a/src/serde/duration/secs.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! De-/serialization functions for `Option` objects represented as milliseconds. -//! Delegates to `js_int::UInt` to ensure integer size is within bounds. - -use std::{convert::TryFrom, time::Duration}; - -use js_int::UInt; -use serde::{ - de::{Deserialize, Deserializer}, - ser::{Error, Serialize, Serializer}, -}; - -/// Serializes a Duration to an integer representing seconds. -/// -/// Will fail if integer is greater than the maximum integer that can be -/// unambiguously represented by an f64. -pub fn serialize(duration: &Duration, serializer: S) -> Result -where - S: Serializer, -{ - match UInt::try_from(duration.as_secs()) { - Ok(uint) => uint.serialize(serializer), - Err(err) => Err(S::Error::custom(err)), - } -} - -/// Deserializes an integer representing seconds into a Duration. -/// -/// Will fail if integer is greater than the maximum integer that can be -/// unambiguously represented by an f64. -pub fn deserialize<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - UInt::deserialize(deserializer).map(|secs| Duration::from_secs(secs.into())) -} - -#[cfg(test)] -mod tests { - use std::time::Duration; - - use serde::{Deserialize, Serialize}; - use serde_json::json; - - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] - struct DurationTest { - #[serde(with = "super")] - timeout: Duration, - } - - #[test] - fn test_deserialize() { - let json = json!({ "timeout": 3 }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - DurationTest { - timeout: Duration::from_secs(3) - }, - ); - } - - #[test] - fn test_serialize() { - let test = DurationTest { - timeout: Duration::from_millis(7000), - }; - assert_eq!(serde_json::to_value(test).unwrap(), json!({ "timeout": 7 }),); - } -} diff --git a/src/serde/json_string.rs b/src/serde/json_string.rs deleted file mode 100644 index e5fabe70..00000000 --- a/src/serde/json_string.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! De-/serialization functions to and from json strings, allows the type to be used as a query string. - -use serde::{ - de::{Deserialize, DeserializeOwned, Deserializer, Error as _}, - ser::{Error as _, Serialize, Serializer}, -}; - -pub fn serialize(filter: T, serializer: S) -> Result -where - T: Serialize, - S: Serializer, -{ - let json = serde_json::to_string(&filter).map_err(S::Error::custom)?; - serializer.serialize_str(&json) -} - -pub fn deserialize<'de, T, D>(deserializer: D) -> Result -where - T: DeserializeOwned, - D: Deserializer<'de>, -{ - let s = String::deserialize(deserializer)?; - serde_json::from_str(&s).map_err(D::Error::custom) -} diff --git a/src/serde/time.rs b/src/serde/time.rs deleted file mode 100644 index e60bb839..00000000 --- a/src/serde/time.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! De-/serialization functions for `std::time::SystemTime` objects - -pub mod ms_since_unix_epoch; -pub mod opt_ms_since_unix_epoch; diff --git a/src/serde/time/ms_since_unix_epoch.rs b/src/serde/time/ms_since_unix_epoch.rs deleted file mode 100644 index ea1b79cc..00000000 --- a/src/serde/time/ms_since_unix_epoch.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! De-/serialization functions for `std::time::SystemTime` objects represented as milliseconds -//! since the UNIX epoch. Delegates to `js_int::UInt` to ensure integer size is within bounds. - -use std::{ - convert::TryFrom, - time::{Duration, SystemTime, UNIX_EPOCH}, -}; - -use js_int::UInt; -use serde::{ - de::{Deserialize, Deserializer}, - ser::{Error, Serialize, Serializer}, -}; - -/// Serialize a SystemTime. -/// -/// Will fail if integer is greater than the maximum integer that can be unambiguously represented -/// by an f64. -pub fn serialize(time: &SystemTime, serializer: S) -> Result -where - S: Serializer, -{ - // If this unwrap fails, the system this is executed is completely broken. - let time_since_epoch = time.duration_since(UNIX_EPOCH).unwrap(); - match UInt::try_from(time_since_epoch.as_millis()) { - Ok(uint) => uint.serialize(serializer), - Err(err) => Err(S::Error::custom(err)), - } -} - -/// Deserializes a SystemTime. -/// -/// Will fail if integer is greater than the maximum integer that can be unambiguously represented -/// by an f64. -pub fn deserialize<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let millis = UInt::deserialize(deserializer)?; - Ok(UNIX_EPOCH + Duration::from_millis(millis.into())) -} - -#[cfg(test)] -mod tests { - use std::time::{Duration, SystemTime, UNIX_EPOCH}; - - use serde::{Deserialize, Serialize}; - use serde_json::json; - - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] - struct SystemTimeTest { - #[serde(with = "super")] - timestamp: SystemTime, - } - - #[test] - fn test_deserialize() { - let json = json!({ "timestamp": 3000 }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - SystemTimeTest { - timestamp: UNIX_EPOCH + Duration::from_millis(3000), - }, - ); - } - - #[test] - fn test_serialize() { - let request = SystemTimeTest { - timestamp: UNIX_EPOCH + Duration::new(2, 0), - }; - assert_eq!( - serde_json::to_value(&request).unwrap(), - json!({ "timestamp": 2000 }) - ); - } -} diff --git a/src/serde/time/opt_ms_since_unix_epoch.rs b/src/serde/time/opt_ms_since_unix_epoch.rs deleted file mode 100644 index 787455ac..00000000 --- a/src/serde/time/opt_ms_since_unix_epoch.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! De-/serialization functions for `Option` objects represented as -//! milliseconds since the UNIX epoch. Delegates to `js_int::UInt` to ensure integer size is within -//! bounds. - -use std::time::{Duration, SystemTime, UNIX_EPOCH}; - -use js_int::UInt; -use serde::{ - de::{Deserialize, Deserializer}, - ser::{Serialize, Serializer}, -}; - -/// Serialize an `Option`. -/// -/// Will fail if integer is greater than the maximum integer that can be unambiguously represented -/// by an f64. -pub fn serialize(opt_time: &Option, serializer: S) -> Result -where - S: Serializer, -{ - match opt_time { - Some(time) => super::ms_since_unix_epoch::serialize(time, serializer), - None => Option::::serialize(&None, serializer), - } -} - -/// Deserializes an `Option`. -/// -/// Will fail if integer is greater than the maximum integer that can be unambiguously represented -/// by an f64. -pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - Ok(Option::::deserialize(deserializer)? - .map(|millis| UNIX_EPOCH + Duration::from_millis(millis.into()))) -} - -#[cfg(test)] -mod tests { - use std::time::{Duration, SystemTime, UNIX_EPOCH}; - - use serde::{Deserialize, Serialize}; - use serde_json::json; - - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] - struct SystemTimeTest { - #[serde(with = "super", default, skip_serializing_if = "Option::is_none")] - timestamp: Option, - } - - #[test] - fn test_deserialize_some() { - let json = json!({ "timestamp": 3000 }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - SystemTimeTest { - timestamp: Some(UNIX_EPOCH + Duration::from_millis(3000)) - }, - ); - } - - #[test] - fn test_deserialize_none_by_absence() { - let json = json!({}); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - SystemTimeTest { timestamp: None }, - ); - } - - #[test] - fn test_deserialize_none_by_null() { - let json = json!({ "timestamp": null }); - - assert_eq!( - serde_json::from_value::(json).unwrap(), - SystemTimeTest { timestamp: None }, - ); - } - - #[test] - fn test_serialize_some() { - let request = SystemTimeTest { - timestamp: Some(UNIX_EPOCH + Duration::new(2, 0)), - }; - assert_eq!( - serde_json::to_value(&request).unwrap(), - json!({ "timestamp": 2000 }) - ); - } - - #[test] - fn test_serialize_none() { - let request = SystemTimeTest { timestamp: None }; - assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); - } -} From 6452401add06475449b8bdff93896f20ebea9e7a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 18 Apr 2020 00:26:29 +0200 Subject: [PATCH 270/350] Add missing skip_serializing_if = "Option::is_none --- CHANGELOG.md | 1 + src/r0/media/get_content_thumbnail.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9ce527..ea4ca735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Breaking changes: Improvements: * Add types for User-Interactive Authentication API: `r0::account::{UserInteractiveAuthenticationInfo, AuthenticationFlow}` +* Add missing serde attributes to `get_content_thumbnail` query parameters # 0.7.2 diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 567631d9..a6d9a127 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -29,6 +29,7 @@ ruma_api! { /// /// Used to prevent routing loops. Defaults to `true`. #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] pub allow_remote: Option, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] @@ -42,6 +43,7 @@ ruma_api! { pub height: UInt, /// The desired resizing method. #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] pub method: Option, /// The *desired* width of the thumbnail. The actual thumbnail may not match the size /// specified. From c5689f3da579bd0c68e8c5e10daa594db9ecb102 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 16:48:20 +0200 Subject: [PATCH 271/350] Replace HashMap with BTreeMap --- CONTRIBUTING.md | 6 +++--- src/r0/capabilities/get_capabilities.rs | 6 +++--- src/r0/client_exchange.rs | 3 ++- src/r0/client_exchange/send_event_to_device.rs | 4 ++-- src/r0/keys.rs | 12 ++++++------ src/r0/keys/claim_keys.rs | 8 ++++---- src/r0/keys/get_keys.rs | 8 ++++---- src/r0/keys/upload_keys.rs | 6 +++--- src/r0/membership.rs | 4 ++-- src/r0/membership/joined_members.rs | 4 ++-- src/r0/push.rs | 4 +++- src/r0/push/get_pushrules_all.rs | 4 ++-- src/r0/push/get_pushrules_global_scope.rs | 4 ++-- src/r0/search/search_events.rs | 8 ++++---- src/r0/server/get_user_info.rs | 4 ++-- src/r0/sync/sync_events.rs | 12 ++++++------ src/r0/thirdparty.rs | 10 +++++----- src/r0/thirdparty/get_location_for_protocol.rs | 4 ++-- src/r0/thirdparty/get_protocols.rs | 4 ++-- src/r0/thirdparty/get_user_for_protocol.rs | 4 ++-- src/unversioned/get_supported_versions.rs | 6 +++--- 21 files changed, 64 insertions(+), 61 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46856b78..fbe97a77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,7 +60,7 @@ Organize your imports into three groups separated by blank lines: For example, ```rust -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -71,7 +71,7 @@ Also, group imports by module. For example, do this: ```rust use std::{ - collections::HashMap, + collections::BTreeMap, convert::TryFrom, fmt::{Debug, Display, Error as FmtError, Formatter}, }; @@ -80,7 +80,7 @@ use std::{ as opposed to: ```rust -use std::collections::HashMap; +use std::collections::BTreeMap; use std::convert::TryFrom; use std::fmt::{Debug, Display, Error as FmtError, Formatter}; ``` diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs index 9345280c..d0d97cca 100644 --- a/src/r0/capabilities/get_capabilities.rs +++ b/src/r0/capabilities/get_capabilities.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::collections::HashMap; +use std::collections::BTreeMap; ruma_api! { metadata { @@ -39,7 +39,7 @@ pub struct Capabilities { /// Any other custom capabilities that the server supports outside of the specification, /// labeled using the Java package naming convention and stored as arbitrary JSON values. #[serde(flatten)] - pub custom_capabilities: HashMap, + pub custom_capabilities: BTreeMap, } /// Information about the m.change_password capability @@ -56,7 +56,7 @@ pub struct RoomVersionsCapability { pub default: String, /// A detailed description of the room versions the server supports. - pub available: HashMap, + pub available: BTreeMap, } /// The stability of a room version diff --git a/src/r0/client_exchange.rs b/src/r0/client_exchange.rs index 033d0fd1..6e68ce68 100644 --- a/src/r0/client_exchange.rs +++ b/src/r0/client_exchange.rs @@ -12,8 +12,9 @@ use serde::{ }; pub mod send_event_to_device; + /// Represents one or all of a user's devices. -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum DeviceIdOrAllDevices { /// Represents a device Id for one of a user's devices. DeviceId(DeviceId), diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index afef7244..d1cace11 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -1,6 +1,6 @@ //! [PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-sendtodevice-eventtype-txnid) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_events::{collections::all, EventResult}; @@ -29,7 +29,7 @@ ruma_api! { /// device. Individual message events can be sent to devices, but all /// events must be of the same type. #[wrap_incoming(all::Event with EventResult)] - pub messages: HashMap> + pub messages: BTreeMap> } response {} diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 1fc91089..1d14d27d 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -1,7 +1,7 @@ //! Endpoints for key management use std::{ - collections::HashMap, + collections::BTreeMap, convert::TryFrom, fmt::{Debug, Display, Error as FmtError, Formatter}, }; @@ -19,7 +19,7 @@ pub mod get_keys; pub mod upload_keys; /// The basic key algorithms in the specification -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub enum KeyAlgorithm { /// The Ed25519 signature algorithm. #[serde(rename = "ed25519")] @@ -59,7 +59,7 @@ impl TryFrom<&'_ str> for KeyAlgorithm { } /// A key algorithm and a device id, combined with a ':' -#[derive(Debug, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub DeviceId); impl Serialize for AlgorithmAndDeviceId { @@ -116,9 +116,9 @@ pub struct DeviceKeys { /// The encryption algorithms supported by this device. pub algorithms: Vec, /// Public identity keys. - pub keys: HashMap, + pub keys: BTreeMap, /// Signatures for the device key object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, /// Additional data added to the device key information by intermediate servers, and /// not covered by the signatures. #[serde(skip_serializing_if = "Option::is_none")] @@ -138,7 +138,7 @@ pub struct SignedKey { /// Base64-encoded 32-byte Curve25519 public key. pub key: String, /// Signatures for the key object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, } /// A one-time public key for "pre-key" messages. diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 70b5a7ec..8a2d7cd2 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/claim](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-claim) -use std::collections::HashMap; +use std::collections::BTreeMap; use std::time::Duration; @@ -31,16 +31,16 @@ ruma_api! { pub timeout: Option, /// The keys to be claimed. - pub one_time_keys: HashMap>, + pub one_time_keys: BTreeMap>, } response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: HashMap, + pub failures: BTreeMap, /// One-time keys for the queried devices. - pub one_time_keys: HashMap>>, + pub one_time_keys: BTreeMap>>, } error: crate::Error diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index b9e3ecb4..64032e30 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/query](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-query) -use std::{collections::HashMap, time::Duration}; +use std::{collections::BTreeMap, time::Duration}; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; @@ -29,7 +29,7 @@ ruma_api! { pub timeout: Option, /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. - pub device_keys: HashMap>, + pub device_keys: BTreeMap>, /// If the client is fetching keys as a result of a device update received in a sync request, /// this should be the 'since' token of that sync request, or any later sync token. @@ -41,10 +41,10 @@ ruma_api! { response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: HashMap, + pub failures: BTreeMap, /// Information on the queried devices. - pub device_keys: HashMap>, + pub device_keys: BTreeMap>, } error: crate::Error diff --git a/src/r0/keys/upload_keys.rs b/src/r0/keys/upload_keys.rs index d99074b6..95224f3c 100644 --- a/src/r0/keys/upload_keys.rs +++ b/src/r0/keys/upload_keys.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/keys/upload](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-upload) -use std::collections::HashMap; +use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; @@ -24,13 +24,13 @@ ruma_api! { /// One-time public keys for "pre-key" messages. #[serde(skip_serializing_if = "Option::is_none")] - pub one_time_keys: Option>, + pub one_time_keys: Option>, } response { /// For each key algorithm, the number of unclaimed one-time keys of that /// type currently held on the server for this device. - pub one_time_key_counts: HashMap + pub one_time_key_counts: BTreeMap } error: crate::Error diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 03af3e75..ce885afb 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -12,7 +12,7 @@ pub mod kick_user; pub mod leave_room; pub mod unban_user; -use std::collections::HashMap; +use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; @@ -27,7 +27,7 @@ pub struct ThirdPartySigned { /// The Matrix ID of the user who issued the invite. pub sender: String, /// A signatures object containing a signature of the entire signed object. - pub signatures: HashMap>, + pub signatures: BTreeMap>, /// The state key of the m.third_party_invite event. pub token: String, } diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index e4727d27..f853af60 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/joined_members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-joined-members) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -25,7 +25,7 @@ ruma_api! { response { /// A list of the rooms the user is in, i.e. /// the ID of each room in which the user has joined membership. - pub joined: HashMap, + pub joined: BTreeMap, } error: crate::Error diff --git a/src/r0/push.rs b/src/r0/push.rs index d1856ff3..28bd0d16 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -27,7 +27,9 @@ pub mod set_pushrule_actions; pub mod set_pushrule_enabled; /// The kinds of push rules that are available -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Display, EnumString)] +#[derive( + Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Display, EnumString, +)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum RuleKind { diff --git a/src/r0/push/get_pushrules_all.rs b/src/r0/push/get_pushrules_all.rs index 6954811f..ac08ddfe 100644 --- a/src/r0/push/get_pushrules_all.rs +++ b/src/r0/push/get_pushrules_all.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/pushrules/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -20,7 +20,7 @@ ruma_api! { response { /// The global ruleset - pub global: HashMap> + pub global: BTreeMap> } error: crate::Error diff --git a/src/r0/push/get_pushrules_global_scope.rs b/src/r0/push/get_pushrules_global_scope.rs index fbefecfc..5857e64e 100644 --- a/src/r0/push/get_pushrules_global_scope.rs +++ b/src/r0/push/get_pushrules_global_scope.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/pushrules/global/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -21,7 +21,7 @@ ruma_api! { response { /// The global ruleset. #[ruma_api(body)] - pub global: HashMap>, + pub global: BTreeMap>, } error: crate::Error diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 441cb58e..74cb80ea 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -1,6 +1,6 @@ //! [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-search) -use std::collections::HashMap; +use std::collections::BTreeMap; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; @@ -102,7 +102,7 @@ pub struct EventContextResult { /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] - pub profile_info: Option>, + pub profile_info: Option>, /// Pagination token for the start of the chunk. pub start: String, } @@ -115,7 +115,7 @@ pub struct Grouping { } /// The key within events to use for this grouping. -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "snake_case")] pub enum GroupingKey { /// `room_id` @@ -172,7 +172,7 @@ pub struct RoomEventResults { pub count: UInt, /// Any groups that were requested. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - pub groups: HashMap>, + pub groups: BTreeMap>, /// Token that can be used to get the next batch of results, by passing as the `next_batch` /// parameter to the next call. If this field is absent, there are no more results. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 5c3a5dd9..5b06a70e 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-admin-whois-userid) -use std::{collections::HashMap, time::SystemTime}; +use std::{collections::BTreeMap, time::SystemTime}; use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -26,7 +26,7 @@ ruma_api! { /// The Matrix user ID of the user. pub user_id: UserId, /// A map of the user's device identifiers to information about that device. - pub devices: HashMap, + pub devices: BTreeMap, } error: crate::Error diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index cb6200e2..49d47a7e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/sync](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-sync) -use std::{collections::HashMap, time::Duration}; +use std::{collections::BTreeMap, time::Duration}; use js_int::UInt; use ruma_api::{ruma_api, Outgoing}; @@ -79,8 +79,8 @@ ruma_api! { pub device_lists: Option, /// For each key algorithm, the number of unclaimed one-time keys /// currently held on the server for a device. - #[serde(default, skip_serializing_if = "HashMap::is_empty")] - pub device_one_time_keys_count: HashMap, + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub device_one_time_keys_count: BTreeMap, } error: crate::Error @@ -131,13 +131,13 @@ pub enum Filter { pub struct Rooms { /// The rooms that the user has left or been banned from. #[wrap_incoming(LeftRoom)] - pub leave: HashMap, + pub leave: BTreeMap, /// The rooms that the user has joined. #[wrap_incoming(JoinedRoom)] - pub join: HashMap, + pub join: BTreeMap, /// The rooms that the user has been invited to. #[wrap_incoming(InvitedRoom)] - pub invite: HashMap, + pub invite: BTreeMap, } /// Historical updates to left rooms. diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index ad0796a9..99a3566f 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -7,7 +7,7 @@ pub mod get_protocols; pub mod get_user_for_protocol; pub mod get_user_for_user_id; -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_identifiers::{RoomAliasId, UserId}; @@ -23,7 +23,7 @@ pub struct Protocol { /// A content URI representing an icon for the third party protocol. pub icon: String, /// The type definitions for the fields defined in `user_fields` and `location_fields`. - pub field_types: HashMap, + pub field_types: BTreeMap, /// A list of objects representing independent instances of configuration. pub instances: Vec, } @@ -37,7 +37,7 @@ pub struct ProtocolInstance { #[serde(skip_serializing_if = "Option::is_none")] pub icon: Option, /// Preset values for `fields` the client may use to search by. - pub fields: HashMap, + pub fields: BTreeMap, /// A unique identifier across all instances. pub network_id: String, } @@ -59,7 +59,7 @@ pub struct Location { /// The protocol ID that the third party location is a part of. pub protocol: String, /// Information used to identify this third party location. - pub fields: HashMap, + pub fields: BTreeMap, } /// A third party network user. @@ -70,7 +70,7 @@ pub struct User { /// The protocol ID that the third party user is a part of. pub protocol: String, /// Information used to identify this third party user. - pub fields: HashMap, + pub fields: BTreeMap, } /// The medium of a third party identifier. diff --git a/src/r0/thirdparty/get_location_for_protocol.rs b/src/r0/thirdparty/get_location_for_protocol.rs index 7cf5633c..e0c30b17 100644 --- a/src/r0/thirdparty/get_location_for_protocol.rs +++ b/src/r0/thirdparty/get_location_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/location/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-location-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { diff --git a/src/r0/thirdparty/get_protocols.rs b/src/r0/thirdparty/get_protocols.rs index e563ab61..aad510f1 100644 --- a/src/r0/thirdparty/get_protocols.rs +++ b/src/r0/thirdparty/get_protocols.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/protocols](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-protocols) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -21,7 +21,7 @@ ruma_api! { response { /// Metadata about protocols supported by the homeserver. #[ruma_api(body)] - pub protocols: HashMap, + pub protocols: BTreeMap, } error: crate::Error diff --git a/src/r0/thirdparty/get_user_for_protocol.rs b/src/r0/thirdparty/get_user_for_protocol.rs index 557f1232..ab9c74a1 100644 --- a/src/r0/thirdparty/get_user_for_protocol.rs +++ b/src/r0/thirdparty/get_user_for_protocol.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/r0/thirdparty/user/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-user-protocol) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -23,7 +23,7 @@ ruma_api! { /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] - pub fields: HashMap, + pub fields: BTreeMap, } response { diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index b8fc8308..874c334a 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-versions) -use std::collections::HashMap; +use std::collections::BTreeMap; use ruma_api::ruma_api; @@ -20,8 +20,8 @@ ruma_api! { /// A list of Matrix client API protocol versions supported by the homeserver. pub versions: Vec, /// Experimental features supported by the server. - #[serde(default, skip_serializing_if = "HashMap::is_empty")] - pub unstable_features: HashMap + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub unstable_features: BTreeMap } error: crate::Error From db04471cf290355cd2307aaa509e2699d3d9da31 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 20:09:14 +0200 Subject: [PATCH 272/350] Update ruma-events to 0.19.0-rc.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 66426a6a..ebeb0d0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } ruma-api = "0.16.0-rc.1" -ruma-events = "0.19.0-rc.1" +ruma-events = "0.19.0-rc.2" ruma-identifiers = "0.15.1" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } From 3ecc114ca6585f27592b2deedb3e279fafab8a69 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 20:09:45 +0200 Subject: [PATCH 273/350] Bump version to 0.8.0-rc.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ebeb0d0a..87503cd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.7.2" +version = "0.8.0-rc.1" edition = "2018" [dependencies] From 0d080a7ffad2703df401afbe572608317fe8c31d Mon Sep 17 00:00:00 2001 From: iinuwa Date: Sun, 19 Apr 2020 15:09:45 -0500 Subject: [PATCH 274/350] Add UIAA error types --- CHANGELOG.md | 10 +- src/error.rs | 2 + src/r0.rs | 1 + src/r0/account.rs | 40 ---- src/r0/account/add_3pid.rs | 31 +++ src/r0/account/change_password.rs | 6 +- src/r0/account/deactivate.rs | 8 +- src/r0/account/register.rs | 6 +- src/r0/device/delete_device.rs | 7 +- src/r0/device/delete_devices.rs | 7 +- src/r0/uiaa.rs | 363 ++++++++++++++++++++++++++++++ 11 files changed, 423 insertions(+), 58 deletions(-) create mode 100644 src/r0/account/add_3pid.rs create mode 100644 src/r0/uiaa.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4ca735..99d0b4fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,13 @@ Breaking changes: * Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` -* Add `auth_parameters` to `r0::account::AuthenticationData` +* Modify `r0::account::AuthenticationData`: + - Rename to `AuthData` + - Change to an enum to facilitate fallback auth acknowledgements + - Add `auth_parameters` field + - Move to `r0::uiaa` module * Add `room_network` parameter to `r0::directory::get_public_rooms_filtered` to - represent `include_all_networks` and `third_party_instance_id` Matrix fields. + represent `include_all_networks` and `third_party_instance_id` Matrix fields * Update `r0::account::register` endpoint: * Remove `bind_email` request field (removed in r0.6.0) * Remove `inhibit_login` request field, make `access_token` and `device_id` response fields optional (added in r0.4.0) @@ -19,7 +23,7 @@ Breaking changes: Improvements: -* Add types for User-Interactive Authentication API: `r0::account::{UserInteractiveAuthenticationInfo, AuthenticationFlow}` +* Add types for User-Interactive Authentication API: `r0::uiaa::{AuthFlow, UiaaInfo, UiaaResponse}` * Add missing serde attributes to `get_content_thumbnail` query parameters # 0.7.2 diff --git a/src/error.rs b/src/error.rs index 999f40aa..0a5ce361 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; /// An enum for the error kind. Items may contain additional information. #[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[serde(tag = "errcode")] +#[cfg_attr(test, derive(PartialEq))] pub enum ErrorKind { /// M_FORBIDDEN #[serde(rename = "M_FORBIDDEN")] @@ -98,6 +99,7 @@ pub enum ErrorKind { /// A Matrix Error without a status code #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct ErrorBody { /// A value which can be used to handle an error message #[serde(flatten)] diff --git a/src/r0.rs b/src/r0.rs index 9ed2405f..3a761cbc 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -30,5 +30,6 @@ pub mod sync; pub mod tag; pub mod thirdparty; pub mod typing; +pub mod uiaa; pub mod user_directory; pub mod voip; diff --git a/src/r0/account.rs b/src/r0/account.rs index 6598d76d..c015ab2f 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -17,48 +17,8 @@ pub mod unbind_3pid; pub mod whoami; -use std::collections::BTreeMap; - use serde::{Deserialize, Serialize}; -/// Additional authentication information for the user-interactive authentication API. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct AuthenticationData { - /// The login type that the client is attempting to complete. - #[serde(rename = "type")] - pub kind: String, - /// The value of the session key given by the homeserver. - pub session: Option, - /// Parameters submitted for a particular authentication stage. - #[serde(flatten)] - pub auth_parameters: BTreeMap, -} - -/// Information about available authentication flows and status for -/// User-Interactive Authenticiation API. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct UserInteractiveAuthenticationInfo { - /// List of authentication flows available for this endpoint. - pub flows: Vec, - /// List of stages in the current flow completed by the client. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub completed: Vec, - /// Authentication parameters required for the client to complete authentication. - pub params: serde_json::Value, - /// Session key for client to use to complete authentication. - #[serde(skip_serializing_if = "Option::is_none")] - pub session: Option, -} - -/// Description of steps required to authenticate via the User-Interactive -/// Authentication API. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct AuthenticationFlow { - /// Ordered list of stages required to complete authentication. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub stages: Vec, -} - /// Additional authentication information for requestToken endpoints. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct IdentityServerInfo { diff --git a/src/r0/account/add_3pid.rs b/src/r0/account/add_3pid.rs new file mode 100644 index 00000000..adef2d45 --- /dev/null +++ b/src/r0/account/add_3pid.rs @@ -0,0 +1,31 @@ +//! [POST /_matrix/client/r0/account/3pid/add](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-add) + +use ruma_api::ruma_api; + +use crate::r0::uiaa::{AuthData, UiaaResponse}; + +ruma_api! { + metadata { + description: "Add contact information to a user's account", + method: POST, + name: "add_3pid", + path: "/_matrix/client/r0/account/3pid/add", + rate_limited: true, + requires_authentication: true, + } + + request { + /// Additional information for the User-Interactive Authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The session identifier given by the identity server. + pub sid: String, + } + + response {} + + error: UiaaResponse +} + diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index abb83411..6eb5f045 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; -use super::AuthenticationData; +use crate::r0::uiaa::{AuthData, UiaaResponse}; ruma_api! { metadata { @@ -18,10 +18,10 @@ ruma_api! { /// The new password for the account. pub new_password: String, /// Additional authentication information for the user-interactive authentication API. - pub auth: Option, + pub auth: Option, } response {} - error: crate::Error + error: UiaaResponse } diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 33af8c3a..5a21a071 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -2,7 +2,9 @@ use ruma_api::ruma_api; -use super::{AuthenticationData, ThirdPartyIdRemovalStatus}; +use crate::r0::uiaa::{AuthData, UiaaResponse}; + +use super::ThirdPartyIdRemovalStatus; ruma_api! { metadata { @@ -17,7 +19,7 @@ ruma_api! { request { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option, + pub auth: Option, /// Identity server from which to unbind the user's third party /// identifier. #[serde(skip_serializing_if = "Option::is_none")] @@ -29,5 +31,5 @@ ruma_api! { pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } - error: crate::Error + error: UiaaResponse } diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index f517f4ca..27046397 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -4,7 +4,7 @@ use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; -use super::AuthenticationData; +use crate::r0::uiaa::{AuthData, UiaaResponse}; ruma_api! { metadata { @@ -46,7 +46,7 @@ ruma_api! { /// It should be left empty, or omitted, unless an earlier call returned an response /// with status code 401. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option, + pub auth: Option, /// Kind of account to register /// /// Defaults to `User` if omitted. @@ -73,7 +73,7 @@ ruma_api! { pub device_id: Option, } - error: crate::Error + error: UiaaResponse } /// The kind of account being registered. diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs index b99b8592..2f5f33f0 100644 --- a/src/r0/device/delete_device.rs +++ b/src/r0/device/delete_device.rs @@ -1,9 +1,10 @@ //! [DELETE /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-devices-deviceid) -use crate::r0::account::AuthenticationData; use ruma_api::ruma_api; use ruma_identifiers::DeviceId; +use crate::r0::uiaa::{AuthData, UiaaResponse}; + ruma_api! { metadata { description: "Delete a device for authenticated user.", @@ -20,10 +21,10 @@ ruma_api! { pub device_id: DeviceId, /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option, + pub auth: Option, } response {} - error: crate::Error + error: UiaaResponse } diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/delete_devices.rs index ef74419a..d8f35b6d 100644 --- a/src/r0/device/delete_devices.rs +++ b/src/r0/device/delete_devices.rs @@ -1,9 +1,10 @@ //! [POST /_matrix/client/r0/delete_devices](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-delete-devices) -use crate::r0::account::AuthenticationData; use ruma_api::ruma_api; use ruma_identifiers::DeviceId; +use crate::r0::uiaa::{AuthData, UiaaResponse}; + ruma_api! { metadata { description: "Delete specified devices.", @@ -20,10 +21,10 @@ ruma_api! { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option, + pub auth: Option, } response {} - error: crate::Error + error: UiaaResponse } diff --git a/src/r0/uiaa.rs b/src/r0/uiaa.rs new file mode 100644 index 00000000..bc6ac20b --- /dev/null +++ b/src/r0/uiaa.rs @@ -0,0 +1,363 @@ +//! Module for User-Interactive Authentication API types. + +use std::collections::BTreeMap; + +use ruma_api::{error::ResponseDeserializationError, EndpointError}; +use serde::{Deserialize, Serialize}; +use serde_json::Value as JsonValue; + +use crate::error::{Error as MatrixError, ErrorBody}; + +/// Additional authentication information for the user-interactive authentication API. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(untagged)] +#[cfg_attr(test, derive(PartialEq))] +pub enum AuthData { + /// Used for sending UIAA authentication requests to the homeserver directly + /// from the client. + DirectRequest { + /// The login type that the client is attempting to complete. + #[serde(rename = "type")] + kind: String, + /// The value of the session key given by the homeserver. + #[serde(skip_serializing_if = "Option::is_none")] + session: Option, + /// Parameters submitted for a particular authentication stage. + #[serde(flatten)] + auth_parameters: BTreeMap, + }, + /// Used by the client to acknowledge that the user has completed a UIAA + /// stage through the fallback method. + FallbackAcknowledgement { + /// The value of the session key given by the homeserver. + session: String, + }, +} + +/// Information about available authentication flows and status for +/// User-Interactive Authenticiation API. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(test, derive(PartialEq))] +pub struct UiaaInfo { + /// List of authentication flows available for this endpoint. + pub flows: Vec, + /// List of stages in the current flow completed by the client. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub completed: Vec, + /// Authentication parameters required for the client to complete authentication. + pub params: JsonValue, + /// Session key for client to use to complete authentication. + #[serde(skip_serializing_if = "Option::is_none")] + pub session: Option, + /// Authentication-related errors for previous request returned by homeserver. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub auth_error: Option, +} + +/// Description of steps required to authenticate via the User-Interactive +/// Authentication API. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(test, derive(PartialEq))] +pub struct AuthFlow { + /// Ordered list of stages required to complete authentication. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub stages: Vec, +} + +/// Contains either a User-Interactive Authentication API response body or a +/// Matrix error. +#[derive(Clone, Debug)] +pub enum UiaaResponse { + /// User-Interactive Authentication API response + AuthResponse(UiaaInfo), + /// Matrix error response + MatrixError(MatrixError), +} + +impl From for UiaaResponse { + fn from(error: MatrixError) -> Self { + Self::MatrixError(error) + } +} + +impl EndpointError for UiaaResponse { + fn try_from_response( + response: http::Response>, + ) -> Result { + if response.status() == http::StatusCode::UNAUTHORIZED { + if let Ok(authentication_info) = serde_json::from_slice::(response.body()) { + return Ok(UiaaResponse::AuthResponse(authentication_info)); + } + } + + MatrixError::try_from_response(response).map(From::from) + } +} + +impl From for http::Response> { + fn from(uiaa_response: UiaaResponse) -> http::Response> { + match uiaa_response { + UiaaResponse::AuthResponse(authentication_info) => http::Response::builder() + .header(http::header::CONTENT_TYPE, "application/json") + .status(&http::StatusCode::UNAUTHORIZED) + .body(serde_json::to_vec(&authentication_info).unwrap()) + .unwrap(), + UiaaResponse::MatrixError(error) => http::Response::from(error), + } + } +} + +#[cfg(test)] +mod tests { + use std::collections::BTreeMap; + + use ruma_api::EndpointError; + use serde_json::{ + from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, + }; + + use super::{AuthData, AuthFlow, UiaaInfo, UiaaResponse}; + use crate::error::{ErrorBody, ErrorKind}; + + #[test] + fn test_serialize_authentication_data_direct_request() { + let mut auth_parameters = BTreeMap::new(); + auth_parameters.insert( + "example_credential".into(), + JsonValue::String("verypoorsharedsecret".into()), + ); + let authentication_data = AuthData::DirectRequest { + kind: "example.type.foo".to_string(), + session: Some("ZXY000".to_string()), + auth_parameters, + }; + + assert_eq!( + json!({ "type": "example.type.foo", "session": "ZXY000", "example_credential": "verypoorsharedsecret" }), + to_json_value(authentication_data).unwrap() + ); + } + + #[test] + fn test_deserialize_authentication_data_direct_request() { + let mut auth_parameters = BTreeMap::new(); + auth_parameters.insert( + "example_credential".into(), + JsonValue::String("verypoorsharedsecret".into()), + ); + let authentication_data = AuthData::DirectRequest { + kind: "example.type.foo".into(), + session: Some("opaque_session_id".to_string()), + auth_parameters, + }; + let json = json!({ "type": "example.type.foo", "session": "opaque_session_id", "example_credential": "verypoorsharedsecret", }); + + assert_eq!( + from_json_value::(json).unwrap(), + authentication_data + ); + } + + #[test] + fn test_serialize_authentication_data_fallback() { + let authentication_data = AuthData::FallbackAcknowledgement { + session: "ZXY000".to_string(), + }; + + assert_eq!( + json!({ "session": "ZXY000" }), + to_json_value(authentication_data).unwrap() + ); + } + + #[test] + fn test_deserialize_authentication_data_fallback() { + let authentication_data = AuthData::FallbackAcknowledgement { + session: "opaque_session_id".to_string(), + }; + let json = json!({ "session": "opaque_session_id" }); + + assert_eq!( + from_json_value::(json).unwrap(), + authentication_data + ); + } + + #[test] + fn test_serialize_uiaa_info() { + let params = json!({ + "example.type.baz": { + "example_key": "foobar" + } + }); + + let uiaa_info = UiaaInfo { + flows: vec![AuthFlow { + stages: vec!["m.login.password".to_string(), "m.login.dummy".to_string()], + }], + completed: vec!["m.login.password".to_string()], + params, + session: None, + auth_error: None, + }; + + let json = json!({ + "flows": [{ "stages": ["m.login.password", "m.login.dummy"] }], + "completed": ["m.login.password"], + "params": { + "example.type.baz": { + "example_key": "foobar" + } + } + }); + assert_eq!(to_json_value(uiaa_info).unwrap(), json); + } + + #[test] + fn test_deserialize_uiaa_info() { + let json = json!({ + "errcode": "M_FORBIDDEN", + "error": "Invalid password", + "completed": [ "example.type.foo" ], + "flows": [ + { + "stages": [ "example.type.foo", "example.type.bar" ] + }, + { + "stages": [ "example.type.foo", "example.type.baz" ] + } + ], + "params": { + "example.type.baz": { + "example_key": "foobar" + } + }, + "session": "xxxxxx" + }); + + let uiaa_info = UiaaInfo { + auth_error: Some(ErrorBody { + kind: ErrorKind::Forbidden, + message: "Invalid password".to_string(), + }), + completed: vec!["example.type.foo".to_string()], + flows: vec![ + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.bar".to_string(), + ], + }, + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.baz".to_string(), + ], + }, + ], + params: json!({ + "example.type.baz": { + "example_key": "foobar" + } + }), + session: Some("xxxxxx".to_string()), + }; + assert_eq!(from_json_value::(json).unwrap(), uiaa_info); + } + + #[test] + fn test_try_uiaa_response_into_http_response() { + let params = json!({ + "example.type.baz": { + "example_key": "foobar" + } + }); + + let uiaa_info = UiaaInfo { + flows: vec![AuthFlow { + stages: vec!["m.login.password".to_string(), "m.login.dummy".to_string()], + }], + completed: vec!["m.login.password".to_string()], + params, + session: None, + auth_error: None, + }; + let uiaa_response: http::Response> = + UiaaResponse::AuthResponse(uiaa_info.clone()).into(); + + assert_eq!( + serde_json::from_slice::(uiaa_response.body()).unwrap(), + uiaa_info, + ); + assert_eq!( + uiaa_response.status(), + http::status::StatusCode::UNAUTHORIZED + ); + } + + #[test] + fn test_try_uiaa_response_from_http_response() { + let json = serde_json::to_string(&json!({ + "errcode": "M_FORBIDDEN", + "error": "Invalid password", + "completed": [ "example.type.foo" ], + "flows": [ + { + "stages": [ "example.type.foo", "example.type.bar" ] + }, + { + "stages": [ "example.type.foo", "example.type.baz" ] + } + ], + "params": { + "example.type.baz": { + "example_key": "foobar" + } + }, + "session": "xxxxxx" + })) + .unwrap(); + let http_response = http::Response::builder() + .status(http::StatusCode::UNAUTHORIZED) + .body(json.into()) + .unwrap(); + + let uiaa_info = UiaaInfo { + auth_error: Some(ErrorBody { + kind: ErrorKind::Forbidden, + message: "Invalid password".to_string(), + }), + completed: vec!["example.type.foo".to_string()], + flows: vec![ + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.bar".to_string(), + ], + }, + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.baz".to_string(), + ], + }, + ], + params: json!({ + "example.type.baz": { + "example_key": "foobar" + } + }), + session: Some("xxxxxx".to_string()), + }; + + let parsed_uiaa_info = match UiaaResponse::try_from_response(http_response) { + Ok(auth_response) => match auth_response { + UiaaResponse::AuthResponse(uiaa_info) => Some(uiaa_info), + _ => None, + }, + _ => None, + }; + + assert_eq!(parsed_uiaa_info, Some(uiaa_info)); + } +} From fc976a57eaa26d49019a8d9e4e31532fe7f7a0e3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 22:18:32 +0200 Subject: [PATCH 275/350] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d0b4fe..cbe2c46f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Breaking changes: * `push::get_notifications::Notification` * `server::get_user_info::ConnectionInfo` * `device::Device` +* Change all usages of `HashMap` to `BTreeMap` Improvements: From 844321376643e923e7605b54984378baed3a3332 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 22:40:24 +0200 Subject: [PATCH 276/350] Add common types section to CONTRIBUTING.md --- CONTRIBUTING.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbe97a77..6de82d34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,6 +49,20 @@ help you on your way: ## Coding Style +### Common types + +When writing endpoint definitions, use the following mapping from request / +response field types listed in the specification to Rust types: + +Specification type | Rust type +-------------------|--------------------------------------------------------------------------------------------------------------------- +`boolean` | `bool` +`integer` | `js_int::UInt` (unless denoted as signed, then `js_int::Int`) +`string` | If for an identifier (e.g. user ID, room ID), use one of the types from `ruma-identifiers`. Otherwise, use `String`. +`object` | `serde_json::Value` +`[…]` | `Vec<…>` +`{string: …}` | `BTreeMap` (or `BTreeMap`) + ### Import Formatting Organize your imports into three groups separated by blank lines: From 5e0467682f7b76356dc931c955ae00afdf522208 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 23:19:18 +0200 Subject: [PATCH 277/350] Update ruma-events to 0.19.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 87503cd7..173b2ab7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } ruma-api = "0.16.0-rc.1" -ruma-events = "0.19.0-rc.2" +ruma-events = "0.19.0" ruma-identifiers = "0.15.1" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } From 1b7863dc36e6e043ae365791cc719dc190abd660 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 19 Apr 2020 23:19:23 +0200 Subject: [PATCH 278/350] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 173b2ab7..406db497 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.1" +version = "0.8.0-rc.2" edition = "2018" [dependencies] From 738ef99dd7ffa54e34e000f124780b4bdbdc5935 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 20 Apr 2020 15:20:41 +0200 Subject: [PATCH 279/350] Implement Display, Error for error::Error --- src/error.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 0a5ce361..efbe5d28 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,99 +1,131 @@ //! Errors that can be sent from the homeserver. +use std::fmt::{self, Display, Formatter}; + use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; +use strum::{AsRefStr, Display, EnumString}; /// An enum for the error kind. Items may contain additional information. -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, AsRefStr, Display, EnumString)] #[serde(tag = "errcode")] #[cfg_attr(test, derive(PartialEq))] pub enum ErrorKind { /// M_FORBIDDEN #[serde(rename = "M_FORBIDDEN")] + #[strum(to_string = "M_FORBIDDEN")] Forbidden, /// M_UNKNOWN_TOKEN #[serde(rename = "M_UNKNOWN_TOKEN")] + #[strum(to_string = "M_UNKNOWN_TOKEN")] UnknownToken, /// M_MISSING_TOKEN #[serde(rename = "M_MISSING_TOKEN")] + #[strum(to_string = "M_MISSING_TOKEN")] MissingToken, /// M_BAD_JSON #[serde(rename = "M_BAD_JSON")] + #[strum(to_string = "M_BAD_JSON")] BadJson, /// M_NOT_JSON #[serde(rename = "M_NOT_JSON")] + #[strum(to_string = "M_NOT_JSON")] NotJson, /// M_NOT_FOUND #[serde(rename = "M_NOT_FOUND")] + #[strum(to_string = "M_NOT_FOUND")] NotFound, /// M_LIMIT_EXCEEDED #[serde(rename = "M_LIMIT_EXCEEDED")] + #[strum(to_string = "M_LIMIT_EXCEEDED")] LimitExceeded, /// M_UNKNOWN #[serde(rename = "M_UNKNOWN")] + #[strum(to_string = "M_UNKNOWN")] Unknown, /// M_UNRECOGNIZED #[serde(rename = "M_UNRECOGNIZED")] + #[strum(to_string = "M_UNRECOGNIZED")] Unrecognized, /// M_UNAUTHORIZED #[serde(rename = "M_UNAUTHORIZED")] + #[strum(to_string = "M_UNAUTHORIZED")] Unauthorized, /// M_USER_IN_USE #[serde(rename = "M_USER_IN_USE")] + #[strum(to_string = "M_USER_IN_USE")] UserInUse, /// M_INVALID_USERNAME #[serde(rename = "M_INVALID_USERNAME")] + #[strum(to_string = "M_INVALID_USERNAME")] InvalidUsername, /// M_ROOM_IN_USE #[serde(rename = "M_ROOM_IN_USE")] + #[strum(to_string = "M_ROOM_IN_USE")] RoomInUse, /// M_INVALID_ROOM_STATE #[serde(rename = "M_INVALID_ROOM_STATE")] + #[strum(to_string = "M_INVALID_ROOM_STATE")] InvalidRoomState, /// M_THREEPID_IN_USE #[serde(rename = "M_THREEPID_IN_USE")] + #[strum(to_string = "M_THREEPID_IN_USE")] ThreepidInUse, /// M_THREEPID_NOT_FOUND #[serde(rename = "M_THREEPID_NOT_FOUND")] + #[strum(to_string = "M_THREEPID_NOT_FOUND")] ThreepidNotFound, /// M_THREEPID_AUTH_FAILED #[serde(rename = "M_THREEPID_AUTH_FAILED")] + #[strum(to_string = "M_THREEPID_AUTH_FAILED")] ThreepidAuthFailed, /// M_THREEPID_DENIED #[serde(rename = "M_THREEPID_DENIED")] + #[strum(to_string = "M_THREEPID_DENIED")] ThreepidDenied, /// M_SERVER_NOT_TRUSTED #[serde(rename = "M_SERVER_NOT_TRUSTED")] + #[strum(to_string = "M_SERVER_NOT_TRUSTED")] ServerNotTrusted, /// M_UNSUPPORTED_ROOM_VERSION #[serde(rename = "M_UNSUPPORTED_ROOM_VERSION")] + #[strum(to_string = "M_UNSUPPORTED_ROOM_VERSION")] UnsupportedRoomVersion, /// M_INCOMPATIBLE_ROOM_VERSION #[serde(rename = "M_INCOMPATIBLE_ROOM_VERSION")] + #[strum(to_string = "M_INCOMPATIBLE_ROOM_VERSION")] IncompatibleRoomVersion, /// M_BAD_STATE #[serde(rename = "M_BAD_STATE")] + #[strum(to_string = "M_BAD_STATE")] BadState, /// M_GUEST_ACCESS_FORBIDDEN #[serde(rename = "M_GUEST_ACCESS_FORBIDDEN")] + #[strum(to_string = "M_GUEST_ACCESS_FORBIDDEN")] GuestAccessForbidden, /// M_CAPTCHA_NEEDED #[serde(rename = "M_CAPTCHA_NEEDED")] + #[strum(to_string = "M_CAPTCHA_NEEDED")] CaptchaNeeded, /// M_CAPTCHA_INVALID #[serde(rename = "M_CAPTCHA_INVALID")] + #[strum(to_string = "M_CAPTCHA_INVALID")] CaptchaInvalid, /// M_MISSING_PARAM #[serde(rename = "M_MISSING_PARAM")] + #[strum(to_string = "M_MISSING_PARAM")] MissingParam, /// M_INVALID_PARAM #[serde(rename = "M_INVALID_PARAM")] + #[strum(to_string = "M_INVALID_PARAM")] InvalidParam, /// M_TOO_LARGE #[serde(rename = "M_TOO_LARGE")] + #[strum(to_string = "M_TOO_LARGE")] TooLarge, /// M_EXCLUSIVE #[serde(rename = "M_EXCLUSIVE")] + #[strum(to_string = "M_EXCLUSIVE")] Exclusive, } @@ -131,6 +163,20 @@ impl EndpointError for Error { } } +impl Display for Error { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "[{} / {}] {}", + self.status_code.as_u16(), + self.kind, + self.message + ) + } +} + +impl std::error::Error for Error {} + impl From for ErrorBody { fn from(error: Error) -> Self { Self { From 7c961917856fae31db2508b75dc7fa712876d891 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 20 Apr 2020 16:03:56 +0200 Subject: [PATCH 280/350] Update dependencies, bump version to 0.8.0-rc.3 --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 406db497..37352a0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,15 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.2" +version = "0.8.0-rc.3" edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } -ruma-api = "0.16.0-rc.1" +ruma-api = "0.16.0-rc.2" ruma-events = "0.19.0" -ruma-identifiers = "0.15.1" +ruma-identifiers = "0.16.0" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.51" From 3385470dd50673683bed25ddd35eb2519f47ef3f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 20 Apr 2020 17:15:09 +0200 Subject: [PATCH 281/350] Update ruma-events, bump version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 37352a0e..355b4fe0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,14 +9,14 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.3" +version = "0.8.0-rc.4" edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } ruma-api = "0.16.0-rc.2" -ruma-events = "0.19.0" +ruma-events = "0.20.0" ruma-identifiers = "0.16.0" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } From 24b9ea7dc98c830607954bb7010bfaa2e0d7463a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 8 Apr 2020 19:45:42 +0200 Subject: [PATCH 282/350] client_exchange: Use room messages to send out to-device events. --- CHANGELOG.md | 2 ++ src/r0/client_exchange/send_event_to_device.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe2c46f..9b9357e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Breaking changes: * `server::get_user_info::ConnectionInfo` * `device::Device` * Change all usages of `HashMap` to `BTreeMap` +* Change the messages type that gets sent out using the `r0::client_exchange::send_event_to_device` + request. Improvements: diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index d1cace11..5dc9c092 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; -use ruma_events::{collections::all, EventResult}; +use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; use ruma_identifiers::UserId; use super::DeviceIdOrAllDevices; @@ -21,15 +21,15 @@ ruma_api! { request { /// Type of event being sent to each device. #[ruma_api(path)] - pub event_type: String, + pub event_type: EventType, /// A request identifier unique to the access token used to send the request. #[ruma_api(path)] pub txn_id: String, /// A map of users to devices to a message event to be sent to the user's /// device. Individual message events can be sent to devices, but all /// events must be of the same type. - #[wrap_incoming(all::Event with EventResult)] - pub messages: BTreeMap> + #[wrap_incoming(MessageEventContent with EventResult)] + pub messages: BTreeMap> } response {} From eb4b8e559ef8fd689e88b66abef9c10596964ebf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 22 Apr 2020 03:01:33 +0200 Subject: [PATCH 283/350] Update ruma-api, ruma-events --- Cargo.toml | 4 +- .../client_exchange/send_event_to_device.rs | 5 +- src/r0/config/get_global_account_data.rs | 5 +- src/r0/config/get_room_account_data.rs | 5 +- src/r0/context/get_context.rs | 17 +++-- src/r0/membership/get_member_events.rs | 5 +- src/r0/message/create_message_event.rs | 5 +- src/r0/message/get_message_events.rs | 5 +- src/r0/push/get_notifications.rs | 14 ++--- src/r0/room/create_room.rs | 5 +- src/r0/room/get_room_event.rs | 5 +- src/r0/search/search_events.rs | 29 ++++----- src/r0/state/get_state_events.rs | 5 +- src/r0/sync/sync_events.rs | 63 +++++++------------ src/r0/tag/get_tags.rs | 5 +- 15 files changed, 68 insertions(+), 109 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 355b4fe0..9343fe78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } -ruma-api = "0.16.0-rc.2" -ruma-events = "0.20.0" +ruma-api = "0.16.0-rc.3" +ruma-events = "0.21.0-beta.1" ruma-identifiers = "0.16.0" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index 5dc9c092..f31e9eff 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; +use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; use ruma_identifiers::UserId; use super::DeviceIdOrAllDevices; @@ -28,8 +28,7 @@ ruma_api! { /// A map of users to devices to a message event to be sent to the user's /// device. Individual message events can be sent to devices, but all /// events must be of the same type. - #[wrap_incoming(MessageEventContent with EventResult)] - pub messages: BTreeMap> + pub messages: BTreeMap>> } response {} diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs index 611781c8..41cb40f9 100644 --- a/src/r0/config/get_global_account_data.rs +++ b/src/r0/config/get_global_account_data.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-account-data-type) use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::UserId; ruma_api! { @@ -26,8 +26,7 @@ ruma_api! { response { /// Account data content for the given type. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub account_data: only::Event, + pub account_data: EventJson, } error: crate::Error diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs index 7c79bad3..2f7a978e 100644 --- a/src/r0/config/get_room_account_data.rs +++ b/src/r0/config/get_room_account_data.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-rooms-roomid-account-data-type) use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::{RoomId, UserId}; ruma_api! { @@ -29,8 +29,7 @@ ruma_api! { response { /// Account data content for the given type. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub account_data: only::Event, + pub account_data: EventJson, } error: crate::Error diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index dc6ff9a1..0f39509b 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::{EventId, RoomId}; use crate::r0::filter::RoomEventFilter; @@ -40,21 +40,20 @@ ruma_api! { /// A token that can be used to paginate forwards with. pub end: String, /// Details of the requested event. - #[wrap_incoming(with EventResult)] - pub event: only::RoomEvent, + pub event: EventJson, /// A list of room events that happened just after the requested event, in chronological /// order. - #[wrap_incoming(only::RoomEvent with EventResult)] - pub events_after: Vec, + + pub events_after: Vec>, /// A list of room events that happened just before the requested event, in /// reverse-chronological order. - #[wrap_incoming(only::RoomEvent with EventResult)] - pub events_before: Vec, + + pub events_before: Vec>, /// A token that can be used to paginate backwards with. pub start: String, /// The state of the room at the last event returned. - #[wrap_incoming(only::StateEvent with EventResult)] - pub state: Vec, + + pub state: Vec>, } error: crate::Error diff --git a/src/r0/membership/get_member_events.rs b/src/r0/membership/get_member_events.rs index f4fb29bd..76d83b65 100644 --- a/src/r0/membership/get_member_events.rs +++ b/src/r0/membership/get_member_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members) use ruma_api::ruma_api; -use ruma_events::{room::member::MemberEvent, EventResult}; +use ruma_events::{room::member::MemberEvent, EventJson}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -42,8 +42,7 @@ ruma_api! { response { /// A list of member events. - #[wrap_incoming(MemberEvent with EventResult)] - pub chunk: Vec + pub chunk: Vec> } error: crate::Error diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index 4849641d..573dff04 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -1,7 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; +use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,8 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub data: MessageEventContent, + pub data: EventJson, } response { diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index e5220d2a..144ce86f 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::all::RoomEvent, EventResult}; +use ruma_events::{collections::all::RoomEvent, EventJson}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -60,8 +60,7 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - #[wrap_incoming(RoomEvent with EventResult)] - pub chunk: Vec, + pub chunk: Vec>, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs index de263b96..43a946c3 100644 --- a/src/r0/push/get_notifications.rs +++ b/src/r0/push/get_notifications.rs @@ -3,10 +3,10 @@ use std::time::SystemTime; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; -use ruma_events::{collections::all, EventResult}; +use ruma_api::ruma_api; +use ruma_events::{collections::all, EventJson}; use ruma_identifiers::RoomId; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use super::Action; @@ -46,22 +46,20 @@ ruma_api! { /// The list of events that triggered notifications. - #[wrap_incoming(Notification)] - pub notifications: Vec, + pub notifications: Vec>, } error: crate::Error } /// Represents a notification -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Notification { /// The actions to perform when the conditions for this rule are met. pub actions: Vec, /// The event that triggered the notification. - #[wrap_incoming(with EventResult)] - pub event: all::Event, + pub event: EventJson, /// The profile tag of the rule that matched this event. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 7dc1be99..c29cc996 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom) use ruma_api::ruma_api; -use ruma_events::{room::power_levels::PowerLevelsEventContent, EventResult}; +use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -46,8 +46,7 @@ ruma_api! { pub name: Option, /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(PowerLevelsEventContent with EventResult)] - pub power_level_content_override: Option, + pub power_level_content_override: Option>, /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs index 29450ae4..b38c9e7f 100644 --- a/src/r0/room/get_room_event.rs +++ b/src/r0/room/get_room_event.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-event-eventid) use ruma_api::ruma_api; -use ruma_events::{collections::all, EventResult}; +use ruma_events::{collections::all, EventJson}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -25,8 +25,7 @@ ruma_api! { response { /// Arbitrary JSON of the event body. Returns both room and state events. - #[wrap_incoming(with EventResult)] - pub event: all::RoomEvent, + pub event: EventJson, } error: crate::Error diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 74cb80ea..525c6bbf 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -3,8 +3,8 @@ use std::collections::BTreeMap; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; -use ruma_events::{collections::all::Event, EventResult}; +use ruma_api::ruma_api; +use ruma_events::{collections::all::Event, EventJson}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -32,7 +32,6 @@ ruma_api! { response { /// A grouping of search results by category. - #[wrap_incoming] pub search_categories: ResultCategories, } @@ -87,18 +86,16 @@ pub struct EventContext { } /// Context for search results, if requested. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventContextResult { /// Pagination token for the end of the chunk. pub end: String, /// Events just after the result. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(Event with EventResult)] - pub events_after: Option>, + pub events_after: Option>>, /// Events just before the result. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(Event with EventResult)] - pub events_before: Option>, + pub events_before: Option>>, /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] @@ -157,17 +154,16 @@ pub enum OrderBy { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct ResultCategories { /// Room event results. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(RoomEventResults)] - pub room_events: Option, + pub room_events: Option, } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Serialize, Outgoing)] -pub struct RoomEventResults { +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomEventJsons { /// An approximate count of the total number of results found. pub count: UInt, /// Any groups that were requested. @@ -178,7 +174,6 @@ pub struct RoomEventResults { #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, /// List of results in the requested order. - #[wrap_incoming(SearchResult)] pub results: Vec, /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. @@ -202,17 +197,15 @@ pub struct ResultGroup { } /// A search result. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct SearchResult { /// Context for result, if requested. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(EventContextResult)] pub context: Option, /// A number that describes how closely this result matches the search. Higher is closer. pub rank: f64, /// The event that matched. - #[wrap_incoming(with EventResult)] - pub result: Event, + pub result: EventJson, } /// A user profile. diff --git a/src/r0/state/get_state_events.rs b/src/r0/state/get_state_events.rs index d45ddd43..35968905 100644 --- a/src/r0/state/get_state_events.rs +++ b/src/r0/state/get_state_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) use ruma_api::ruma_api; -use ruma_events::{collections::all::StateEvent, EventResult}; +use ruma_events::{collections::all::StateEvent, EventJson}; use ruma_identifiers::RoomId; ruma_api! { @@ -25,8 +25,7 @@ ruma_api! { /// list of events. If the user has left the room then this will be the state of the /// room when they left as a list of events. #[ruma_api(body)] - #[wrap_incoming(StateEvent with EventResult)] - pub room_state: Vec, + pub room_state: Vec>, } error: crate::Error diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 49d47a7e..24fa044f 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, time::Duration}; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; +use ruma_api::ruma_api; use ruma_events::{ collections::{ all::{RoomEvent, StateEvent}, @@ -12,7 +12,7 @@ use ruma_events::{ presence::PresenceEvent, stripped::AnyStrippedStateEvent, to_device::AnyToDeviceEvent, - EventResult, + EventJson, }; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -63,14 +63,11 @@ ruma_api! { /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, /// Updates to rooms. - #[wrap_incoming] pub rooms: Rooms, /// Updates to the presence status of other users. - #[wrap_incoming] pub presence: Presence, /// Messages sent dirrectly between devices. #[serde(default, skip_serializing_if = "ToDevice::is_empty")] - #[wrap_incoming] pub to_device: ToDevice, /// Information on E2E device updates. /// @@ -127,36 +124,30 @@ pub enum Filter { } /// Updates to rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Rooms { /// The rooms that the user has left or been banned from. - #[wrap_incoming(LeftRoom)] pub leave: BTreeMap, /// The rooms that the user has joined. - #[wrap_incoming(JoinedRoom)] pub join: BTreeMap, /// The rooms that the user has been invited to. - #[wrap_incoming(InvitedRoom)] pub invite: BTreeMap, } /// Historical updates to left rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. - #[wrap_incoming] pub timeline: Timeline, /// The state updates for the room up to the start of the timeline. - #[wrap_incoming] pub state: State, /// The private data that this user has attached to this room. - #[wrap_incoming] pub account_data: AccountData, } /// Updates to joined rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct JoinedRoom { /// Information about the room which clients may need to correctly render it /// to users. @@ -164,19 +155,15 @@ pub struct JoinedRoom { /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, /// The timeline of messages and state changes in the room. - #[wrap_incoming] pub timeline: Timeline, /// Updates to the state, between the time indicated by the `since` parameter, and the start /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not /// given, or `full_state` is true). - #[wrap_incoming] pub state: State, /// The private data that this user has attached to this room. - #[wrap_incoming] pub account_data: AccountData, /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// room. e.g. typing. - #[wrap_incoming] pub ephemeral: Ephemeral, } @@ -192,7 +179,7 @@ pub struct UnreadNotificationsCount { } /// Events in the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. #[serde(skip_serializing_if = "Option::is_none")] @@ -202,32 +189,28 @@ pub struct Timeline { #[serde(skip_serializing_if = "Option::is_none")] pub prev_batch: Option, /// A list of events. - #[wrap_incoming(RoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// State events in the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct State { /// A list of state events. - #[wrap_incoming(StateEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct AccountData { /// A list of events. - #[wrap_incoming(NonRoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Ephemeral { /// A list of events. - #[wrap_incoming(NonRoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Information about room for rendering to clients. @@ -250,35 +233,31 @@ pub struct RoomSummary { } /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct InvitedRoom { /// The state of a room that the user has been invited to. - #[wrap_incoming] pub invite_state: InviteState, } /// The state of a room that the user has been invited to. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct InviteState { /// A list of state events. - #[wrap_incoming(AnyStrippedStateEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Presence { /// A list of events. - #[wrap_incoming(PresenceEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Messages sent dirrectly between devices. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct ToDevice { /// A list of to-device events. - #[wrap_incoming(AnyToDeviceEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } impl ToDevice { @@ -287,7 +266,7 @@ impl ToDevice { } } -impl Default for IncomingToDevice { +impl Default for ToDevice { fn default() -> Self { Self { events: Vec::new() } } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 14e30112..d02cbe27 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) use ruma_api::ruma_api; -use ruma_events::{tag::TagEventContent, EventResult}; +use ruma_events::{tag::TagEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; ruma_api! { @@ -25,8 +25,7 @@ ruma_api! { response { /// The user's tags for the room. - #[wrap_incoming(with EventResult)] - pub tags: TagEventContent, + pub tags: EventJson, } error: crate::Error From 473cf2386178781688f12c538ee6419869d14a46 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 22 Apr 2020 22:27:54 +0200 Subject: [PATCH 284/350] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9343fe78..026972ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.4" +version = "0.8.0-rc.5" edition = "2018" [dependencies] From aec59b86aa83ccc644d2c460869a7213d36ce876 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Thu, 23 Apr 2020 16:01:51 -0500 Subject: [PATCH 285/350] Add M_USER_DEACTIVATED to ErrorKind --- CHANGELOG.md | 1 + src/error.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9357e9..2a9afdfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Breaking changes: * Change all usages of `HashMap` to `BTreeMap` * Change the messages type that gets sent out using the `r0::client_exchange::send_event_to_device` request. +* Add `M_USER_DEACTIVATED` to `error::ErrorKind` Improvements: diff --git a/src/error.rs b/src/error.rs index efbe5d28..1fb19521 100644 --- a/src/error.rs +++ b/src/error.rs @@ -51,6 +51,10 @@ pub enum ErrorKind { #[serde(rename = "M_UNAUTHORIZED")] #[strum(to_string = "M_UNAUTHORIZED")] Unauthorized, + /// M_USER_DEACTIVATED + #[serde(rename = "M_USER_DEACTIVATED")] + #[strum(to_string = "M_USER_DEACTIVATED")] + UserDeactivated, /// M_USER_IN_USE #[serde(rename = "M_USER_IN_USE")] #[strum(to_string = "M_USER_IN_USE")] From 6e990236c29163a93551c12a8e4478b607f5f9f3 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Thu, 23 Apr 2020 15:54:45 -0500 Subject: [PATCH 286/350] Add missing state response field to get_message_events --- CHANGELOG.md | 1 + src/r0/message/get_message_events.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9afdfd..fe4295a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Improvements: * Add types for User-Interactive Authentication API: `r0::uiaa::{AuthFlow, UiaaInfo, UiaaResponse}` * Add missing serde attributes to `get_content_thumbnail` query parameters +* Add missing `state` response field to `r0::message::get_message_events` # 0.7.2 diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index 144ce86f..e8bb5c70 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -1,8 +1,11 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages) +//! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-messages) use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::all::RoomEvent, EventJson}; +use ruma_events::{ + collections::all::{RoomEvent, StateEvent}, + EventJson, +}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -60,9 +63,13 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub chunk: Vec>, /// The token the pagination ends at. pub end: String, + /// A list of state events relevant to showing the `chunk`. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub state: Vec>, } error: crate::Error From ac44889922bff1ac6fed1f31eca91824cdc1c1c7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 18:49:49 +0200 Subject: [PATCH 287/350] Add builds.sr.ht manifests --- .builds/beta.yml | 30 ++++++++++++++++++++++++++++++ .builds/msrv.yml | 26 ++++++++++++++++++++++++++ .builds/nightly.yml | 32 ++++++++++++++++++++++++++++++++ .builds/stable.yml | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 .builds/beta.yml create mode 100644 .builds/msrv.yml create mode 100644 .builds/nightly.yml create mode 100644 .builds/stable.yml diff --git a/.builds/beta.yml b/.builds/beta.yml new file mode 100644 index 00000000..4a0abed4 --- /dev/null +++ b/.builds/beta.yml @@ -0,0 +1,30 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-client-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install beta --profile minimal -c rustfmt -c clippy + rustup default beta + - test: | + cd ruma-client-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + cargo fmt -- --check + fmt_exit=$? + + cargo clippy --all-targets --all-features -- -D warnings + clippy_exit=$? + + cargo test --no-default-features --verbose + test1_exit=$? + + cargo test --all-features --verbose + test2_exit=$? + + exit $(( $fmt_exit || $clippy_exit || $test1_exit || $test2_exit )) diff --git a/.builds/msrv.yml b/.builds/msrv.yml new file mode 100644 index 00000000..57154b32 --- /dev/null +++ b/.builds/msrv.yml @@ -0,0 +1,26 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-client-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install 1.39.0 --profile minimal + rustup default 1.39.0 + - test: | + cd ruma-client-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + # Only make sure the code builds with the MSRV. Tests can require later + # Rust versions, don't compile or run them. + cargo build --no-default-features --verbose + build1_exit=$? + + cargo build --all-features --verbose + build2_exit=$? + + exit $(( $build1_exit || $build2_exit )) diff --git a/.builds/nightly.yml b/.builds/nightly.yml new file mode 100644 index 00000000..bf523c21 --- /dev/null +++ b/.builds/nightly.yml @@ -0,0 +1,32 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-client-api +tasks: + - rustup: | + rustup toolchain install nightly --profile minimal + rustup default nightly + + # Try installing rustfmt & clippy for nightly, but don't fail the build + # if they are not available + rustup component add rustfmt || true + rustup component add clippy || true + - test: | + cd ruma-client-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + if ( rustup component list | grep -q rustfmt ); then + cargo fmt -- --check + fi + fmt_exit=$? + + if ( rustup component list | grep -q clippy ); then + cargo clippy --all-targets --all-features -- -D warnings + fi + clippy_exit=$? + + exit $(( $fmt_exit || $clippy_exit )) diff --git a/.builds/stable.yml b/.builds/stable.yml new file mode 100644 index 00000000..73ba28ed --- /dev/null +++ b/.builds/stable.yml @@ -0,0 +1,32 @@ +image: archlinux +packages: + - rustup +sources: + - https://github.com/ruma/ruma-client-api +tasks: + - rustup: | + # We specify --profile minimal because we'd otherwise download docs + rustup toolchain install stable --profile minimal -c rustfmt -c clippy + rustup default stable + - test: | + cd ruma-client-api + + # We don't want the build to stop on individual failure of independent + # tools, so capture tool exit codes and set the task exit code manually + set +e + + cargo fmt -- --check + fmt_exit=$? + + cargo clippy --all-targets --all-features -- -D warnings + clippy_exit=$? + + cargo test --no-default-features --verbose + test1_exit=$? + + cargo test --all-features --verbose + test2_exit=$? + + exit $(( $fmt_exit || $clippy_exit || $test1_exit || $test2_exit )) + # TODO: Add audit task once cargo-audit binary releases are available. + # See https://github.com/RustSec/cargo-audit/issues/66 From 172e89357392184c32fb4262dbde518e1ce807b1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 18:51:00 +0200 Subject: [PATCH 288/350] Remove cargo audit to speed up CI --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51cc2c60..01f78d87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,16 +13,8 @@ jobs: before_script: - rustup component add rustfmt - rustup component add clippy - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo install --force cargo-audit - fi - cargo generate-lockfile script: - - | - if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then - cargo audit - fi - cargo fmt -- --check - | if [ "$TRAVIS_RUST_VERSION" != "1.39.0" ]; then From 3478f8653d6f8876288edf5d001bea22dd5ced38 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 19:20:01 +0200 Subject: [PATCH 289/350] Fix MSRV in README.md, builds.sr.ht manifest --- .builds/msrv.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.builds/msrv.yml b/.builds/msrv.yml index 57154b32..5f118e3f 100644 --- a/.builds/msrv.yml +++ b/.builds/msrv.yml @@ -6,8 +6,8 @@ sources: tasks: - rustup: | # We specify --profile minimal because we'd otherwise download docs - rustup toolchain install 1.39.0 --profile minimal - rustup default 1.39.0 + rustup toolchain install 1.40.0 --profile minimal + rustup default 1.40.0 - test: | cd ruma-client-api diff --git a/README.md b/README.md index ca76cd0b..a58f0978 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ These types can be shared by client and server code. ## Minimum Rust version -ruma-client-api requires Rust 1.39.0 or later. +ruma-client-api requires Rust 1.40.0 or later. ## Contributing From d85191d5114a208c3a8e44815390f3803415e73b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 19:39:25 +0200 Subject: [PATCH 290/350] Remove travis CI --- .travis.yml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 01f78d87..00000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: "rust" -cache: "cargo" -rust: - - 1.40.0 - - stable - - beta - - nightly -jobs: - allow_failures: - - rust: nightly - fast_finish: true - -before_script: - - rustup component add rustfmt - - rustup component add clippy - - cargo generate-lockfile -script: - - cargo fmt -- --check - - | - if [ "$TRAVIS_RUST_VERSION" != "1.39.0" ]; then - cargo clippy --all-targets --all-features -- -D warnings - fi - - cargo build --verbose - - cargo test --verbose -if: "type != push OR (tag IS blank AND branch = master)" From f4b9841590f93dc20249115c3041ec1646084c5c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 24 Apr 2020 22:30:22 +0200 Subject: [PATCH 291/350] Fix json escaping breaking login endpoint --- src/r0/session/login.rs | 23 +++------------- src/r0/session/login/user_serde.rs | 42 ++++++++++++------------------ 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index ab7af74d..0028318f 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Serialize}; use crate::r0::thirdparty::Medium; @@ -58,7 +58,8 @@ ruma_api! { } /// Identification information for the user. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(from = "user_serde::UserInfo", into = "user_serde::UserInfo")] pub enum UserInfo { /// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier' /// field). @@ -125,24 +126,6 @@ pub struct IdentityServerInfo { mod user_serde; -impl Serialize for UserInfo { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - user_serde::UserInfo::from(self).serialize(serializer) - } -} - -impl<'de> Deserialize<'de> for UserInfo { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - user_serde::UserInfo::deserialize(deserializer).map(Into::into) - } -} - #[cfg(test)] mod tests { use std::convert::TryInto; diff --git a/src/r0/session/login/user_serde.rs b/src/r0/session/login/user_serde.rs index f7568789..9673f8d1 100644 --- a/src/r0/session/login/user_serde.rs +++ b/src/r0/session/login/user_serde.rs @@ -8,35 +8,31 @@ use super::Medium; // The following three structs could just be used in place of the one in the parent module, but // that one is arguably much easier to deal with. #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub(crate) struct UserInfo<'a> { - #[serde(borrow)] - pub identifier: UserIdentifier<'a>, +pub(crate) struct UserInfo { + pub identifier: UserIdentifier, } #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[serde(tag = "type")] -pub(crate) enum UserIdentifier<'a> { +pub(crate) enum UserIdentifier { #[serde(rename = "m.id.user")] - MatrixId { user: &'a str }, + MatrixId { user: String }, #[serde(rename = "m.id.thirdparty")] - ThirdPartyId { medium: Medium, address: &'a str }, + ThirdPartyId { medium: Medium, address: String }, #[serde(rename = "m.id.phone")] - PhoneNumber { country: &'a str, phone: &'a str }, + PhoneNumber { country: String, phone: String }, } -impl<'a> From<&'a super::UserInfo> for UserInfo<'a> { - fn from(su: &'a super::UserInfo) -> Self { +impl From for UserInfo { + fn from(info: super::UserInfo) -> Self { use super::UserInfo::*; - match su { + match info { MatrixId(user) => UserInfo { identifier: UserIdentifier::MatrixId { user }, }, ThirdPartyId { address, medium } => UserInfo { - identifier: UserIdentifier::ThirdPartyId { - address, - medium: *medium, - }, + identifier: UserIdentifier::ThirdPartyId { address, medium }, }, PhoneNumber { country, phone } => UserInfo { identifier: UserIdentifier::PhoneNumber { country, phone }, @@ -45,20 +41,14 @@ impl<'a> From<&'a super::UserInfo> for UserInfo<'a> { } } -impl Into for UserInfo<'_> { - fn into(self) -> super::UserInfo { +impl From for super::UserInfo { + fn from(info: UserInfo) -> super::UserInfo { use super::UserInfo::*; - match self.identifier { - UserIdentifier::MatrixId { user } => MatrixId(user.to_owned()), - UserIdentifier::ThirdPartyId { address, medium } => ThirdPartyId { - address: address.to_owned(), - medium: medium.to_owned(), - }, - UserIdentifier::PhoneNumber { country, phone } => PhoneNumber { - country: country.to_owned(), - phone: phone.to_owned(), - }, + match info.identifier { + UserIdentifier::MatrixId { user } => MatrixId(user), + UserIdentifier::ThirdPartyId { address, medium } => ThirdPartyId { address, medium }, + UserIdentifier::PhoneNumber { country, phone } => PhoneNumber { country, phone }, } } } From a761d59a4c864159bf8af798198c70616296bd3e Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Fri, 24 Apr 2020 06:33:53 -0500 Subject: [PATCH 292/350] Normalize serde_json imports --- CHANGELOG.md | 1 + CONTRIBUTING.md | 17 ++++++++ src/error.rs | 5 ++- src/r0/capabilities/get_capabilities.rs | 4 +- src/r0/config/set_global_account_data.rs | 4 +- src/r0/config/set_room_account_data.rs | 4 +- src/r0/directory/get_public_rooms_filtered.rs | 5 ++- src/r0/filter.rs | 12 +++--- src/r0/keys/claim_keys.rs | 4 +- src/r0/keys/get_keys.rs | 4 +- src/r0/media/get_media_preview.rs | 4 +- src/r0/membership/invite_user.rs | 25 ++++++----- src/r0/room/create_room.rs | 4 +- src/r0/session/get_login_types.rs | 4 +- src/r0/session/login.rs | 42 +++++++------------ .../state/create_state_event_for_empty_key.rs | 4 +- src/r0/state/create_state_event_for_key.rs | 4 +- .../state/get_state_events_for_empty_key.rs | 4 +- src/r0/state/get_state_events_for_key.rs | 4 +- src/r0/uiaa.rs | 11 ++--- 20 files changed, 88 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe4295a1..c14b1f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Improvements: * Add types for User-Interactive Authentication API: `r0::uiaa::{AuthFlow, UiaaInfo, UiaaResponse}` * Add missing serde attributes to `get_content_thumbnail` query parameters * Add missing `state` response field to `r0::message::get_message_events` +* Normalize `serde_json` imports # 0.7.2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6de82d34..3095dfbe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -99,6 +99,23 @@ use std::convert::TryFrom; use std::fmt::{Debug, Display, Error as FmtError, Formatter}; ``` +### Serde Imports + +When importing methods and types from `serde_json`, methods should be such as +`serde_json::{from,to}_{slice,string,value,vec}` should be imported as +`{from,to}_json_{slice,string,value,vec}`. + +For example: + +```rust +use serde_json::{ + from_value as from_json_value, + to_str as to_json_str, +}; +``` + +Also, `serde_json::Value` should be imported as `JsonValue`. + ### Code Formatting and Linting Use `rustfmt` to format your code and `clippy` to lint your code. Before diff --git a/src/error.rs b/src/error.rs index 1fb19521..102467ce 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,7 @@ use std::fmt::{self, Display, Formatter}; use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; +use serde_json::{from_slice as from_json_slice, to_vec as to_json_vec}; use strum::{AsRefStr, Display, EnumString}; /// An enum for the error kind. Items may contain additional information. @@ -160,7 +161,7 @@ impl EndpointError for Error { fn try_from_response( response: http::Response>, ) -> Result { - match serde_json::from_slice::(response.body()) { + match from_json_slice::(response.body()) { Ok(error_body) => Ok(error_body.into_error(response.status())), Err(de_error) => Err(ResponseDeserializationError::new(de_error, response)), } @@ -206,7 +207,7 @@ impl From for http::Response> { http::Response::builder() .header(http::header::CONTENT_TYPE, "application/json") .status(error.status_code) - .body(serde_json::to_vec(&ErrorBody::from(error)).unwrap()) + .body(to_json_vec(&ErrorBody::from(error)).unwrap()) .unwrap() } } diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs index d0d97cca..43f42ff0 100644 --- a/src/r0/capabilities/get_capabilities.rs +++ b/src/r0/capabilities/get_capabilities.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; -use serde_json::Value; +use serde_json::Value as JsonValue; use std::collections::BTreeMap; ruma_api! { @@ -39,7 +39,7 @@ pub struct Capabilities { /// Any other custom capabilities that the server supports outside of the specification, /// labeled using the Java package naming convention and stored as arbitrary JSON values. #[serde(flatten)] - pub custom_capabilities: BTreeMap, + pub custom_capabilities: BTreeMap, } /// Information about the m.change_password capability diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index 363f7f6d..adc202d4 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -17,7 +17,7 @@ ruma_api! { request { /// Arbitrary JSON to store as config data. #[ruma_api(body)] - pub data: Value, + pub data: JsonValue, /// The event type of the account_data to set. /// /// Custom types should be namespaced to avoid clashes. diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 82cc64c4..ff2f78bf 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -17,7 +17,7 @@ ruma_api! { request { /// Arbitrary JSON to store as config data. #[ruma_api(body)] - pub data: Value, + pub data: JsonValue, /// The event type of the account_data to set. /// /// Custom types should be namespaced to avoid clashes. diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index 3deb6565..716df562 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -9,7 +9,8 @@ use serde::{ ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer, }; -use serde_json::Value; + +use serde_json::Value as JsonValue; use super::PublicRoomsChunk; @@ -130,7 +131,7 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor { { let mut include_all_networks = false; let mut third_party_instance_id = None; - while let Some((key, value)) = access.next_entry::()? { + while let Some((key, value)) = access.next_entry::()? { match key.as_str() { "include_all_networks" => { include_all_networks = match value.as_bool() { diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 2b8de854..21a1649e 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -305,14 +305,14 @@ impl<'de> Deserialize<'de> for LazyLoadOptions { #[cfg(test)] mod tests { - use serde_json::json; + use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use super::LazyLoadOptions; #[test] fn test_serializing_disabled_lazy_load() { let lazy_load_options = LazyLoadOptions::Disabled; - assert_eq!(serde_json::to_value(lazy_load_options).unwrap(), json!({})); + assert_eq!(to_json_value(lazy_load_options).unwrap(), json!({})); } #[test] @@ -321,7 +321,7 @@ mod tests { include_redundant_members: false, }; assert_eq!( - serde_json::to_value(lazy_load_options).unwrap(), + to_json_value(lazy_load_options).unwrap(), json!({ "lazy_load_members": true }) ); } @@ -332,7 +332,7 @@ mod tests { include_redundant_members: true, }; assert_eq!( - serde_json::to_value(lazy_load_options).unwrap(), + to_json_value(lazy_load_options).unwrap(), json!({ "lazy_load_members": true, "include_redundant_members": true }) ); } @@ -341,7 +341,7 @@ mod tests { fn test_deserializing_no_lazy_load() { let json = json!({}); assert_eq!( - serde_json::from_value::(json).unwrap(), + from_json_value::(json).unwrap(), LazyLoadOptions::Disabled, ); } @@ -350,7 +350,7 @@ mod tests { fn test_deserializing_ignore_redundant_members_when_no_lazy_load() { let json = json!({ "include_redundant_members": true }); assert_eq!( - serde_json::from_value::(json).unwrap(), + from_json_value::(json).unwrap(), LazyLoadOptions::Disabled, ); } diff --git a/src/r0/keys/claim_keys.rs b/src/r0/keys/claim_keys.rs index 8a2d7cd2..d894d400 100644 --- a/src/r0/keys/claim_keys.rs +++ b/src/r0/keys/claim_keys.rs @@ -6,7 +6,7 @@ use std::time::Duration; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; -use serde_json::Value; +use serde_json::Value as JsonValue; use super::{AlgorithmAndDeviceId, KeyAlgorithm, OneTimeKey}; @@ -37,7 +37,7 @@ ruma_api! { response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: BTreeMap, + pub failures: BTreeMap, /// One-time keys for the queried devices. pub one_time_keys: BTreeMap>>, diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index 64032e30..74194f38 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -4,7 +4,7 @@ use std::{collections::BTreeMap, time::Duration}; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; -use serde_json::Value; +use serde_json::Value as JsonValue; use super::DeviceKeys; @@ -41,7 +41,7 @@ ruma_api! { response { /// If any remote homeservers could not be reached, they are recorded here. /// The names of the properties are the names of the unreachable servers. - pub failures: BTreeMap, + pub failures: BTreeMap, /// Information on the queried devices. pub device_keys: BTreeMap>, diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index b517d21d..be407264 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -3,7 +3,7 @@ use std::time::SystemTime; use ruma_api::ruma_api; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -31,7 +31,7 @@ ruma_api! { /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` /// field, and `og:image` returns the MXC URI to the image, if any. #[ruma_api(body)] - pub data: Option, + pub data: Option, } error: crate::Error diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index 0d0de7bf..9febe0d7 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -51,14 +51,17 @@ pub enum InvitationRecipient { #[cfg(test)] mod tests { + use std::convert::TryFrom; + + use ruma_identifiers::UserId; + use serde_json::{from_value as from_json_value, json}; + use super::InvitationRecipient; use crate::r0::{membership::Invite3pid, thirdparty::Medium}; - use ruma_identifiers::UserId; - use std::convert::TryFrom; #[test] fn deserialize_invite_by_user_id() { let incoming = - serde_json::from_str::(r#" { "user_id": "@carl:example.org" } "#) + from_json_value::(json!({ "user_id": "@carl:example.org" })) .unwrap(); let user_id = UserId::try_from("@carl:example.org").unwrap(); let recipient = InvitationRecipient::UserId { user_id }; @@ -67,16 +70,12 @@ mod tests { #[test] fn deserialize_invite_by_3pid() { - let incoming = serde_json::from_str::( - r#" - { - "id_server": "example.org", - "id_access_token": "abcdefghijklmnop", - "medium": "email", - "address": "carl@example.org" - } - "#, - ) + let incoming = from_json_value::(json!({ + "id_server": "example.org", + "id_access_token": "abcdefghijklmnop", + "medium": "email", + "address": "carl@example.org" + })) .unwrap(); let recipient = InvitationRecipient::ThirdPartyId(Invite3pid { id_server: "example.org".to_string(), diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index c29cc996..89ca0dfd 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -4,7 +4,7 @@ use ruma_api::ruma_api; use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; -use serde_json::Value; +use serde_json::Value as JsonValue; use super::Visibility; use crate::r0::membership::Invite3pid; @@ -106,5 +106,5 @@ pub struct InitialStateEvent { /// `state_key` of the event to be sent. pub state_key: Option, /// JSON content of the state event. - pub content: Value, + pub content: JsonValue, } diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs index 8e323a08..a07da00c 100644 --- a/src/r0/session/get_login_types.rs +++ b/src/r0/session/get_login_types.rs @@ -37,12 +37,14 @@ pub enum LoginType { #[cfg(test)] mod tests { + use serde_json::{from_value as from_json_value, json}; + use super::LoginType; #[test] fn deserialize_login_type() { assert_eq!( - serde_json::from_str::(r#" {"type": "m.login.password"} "#).unwrap(), + from_json_value::(json!({ "type": "m.login.password" })).unwrap(), LoginType::Password, ); } diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 0028318f..f9444bf9 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -130,21 +130,17 @@ mod user_serde; mod tests { use std::convert::TryInto; - use serde_json::json; + use serde_json::{from_value as from_json_value, json, Value as JsonValue}; use super::{LoginInfo, Medium, Request, UserInfo}; #[test] fn deserialize_login_type() { assert_eq!( - serde_json::from_str::( - r#" - { - "type": "m.login.password", - "password": "ilovebananas" - } - "#, - ) + from_json_value::(json!({ + "type": "m.login.password", + "password": "ilovebananas" + }),) .unwrap(), LoginInfo::Password { password: "ilovebananas".into() @@ -152,14 +148,10 @@ mod tests { ); assert_eq!( - serde_json::from_str::( - r#" - { - "type": "m.login.token", - "token": "1234567890abcdef" - } - "#, - ) + from_json_value::(json!({ + "type": "m.login.token", + "token": "1234567890abcdef" + }),) .unwrap(), LoginInfo::Token { token: "1234567890abcdef".into() @@ -170,16 +162,12 @@ mod tests { #[test] fn deserialize_user() { assert_eq!( - serde_json::from_str::( - r#" - { - "identifier": { - "type": "m.id.user", - "user": "cheeky_monkey" - } + from_json_value::(json!({ + "identifier": { + "type": "m.id.user", + "user": "cheeky_monkey" } - "#, - ) + })) .unwrap(), UserInfo::MatrixId("cheeky_monkey".into()) ); @@ -201,7 +189,7 @@ mod tests { .try_into() .unwrap(); - let req_body_value: serde_json::Value = serde_json::from_slice(req.body()).unwrap(); + let req_body_value: JsonValue = serde_json::from_slice(req.body()).unwrap(); assert_eq!( req_body_value, json!({ diff --git a/src/r0/state/create_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs index e0c0decb..edee60d5 100644 --- a/src/r0/state/create_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -24,7 +24,7 @@ ruma_api! { pub event_type: EventType, /// The event's content. #[ruma_api(body)] - pub data: Value, + pub data: JsonValue, } response { diff --git a/src/r0/state/create_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs index d377cb98..c52d4915 100644 --- a/src/r0/state/create_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -27,7 +27,7 @@ ruma_api! { pub state_key: String, /// The event's content. #[ruma_api(body)] - pub data: Value, + pub data: JsonValue, } response { diff --git a/src/r0/state/get_state_events_for_empty_key.rs b/src/r0/state/get_state_events_for_empty_key.rs index ae8a3619..30747c36 100644 --- a/src/r0/state/get_state_events_for_empty_key.rs +++ b/src/r0/state/get_state_events_for_empty_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -27,7 +27,7 @@ ruma_api! { response { /// The content of the state event. #[ruma_api(body)] - pub content: Value, + pub content: JsonValue, } error: crate::Error diff --git a/src/r0/state/get_state_events_for_key.rs b/src/r0/state/get_state_events_for_key.rs index 815980b3..5317be65 100644 --- a/src/r0/state/get_state_events_for_key.rs +++ b/src/r0/state/get_state_events_for_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_json::Value; +use serde_json::Value as JsonValue; ruma_api! { metadata { @@ -30,7 +30,7 @@ ruma_api! { response { /// The content of the state event. #[ruma_api(body)] - pub content: Value, + pub content: JsonValue, } error: crate::Error diff --git a/src/r0/uiaa.rs b/src/r0/uiaa.rs index bc6ac20b..3caa8afa 100644 --- a/src/r0/uiaa.rs +++ b/src/r0/uiaa.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; -use serde_json::Value as JsonValue; +use serde_json::{from_slice as from_json_slice, to_vec as to_json_vec, Value as JsonValue}; use crate::error::{Error as MatrixError, ErrorBody}; @@ -85,7 +85,7 @@ impl EndpointError for UiaaResponse { response: http::Response>, ) -> Result { if response.status() == http::StatusCode::UNAUTHORIZED { - if let Ok(authentication_info) = serde_json::from_slice::(response.body()) { + if let Ok(authentication_info) = from_json_slice::(response.body()) { return Ok(UiaaResponse::AuthResponse(authentication_info)); } } @@ -100,7 +100,7 @@ impl From for http::Response> { UiaaResponse::AuthResponse(authentication_info) => http::Response::builder() .header(http::header::CONTENT_TYPE, "application/json") .status(&http::StatusCode::UNAUTHORIZED) - .body(serde_json::to_vec(&authentication_info).unwrap()) + .body(to_json_vec(&authentication_info).unwrap()) .unwrap(), UiaaResponse::MatrixError(error) => http::Response::from(error), } @@ -113,7 +113,8 @@ mod tests { use ruma_api::EndpointError; use serde_json::{ - from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, + from_slice as from_json_slice, from_value as from_json_value, json, + to_value as to_json_value, Value as JsonValue, }; use super::{AuthData, AuthFlow, UiaaInfo, UiaaResponse}; @@ -286,7 +287,7 @@ mod tests { UiaaResponse::AuthResponse(uiaa_info.clone()).into(); assert_eq!( - serde_json::from_slice::(uiaa_response.body()).unwrap(), + from_json_slice::(uiaa_response.body()).unwrap(), uiaa_info, ); assert_eq!( From 2e696a114b7809230a192fb9450b2982dc299eac Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 25 Apr 2020 09:28:08 +0200 Subject: [PATCH 293/350] Update example in CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3095dfbe..5e98c4ff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,7 +87,7 @@ Also, group imports by module. For example, do this: use std::{ collections::BTreeMap, convert::TryFrom, - fmt::{Debug, Display, Error as FmtError, Formatter}, + fmt::{self, Debug, Display, Formatter}, }; ``` @@ -96,7 +96,7 @@ as opposed to: ```rust use std::collections::BTreeMap; use std::convert::TryFrom; -use std::fmt::{Debug, Display, Error as FmtError, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; ``` ### Serde Imports From 210e3fd4a9c52238ad5d219c75a9e3265d86e2f6 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Sat, 25 Apr 2020 02:30:20 -0500 Subject: [PATCH 294/350] Make display_name of RoomMember optional --- CHANGELOG.md | 1 + src/r0/membership/joined_members.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c14b1f66..cd03b19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Breaking changes: * Change the messages type that gets sent out using the `r0::client_exchange::send_event_to_device` request. * Add `M_USER_DEACTIVATED` to `error::ErrorKind` +* Make `display_name` field of `r0::membership::joined_events::RoomMember` optional Improvements: diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index f853af60..400ee601 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/joined_members](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-joined-members) +//! [GET /_matrix/client/r0/rooms/{roomId}/joined_members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members) use std::collections::BTreeMap; @@ -31,12 +31,13 @@ ruma_api! { error: crate::Error } -// TODO: Find out whether display_name and avatar_url are optional /// Information about a room member. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomMember { /// The display name of the user. - pub display_name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub display_name: Option, /// The mxc avatar url of the user. + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, } From 762a65ec5eca31908ec38065b1b05bddde81f08c Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Sat, 25 Apr 2020 08:08:57 -0500 Subject: [PATCH 295/350] Update search endpoint to r0.6.0 --- CHANGELOG.md | 1 + src/r0/search/search_events.rs | 58 ++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd03b19b..02c074b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Breaking changes: request. * Add `M_USER_DEACTIVATED` to `error::ErrorKind` * Make `display_name` field of `r0::membership::joined_events::RoomMember` optional +* Update `r0::search::search_events` to r0.6.0 Improvements: diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 525c6bbf..ee0bb836 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -4,7 +4,10 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::all::Event, EventJson}; +use ruma_events::{ + collections::all::{Event, StateEvent}, + EventJson, +}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -53,8 +56,6 @@ pub struct Criteria { #[serde(skip_serializing_if = "Option::is_none")] pub event_context: Option, /// A `Filter` to apply to the search. - // TODO: "timeline" key might need to be included. - // See https://github.com/matrix-org/matrix-doc/issues/598. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, /// Requests that the server partitions the result set based on the provided list of keys. @@ -77,9 +78,11 @@ pub struct Criteria { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { /// How many events after the result are returned. - pub after_limit: UInt, + #[serde(skip_serializing_if = "Option::is_none")] + pub after_limit: Option, /// How many events before the result are returned. - pub before_limit: UInt, + #[serde(skip_serializing_if = "Option::is_none")] + pub before_limit: Option, /// Requests that the server returns the historic profile information for the users that /// sent the events that were returned. pub include_profile: bool, @@ -89,26 +92,27 @@ pub struct EventContext { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventContextResult { /// Pagination token for the end of the chunk. - pub end: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, /// Events just after the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>>, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_after: Vec>, /// Events just before the result. - #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>>, + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_before: Vec>, /// The historic profile information of the users that sent the events returned. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] pub profile_info: Option>, /// Pagination token for the start of the chunk. - pub start: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub start: Option, } /// A grouping for partioning the result set. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct Grouping { /// The key within events to use for this grouping. - pub key: GroupingKey, + pub key: Option, } /// The key within events to use for this grouping. @@ -125,6 +129,7 @@ pub enum GroupingKey { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Groupings { /// List of groups to request. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub group_by: Vec, } @@ -167,8 +172,7 @@ pub struct RoomEventJsons { /// An approximate count of the total number of results found. pub count: UInt, /// Any groups that were requested. - // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 - pub groups: BTreeMap>, + pub groups: BTreeMap>, /// Token that can be used to get the next batch of results, by passing as the `next_batch` /// parameter to the next call. If this field is absent, there are no more results. #[serde(skip_serializing_if = "Option::is_none")] @@ -177,9 +181,12 @@ pub struct RoomEventJsons { pub results: Vec, /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. - #[serde(skip_serializing_if = "Option::is_none")] - // TODO: Major WTF here. https://github.com/matrix-org/matrix-doc/issues/773 - pub state: Option<()>, + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub state: BTreeMap>>, + /// List of words which should be highlighted, useful for stemming which may + /// change the query terms. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub highlights: Vec, } /// A grouping of results, if requested. @@ -203,9 +210,11 @@ pub struct SearchResult { #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, /// A number that describes how closely this result matches the search. Higher is closer. - pub rank: f64, + #[serde(skip_serializing_if = "Option::is_none")] + pub rank: Option, /// The event that matched. - pub result: EventJson, + #[serde(skip_serializing_if = "Option::is_none")] + pub result: Option>, } /// A user profile. @@ -218,3 +227,12 @@ pub struct UserProfile { #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, } + +/// Represents either a room or user ID for returning grouped search results. +#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub enum RoomIdOrUserId { + /// Represents a room ID. + RoomId(RoomId), + /// Represents a user ID. + UserId(UserId), +} From 1c3f8712fab158756f8848a7ac82f64e5451aecc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 28 Apr 2020 19:37:42 +0200 Subject: [PATCH 296/350] Make all fields in get_message_event response optional --- src/r0/message/get_message_events.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index e8bb5c70..11f322f2 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -61,12 +61,14 @@ ruma_api! { response { /// The token the pagination starts from. - pub start: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub start: Option, + /// The token the pagination ends at. + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, /// A list of room events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub chunk: Vec>, - /// The token the pagination ends at. - pub end: String, /// A list of state events relevant to showing the `chunk`. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub state: Vec>, From 5a26c387646e17ba076e478d1e7b896b7e47137d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 28 Apr 2020 19:57:59 +0200 Subject: [PATCH 297/350] Remove uses of deprecated UInt::min_value --- src/r0/message/get_message_events.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index 11f322f2..2f70ed81 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -94,6 +94,7 @@ mod tests { use std::convert::{TryFrom, TryInto}; + use js_int::UInt; use ruma_identifiers::RoomId; use crate::r0::filter::{LazyLoadOptions, RoomEventFilter}; @@ -115,7 +116,7 @@ mod tests { from: "token".into(), to: Some("token2".into()), dir: Direction::Backward, - limit: Some(js_int::UInt::min_value()), + limit: Some(UInt::from(0u32)), filter: Some(filter), }; @@ -134,7 +135,7 @@ mod tests { from: "token".into(), to: Some("token2".into()), dir: Direction::Backward, - limit: Some(js_int::UInt::min_value()), + limit: Some(UInt::from(0u32)), filter: None, }; @@ -153,7 +154,7 @@ mod tests { from: "token".into(), to: Some("token2".into()), dir: Direction::Backward, - limit: Some(js_int::UInt::min_value()), + limit: Some(UInt::from(0u32)), filter: Some(RoomEventFilter::default()), }; From 5aef53758269e35201cbf15c9c1eb06a71f44685 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 Apr 2020 15:28:42 +0200 Subject: [PATCH 298/350] impl Display for UiaaResponse --- src/r0/uiaa.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/r0/uiaa.rs b/src/r0/uiaa.rs index 3caa8afa..14b7a97a 100644 --- a/src/r0/uiaa.rs +++ b/src/r0/uiaa.rs @@ -1,6 +1,9 @@ //! Module for User-Interactive Authentication API types. -use std::collections::BTreeMap; +use std::{ + collections::BTreeMap, + fmt::{self, Display, Formatter}, +}; use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; @@ -74,6 +77,15 @@ pub enum UiaaResponse { MatrixError(MatrixError), } +impl Display for UiaaResponse { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Self::AuthResponse(_) => write!(f, "User-Interactive Authentication required."), + Self::MatrixError(err) => write!(f, "{}", err), + } + } +} + impl From for UiaaResponse { fn from(error: MatrixError) -> Self { Self::MatrixError(error) From 15cb930102429c79e60d76f30b199cbb1c805bd0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 30 Apr 2020 15:29:44 +0200 Subject: [PATCH 299/350] Update formatting of change log --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c074b1..9e2cee77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,10 @@ Breaking changes: * Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` * Modify `r0::account::AuthenticationData`: - - Rename to `AuthData` - - Change to an enum to facilitate fallback auth acknowledgements - - Add `auth_parameters` field - - Move to `r0::uiaa` module + * Rename to `AuthData` + * Change to an enum to facilitate fallback auth acknowledgements + * Add `auth_parameters` field + * Move to `r0::uiaa` module * Add `room_network` parameter to `r0::directory::get_public_rooms_filtered` to represent `include_all_networks` and `third_party_instance_id` Matrix fields * Update `r0::account::register` endpoint: From dbb60142cf336784d809c6c4d79bd8de4c67fb5f Mon Sep 17 00:00:00 2001 From: iinuwa Date: Fri, 1 May 2020 04:33:20 -0500 Subject: [PATCH 300/350] Sync endpoint touchups * Add account_data to sync endpoint. * Update RoomSummary not to serialize empty optional fields --- CHANGELOG.md | 1 + src/r0/sync/sync_events.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e2cee77..11a754da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Breaking changes: * Add `M_USER_DEACTIVATED` to `error::ErrorKind` * Make `display_name` field of `r0::membership::joined_events::RoomMember` optional * Update `r0::search::search_events` to r0.6.0 +* Add `account_data` field to `r0::sync::sync_events` Improvements: diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 24fa044f..6d96ac17 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -66,6 +66,8 @@ ruma_api! { pub rooms: Rooms, /// Updates to the presence status of other users. pub presence: Presence, + /// The global private data created by this user. + pub account_data: AccountData, /// Messages sent dirrectly between devices. #[serde(default, skip_serializing_if = "ToDevice::is_empty")] pub to_device: ToDevice, @@ -223,12 +225,18 @@ pub struct RoomSummary { /// Number of users whose membership status is `join`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. - #[serde(rename = "m.joined_member_count")] + #[serde( + rename = "m.joined_member_count", + skip_serializing_if = "Option::is_none" + )] pub joined_member_count: Option, /// Number of users whose membership status is `invite`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. - #[serde(rename = "m.invited_member_count")] + #[serde( + rename = "m.invited_member_count", + skip_serializing_if = "Option::is_none" + )] pub invited_member_count: Option, } From 06f83742506e06d6d2731667eb9fa081654455cf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 1 May 2020 13:52:44 +0200 Subject: [PATCH 301/350] sync_events: make account_data optional --- src/r0/sync/sync_events.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 6d96ac17..9a9add73 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -145,7 +145,8 @@ pub struct LeftRoom { /// The state updates for the room up to the start of the timeline. pub state: State, /// The private data that this user has attached to this room. - pub account_data: AccountData, + #[serde(skip_serializing_if = "Option::is_none")] + pub account_data: Option, } /// Updates to joined rooms. @@ -163,7 +164,8 @@ pub struct JoinedRoom { /// given, or `full_state` is true). pub state: State, /// The private data that this user has attached to this room. - pub account_data: AccountData, + #[serde(skip_serializing_if = "Option::is_none")] + pub account_data: Option, /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// room. e.g. typing. pub ephemeral: Ephemeral, From bc9b43e03f2ac23833bb8c275bff37bfd9896c82 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 2 May 2020 18:52:16 +0200 Subject: [PATCH 302/350] Update dependencies, use push::Action from ruma-common --- Cargo.toml | 9 +-- src/r0/push.rs | 166 ++----------------------------------------------- 2 files changed, 9 insertions(+), 166 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 026972ff..7b009a7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,13 @@ edition = "2018" [dependencies] http = "0.2.1" -js_int = { version = "0.1.4", features = ["serde"] } +js_int = { version = "0.1.5", features = ["serde"] } ruma-api = "0.16.0-rc.3" +ruma-common = "0.1.1" ruma-events = "0.21.0-beta.1" -ruma-identifiers = "0.16.0" -ruma-serde = "0.1.0" +ruma-identifiers = "0.16.1" +ruma-serde = "0.1.3" serde = { version = "1.0.106", features = ["derive"] } -serde_json = "1.0.51" +serde_json = "1.0.52" strum = { version = "0.18.0", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } diff --git a/src/r0/push.rs b/src/r0/push.rs index 28bd0d16..cf922f8d 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -1,16 +1,8 @@ //! Endpoints for push notifications. -use std::{ - convert::TryFrom, - fmt::{Formatter, Result as FmtResult}, -}; +use std::convert::TryFrom; -use serde::{ - de::{Error as SerdeError, MapAccess, Unexpected, Visitor}, - ser::SerializeStruct, - Deserialize, Deserializer, Serialize, Serializer, -}; -use serde_json::Value as JsonValue; +use serde::{Deserialize, Serialize}; use strum::{Display, EnumString}; pub mod delete_pushrule; @@ -26,6 +18,8 @@ pub mod set_pushrule; pub mod set_pushrule_actions; pub mod set_pushrule_enabled; +pub use ruma_common::push::Action; + /// The kinds of push rules that are available #[derive( Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Display, EnumString, @@ -175,155 +169,3 @@ pub enum PushFormat { /// Require the homeserver to only send a reduced set of fields in the push. EventIdOnly, } - -/// This represents the different actions that should be taken when a rule is matched, and -/// controls how notifications are delivered to the client. -// See https://matrix.org/docs/spec/client_server/r0.6.0#actions for details. -#[derive(Clone, Debug)] -pub enum Action { - /// Causes matching events to generate a notification. - Notify, - - /// Prevents matching events from generating a notification. - DontNotify, - - /// Behaves like notify but homeservers may choose to coalesce multiple events - /// into a single notification. - Coalesce, - - /// Sets an entry in the 'tweaks' dictionary sent to the push gateway. - SetTweak { - /// The kind of this tweak - kind: TweakKind, - - /// The value of the tweak, if any - value: Option, - }, -} - -/// The different kinds of tweaks available -#[derive(Clone, Debug)] -pub enum TweakKind { - /// The "sound" tweak. - Sound, - - /// The "highlight" tweak. - Highlight, - - /// A name for a custom client-defined tweak. - Custom(String), -} - -impl Serialize for Action { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - match self { - Action::Notify => serializer.serialize_unit_variant("Action", 0, "notify"), - Action::DontNotify => serializer.serialize_unit_variant("Action", 1, "dont_notify"), - Action::Coalesce => serializer.serialize_unit_variant("Action", 2, "coalesce"), - Action::SetTweak { kind, value } => { - let kind_name = match &kind { - TweakKind::Sound => "sound", - TweakKind::Highlight => "highlight", - TweakKind::Custom(name) => name, - }; - let num_fields = match value { - Some(_) => 2, - None => 1, - }; - let mut s = serializer.serialize_struct("Action", num_fields)?; - s.serialize_field("set_tweak", kind_name)?; - - match &value { - Some(value) => { - s.serialize_field("value", value)?; - } - None => {} - }; - s.end() - } - } - } -} - -impl<'de> Deserialize<'de> for Action { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct ActionVisitor; - impl<'de> Visitor<'de> for ActionVisitor { - type Value = Action; - - fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult { - write!(formatter, "a valid action object") - } - - /// Match a simple action type - fn visit_str(self, v: &str) -> Result - where - E: SerdeError, - { - match v { - "notify" => Ok(Action::Notify), - "dont_notify" => Ok(Action::DontNotify), - "coalesce" => Ok(Action::Coalesce), - s => Err(E::unknown_variant( - &s, - &["notify", "dont_notify", "coalesce"], - )), - } - } - - /// Match the more complex set_tweaks action object as a key-value map - fn visit_map(self, mut map: A) -> Result - where - A: MapAccess<'de>, - { - let mut tweak_kind: Option = None; - let mut tweak_value: Option = None; - - // We loop over all entries in the map to find one with a "set_tweak" key to find - // which type of tweak is being set. - // Then we also try to find one with the "value" key if it exists. - while let Some((key, value)) = map.next_entry::<&str, JsonValue>()? { - match key { - "set_tweak" => { - let kind = match value.as_str() { - Some("sound") => TweakKind::Sound, - Some("highlight") => TweakKind::Highlight, - Some(s) => TweakKind::Custom(s.to_string()), - None => { - return Err(A::Error::invalid_type( - Unexpected::Other("non-string object"), - &"string", - )) - } - }; - tweak_kind = Some(kind); - } - "value" => { - tweak_value = Some(value); - } - _ => {} - } - } - - match tweak_kind { - Some(kind) => Ok(Action::SetTweak { - kind, - value: tweak_value, - }), - None => Err(A::Error::invalid_type( - Unexpected::Other("object without \"set_tweak\" key"), - &"valid \"set_tweak\" action object", - )), - } - } - } - - deserializer.deserialize_any(ActionVisitor) - } -} From b809db81f46c180449273b67604b304efb672bb8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:34:52 +0200 Subject: [PATCH 303/350] Update create_message_event, create_state_event_* --- src/r0/message/create_message_event.rs | 16 +++++++++++----- src/r0/state/create_state_event_for_empty_key.rs | 14 +++++++++----- src/r0/state/create_state_event_for_key.rs | 15 ++++++++++----- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index 573dff04..850f5eaf 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -1,8 +1,9 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) +//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; +use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -18,9 +19,11 @@ ruma_api! { /// 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, + /// The transaction ID for this event. /// /// Clients should generate an ID unique across requests with the @@ -28,14 +31,17 @@ ruma_api! { /// idempotency of requests. #[ruma_api(path)] pub txn_id: String, - /// The event's content. + + /// The event's content. The type for this field will be updated in a + /// future release, until then you can create a value using + /// `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub data: EventJson, + pub data: Box, } response { /// A unique identifier for the event. - pub event_id: EventId, + pub event_id: Option, } error: crate::Error diff --git a/src/r0/state/create_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs index edee60d5..c73543d8 100644 --- a/src/r0/state/create_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -1,9 +1,9 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype) +//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-state-eventtype) use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -19,17 +19,21 @@ ruma_api! { /// 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, - /// The event's content. + + /// The event's content. The type for this field will be updated in a + /// future release, until then you can create a value using + /// `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub data: JsonValue, + pub data: Box, } response { /// A unique identifier for the event. - pub event_id: EventId, + pub event_id: Option, } error: crate::Error diff --git a/src/r0/state/create_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs index c52d4915..0b3d1646 100644 --- a/src/r0/state/create_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -1,9 +1,9 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) +//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey) use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::{EventId, RoomId}; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -19,20 +19,25 @@ ruma_api! { /// 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, + /// The state_key for the state to send. Defaults to the empty string. #[ruma_api(path)] pub state_key: String, - /// The event's content. + + /// The event's content. The type for this field will be updated in a + /// future release, until then you can create a value using + /// `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub data: JsonValue, + pub data: Box, } response { /// A unique identifier for the event. - pub event_id: EventId, + pub event_id: Option, } error: crate::Error From f2c8a7b5df409cdd826393cd6a5ae6c6b89b1349 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:41:14 +0200 Subject: [PATCH 304/350] Update dependencies --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b009a7b..bf3c05f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,9 @@ edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.5", features = ["serde"] } -ruma-api = "0.16.0-rc.3" +ruma-api = "0.16.0" ruma-common = "0.1.1" -ruma-events = "0.21.0-beta.1" +ruma-events = "0.21.0" ruma-identifiers = "0.16.1" ruma-serde = "0.1.3" serde = { version = "1.0.106", features = ["derive"] } From e5adfe1181d0fa8f32955b396d859407b4e43b82 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:42:15 +0200 Subject: [PATCH 305/350] Rename r0::{client_exchange => to_device} --- CHANGELOG.md | 1 + src/r0.rs | 2 +- src/r0/{client_exchange.rs => to_device.rs} | 0 src/r0/{client_exchange => to_device}/send_event_to_device.rs | 0 4 files changed, 2 insertions(+), 1 deletion(-) rename src/r0/{client_exchange.rs => to_device.rs} (100%) rename src/r0/{client_exchange => to_device}/send_event_to_device.rs (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a754da..4b9fbdc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Breaking changes: * Make `display_name` field of `r0::membership::joined_events::RoomMember` optional * Update `r0::search::search_events` to r0.6.0 * Add `account_data` field to `r0::sync::sync_events` +* Rename `r0::client_exchange` to `r0::to_device` Improvements: diff --git a/src/r0.rs b/src/r0.rs index 3a761cbc..23154ee7 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -4,7 +4,6 @@ pub mod account; pub mod alias; pub mod appservice; pub mod capabilities; -pub mod client_exchange; pub mod config; pub mod contact; pub mod context; @@ -29,6 +28,7 @@ pub mod state; pub mod sync; pub mod tag; pub mod thirdparty; +pub mod to_device; pub mod typing; pub mod uiaa; pub mod user_directory; diff --git a/src/r0/client_exchange.rs b/src/r0/to_device.rs similarity index 100% rename from src/r0/client_exchange.rs rename to src/r0/to_device.rs diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/to_device/send_event_to_device.rs similarity index 100% rename from src/r0/client_exchange/send_event_to_device.rs rename to src/r0/to_device/send_event_to_device.rs From ebd4af10c5cb5633a226eb7dc531b119674caba0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:43:51 +0200 Subject: [PATCH 306/350] Update join_room_by_id_or_alias --- src/r0/membership/join_room_by_id_or_alias.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/r0/membership/join_room_by_id_or_alias.rs b/src/r0/membership/join_room_by_id_or_alias.rs index 287ae7c9..91ecda4e 100644 --- a/src/r0/membership/join_room_by_id_or_alias.rs +++ b/src/r0/membership/join_room_by_id_or_alias.rs @@ -19,11 +19,13 @@ ruma_api! { /// The room where the user should be invited. #[ruma_api(path)] pub room_id_or_alias: RoomIdOrAliasId, + /// The servers to attempt to join the room through. One of the servers /// must be participating in the room. #[ruma_api(query)] #[serde(default)] - pub server_name: String, // TODO: Vec once it is supported (#146, ruma-api#48) + pub server_name: Vec, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] From e759c3821e104353dc88a554177b300ae261d8c2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:55:34 +0200 Subject: [PATCH 307/350] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bf3c05f6..29aecc18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.5" +version = "0.8.0-rc.6" edition = "2018" [dependencies] From 1ca24515adf56277da9357493f71e06540826780 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 00:11:04 +0200 Subject: [PATCH 308/350] Update remaining r0.4.0 modules to r0.6.0 --- src/r0/account/whoami.rs | 2 +- src/r0/alias/delete_alias.rs | 2 +- src/r0/alias/get_alias.rs | 2 +- src/r0/config/set_global_account_data.rs | 4 +- src/r0/config/set_room_account_data.rs | 5 +- .../request_contact_verification_token.rs | 24 +++++- src/r0/context/get_context.rs | 72 +++++++++++------- src/r0/filter.rs | 16 ++-- src/r0/filter/create_filter.rs | 9 ++- src/r0/filter/get_filter.rs | 9 ++- src/r0/media/create_content.rs | 7 +- src/r0/membership.rs | 11 ++- src/r0/membership/ban_user.rs | 10 ++- src/r0/membership/forget_room.rs | 2 +- src/r0/membership/join_room_by_id.rs | 3 +- src/r0/membership/joined_rooms.rs | 6 +- src/r0/membership/kick_user.rs | 10 ++- src/r0/membership/leave_room.rs | 2 +- src/r0/membership/unban_user.rs | 3 +- src/r0/presence/set_presence.rs | 14 ++-- src/r0/profile/get_avatar_url.rs | 2 +- src/r0/profile/get_display_name.rs | 2 +- src/r0/profile/get_profile.rs | 3 +- src/r0/profile/set_avatar_url.rs | 9 ++- src/r0/profile/set_display_name.rs | 9 ++- src/r0/receipt/create_receipt.rs | 16 ++-- src/r0/redact/redact_event.rs | 17 +++-- src/r0/search/search_events.rs | 75 +++++++++++++------ src/r0/server/get_user_info.rs | 35 +++++---- src/r0/session/logout.rs | 2 +- src/r0/session/logout_all.rs | 2 +- src/r0/state/get_state_events.rs | 2 +- .../state/get_state_events_for_empty_key.rs | 3 +- src/r0/state/get_state_events_for_key.rs | 4 +- src/r0/tag/create_tag.rs | 23 +++--- src/r0/tag/delete_tag.rs | 16 ++-- src/r0/tag/get_tags.rs | 9 ++- src/r0/typing/create_typing_event.rs | 17 +++-- src/r0/voip/get_turn_server_info.rs | 13 ++-- src/unversioned/discover_homeserver.rs | 30 ++++---- 40 files changed, 314 insertions(+), 188 deletions(-) diff --git a/src/r0/account/whoami.rs b/src/r0/account/whoami.rs index 0f4f3ea5..cee6c52a 100644 --- a/src/r0/account/whoami.rs +++ b/src/r0/account/whoami.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-whoami) +//! [GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-account-whoami) use ruma_api::ruma_api; diff --git a/src/r0/alias/delete_alias.rs b/src/r0/alias/delete_alias.rs index cebc3cd7..c8dbedc2 100644 --- a/src/r0/alias/delete_alias.rs +++ b/src/r0/alias/delete_alias.rs @@ -1,4 +1,4 @@ -//! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-directory-room-roomalias) +//! [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-directory-room-roomalias) use ruma_api::ruma_api; use ruma_identifiers::RoomAliasId; diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index d2d49fb4..00ec2100 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-directory-room-roomalias) +//! [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-directory-room-roomalias) use ruma_api::ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index adc202d4..184f4cf1 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-account-data-type) +//! [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-user-userid-account-data-type) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -18,11 +18,13 @@ ruma_api! { /// Arbitrary JSON to store as config data. #[ruma_api(body)] pub data: JsonValue, + /// The event type of the account_data to set. /// /// Custom types should be namespaced to avoid clashes. #[ruma_api(path)] pub event_type: String, + /// The ID of the user to set account_data for. /// /// The access token must be authorized to make requests for this user ID. diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index ff2f78bf..26949547 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -18,14 +18,17 @@ ruma_api! { /// Arbitrary JSON to store as config data. #[ruma_api(body)] pub data: JsonValue, + /// The event type of the account_data to set. /// /// Custom types should be namespaced to avoid clashes. #[ruma_api(path)] pub event_type: String, + /// The ID of the room to set account_data on. #[ruma_api(path)] pub room_id: RoomId, + /// The ID of the user to set account_data for. /// /// The access token must be authorized to make requests for this user ID. diff --git a/src/r0/contact/request_contact_verification_token.rs b/src/r0/contact/request_contact_verification_token.rs index ef8e4903..03cda2ee 100644 --- a/src/r0/contact/request_contact_verification_token.rs +++ b/src/r0/contact/request_contact_verification_token.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) +//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-email-requesttoken) use js_int::UInt; use ruma_api::ruma_api; @@ -16,13 +16,29 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The email address. pub email: String, - /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + + /// A URL for the identity server to redirect the user to after + /// validation is completed. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + + /// Used to distinguish protocol level retries from requests to re-send + /// the email. + pub send_attempt: UInt, + + /// The identity server to send the onward request to as a hostname with + /// an appended colon and port number if the port is not the default. #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, + + /// An access token previously registered with the identity server. + /// + /// Required if an `id_server` is supplied. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_access_token: Option, } response {} diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index 0f39509b..a02e9ce4 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-context-eventid) +//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-context-eventid) use js_int::UInt; use ruma_api::ruma_api; @@ -18,43 +18,63 @@ ruma_api! { } request { - /// 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)] - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, /// The room to get events from. #[ruma_api(path)] pub room_id: RoomId, - /// A RoomEventFilter to filter returned events with. - #[serde(skip_serializing_if = "Option::is_none")] + + /// The event to get context around. + #[ruma_api(path)] + pub event_id: EventId, + + /// The maximum number of events to return. + /// + /// Defaults to 10. #[ruma_api(query)] + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, + + /// A RoomEventFilter to filter returned events with. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, } response { - /// A token that can be used to paginate forwards with. - pub end: String, - /// Details of the requested event. - pub event: EventJson, - /// A list of room events that happened just after the requested event, in chronological - /// order. - - pub events_after: Vec>, - /// A list of room events that happened just before the requested event, in - /// reverse-chronological order. - - pub events_before: Vec>, /// A token that can be used to paginate backwards with. - pub start: String, - /// The state of the room at the last event returned. + #[serde(skip_serializing_if = "Option::is_none")] + pub start: Option, + /// A token that can be used to paginate forwards with. + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, + + /// A list of room events that happened just before the requested event, + /// in reverse-chronological order. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_before: Vec>, + + /// Details of the requested event. + #[serde(skip_serializing_if = "Option::is_none")] + pub event: Option>, + + /// A list of room events that happened just after the requested event, + /// in chronological order. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_after: Vec>, + + /// The state of the room at the last event returned. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub state: Vec>, } error: crate::Error } + +fn default_limit() -> UInt { + UInt::from(10u32) +} + +#[allow(clippy::trivially_copy_pass_by_ref)] +fn is_default_limit(val: &UInt) -> bool { + *val == default_limit() +} diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 21a1649e..707a1c7b 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -184,21 +184,25 @@ pub struct FilterDefinition { /// include more fields than were requested. #[serde(default, skip_serializing_if = "Option::is_none")] pub event_fields: Option>, + /// The format to use for events. /// /// 'client' will return the events in a format suitable for clients. 'federation' will return /// the raw event as received over federation. The default is 'client'. #[serde(skip_serializing_if = "Option::is_none")] pub event_format: Option, - /// The user account data that isn't associated with rooms to include. - #[serde(skip_serializing_if = "Option::is_none")] - pub account_data: Option, - /// Filters to be applied to room data. - #[serde(skip_serializing_if = "Option::is_none")] - pub room: Option, + /// The presence updates to include. #[serde(skip_serializing_if = "Option::is_none")] pub presence: Option, + + /// The user account data that isn't associated with rooms to include. + #[serde(skip_serializing_if = "Option::is_none")] + pub account_data: Option, + + /// Filters to be applied to room data. + #[serde(skip_serializing_if = "Option::is_none")] + pub room: Option, } impl FilterDefinition { diff --git a/src/r0/filter/create_filter.rs b/src/r0/filter/create_filter.rs index b11d324c..a3d2dc1f 100644 --- a/src/r0/filter/create_filter.rs +++ b/src/r0/filter/create_filter.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-user-userid-filter) +//! [POST /_matrix/client/r0/user/{userId}/filter](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-userid-filter) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -16,14 +16,15 @@ ruma_api! { } request { - /// The filter definition. - #[ruma_api(body)] - pub filter: FilterDefinition, /// The ID of the user uploading the filter. /// /// The access token must be authorized to make requests for this user ID. #[ruma_api(path)] pub user_id: UserId, + + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition, } response { diff --git a/src/r0/filter/get_filter.rs b/src/r0/filter/get_filter.rs index 0209d6c3..c69c57d9 100644 --- a/src/r0/filter/get_filter.rs +++ b/src/r0/filter/get_filter.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-filter-filterid) +//! [GET /_matrix/client/r0/user/{userId}/filter/{filterId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-filter-filterid) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -16,12 +16,13 @@ ruma_api! { } request { - /// The ID of the filter to download. - #[ruma_api(path)] - pub filter_id: String, /// The user ID to download a filter for. #[ruma_api(path)] pub user_id: UserId, + + /// The ID of the filter to download. + #[ruma_api(path)] + pub filter_id: String, } response { diff --git a/src/r0/media/create_content.rs b/src/r0/media/create_content.rs index 959e8611..1f75f0de 100644 --- a/src/r0/media/create_content.rs +++ b/src/r0/media/create_content.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-media-r0-upload) +//! [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-media-r0-upload) use ruma_api::ruma_api; @@ -14,12 +14,15 @@ ruma_api! { request { /// The name of the file being uploaded. - #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] pub filename: Option, + /// The content type of the file being uploaded. + // TODO: This should be optional. #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, + /// The file contents to upload. #[ruma_api(raw_body)] pub file: Vec, diff --git a/src/r0/membership.rs b/src/r0/membership.rs index ce885afb..4acac3db 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -22,14 +22,17 @@ use crate::r0::thirdparty::Medium; /// identity which has been invited to the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartySigned { - /// The Matrix ID of the invitee. - pub mxid: String, /// The Matrix ID of the user who issued the invite. pub sender: String, - /// A signatures object containing a signature of the entire signed object. - pub signatures: BTreeMap>, + + /// The Matrix ID of the invitee. + pub mxid: String, + /// The state key of the m.third_party_invite event. pub token: String, + + /// A signatures object containing a signature of the entire signed object. + pub signatures: BTreeMap>, } /// Represents third party IDs to invite to the room. diff --git a/src/r0/membership/ban_user.rs b/src/r0/membership/ban_user.rs index 20ccacbc..0da3e1a8 100644 --- a/src/r0/membership/ban_user.rs +++ b/src/r0/membership/ban_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-ban) +//! [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-ban) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -14,14 +14,16 @@ ruma_api! { } request { - /// The reason for banning the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, /// The room to kick the user from. #[ruma_api(path)] pub room_id: RoomId, + /// The user to ban. pub user_id: UserId, + + /// The reason for banning the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, } response {} diff --git a/src/r0/membership/forget_room.rs b/src/r0/membership/forget_room.rs index ffabe3cd..39644b06 100644 --- a/src/r0/membership/forget_room.rs +++ b/src/r0/membership/forget_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-forget) +//! [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-forget) use ruma_api::ruma_api; use ruma_identifiers::RoomId; diff --git a/src/r0/membership/join_room_by_id.rs b/src/r0/membership/join_room_by_id.rs index 6555f6fc..340a677c 100644 --- a/src/r0/membership/join_room_by_id.rs +++ b/src/r0/membership/join_room_by_id.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-join) +//! [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-join) use ruma_api::ruma_api; use ruma_identifiers::RoomId; @@ -19,6 +19,7 @@ ruma_api! { /// The room where the user should be invited. #[ruma_api(path)] pub room_id: RoomId, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/membership/joined_rooms.rs b/src/r0/membership/joined_rooms.rs index e9f84431..f3ec413c 100644 --- a/src/r0/membership/joined_rooms.rs +++ b/src/r0/membership/joined_rooms.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms) +//! [GET /_matrix/client/r0/joined_rooms](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-joined-rooms) use ruma_api::ruma_api; use ruma_identifiers::RoomId; @@ -16,8 +16,8 @@ ruma_api! { request {} response { - /// A list of the rooms the user is in, i.e. - /// the ID of each room in which the user has joined membership. + /// A list of the rooms the user is in, i.e. the ID of each room in + /// which the user has joined membership. pub joined_rooms: Vec, } diff --git a/src/r0/membership/kick_user.rs b/src/r0/membership/kick_user.rs index d9276324..f6c5da5b 100644 --- a/src/r0/membership/kick_user.rs +++ b/src/r0/membership/kick_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-kick) +//! [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-kick) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -14,14 +14,16 @@ ruma_api! { } request { - /// The reason for kicking the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, /// The room to kick the user from. #[ruma_api(path)] pub room_id: RoomId, + /// The user to kick. pub user_id: UserId, + + /// The reason for kicking the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, } response {} diff --git a/src/r0/membership/leave_room.rs b/src/r0/membership/leave_room.rs index d9487759..c0227806 100644 --- a/src/r0/membership/leave_room.rs +++ b/src/r0/membership/leave_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-leave) +//! [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-leave) use ruma_api::ruma_api; use ruma_identifiers::RoomId; diff --git a/src/r0/membership/unban_user.rs b/src/r0/membership/unban_user.rs index 27bd9e93..b754b701 100644 --- a/src/r0/membership/unban_user.rs +++ b/src/r0/membership/unban_user.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-unban) +//! [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-unban) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -17,6 +17,7 @@ ruma_api! { /// The room to unban the user from. #[ruma_api(path)] pub room_id: RoomId, + /// The user to unban. pub user_id: UserId, } diff --git a/src/r0/presence/set_presence.rs b/src/r0/presence/set_presence.rs index b295b5a5..4d3636f8 100644 --- a/src/r0/presence/set_presence.rs +++ b/src/r0/presence/set_presence.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-presence-userid-status) +//! [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-presence-userid-status) use ruma_api::ruma_api; use ruma_events::presence::PresenceState; @@ -15,14 +15,16 @@ ruma_api! { } request { - /// The new presence state. - pub presence: PresenceState, - /// The status message to attach to this state. - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, /// The user whose presence state will be updated. #[ruma_api(path)] pub user_id: UserId, + + /// The new presence state. + pub presence: PresenceState, + + /// The status message to attach to this state. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, } response {} diff --git a/src/r0/profile/get_avatar_url.rs b/src/r0/profile/get_avatar_url.rs index d6fa0cb5..6a950c01 100644 --- a/src/r0/profile/get_avatar_url.rs +++ b/src/r0/profile/get_avatar_url.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-avatar-url) +//! [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-profile-userid-avatar-url) use ruma_api::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/get_display_name.rs b/src/r0/profile/get_display_name.rs index 9f4aa150..d864cb60 100644 --- a/src/r0/profile/get_display_name.rs +++ b/src/r0/profile/get_display_name.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid-displayname) +//! [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-profile-userid-displayname) use ruma_api::ruma_api; use ruma_identifiers::UserId; diff --git a/src/r0/profile/get_profile.rs b/src/r0/profile/get_profile.rs index 2aa014b2..5bdb781e 100644 --- a/src/r0/profile/get_profile.rs +++ b/src/r0/profile/get_profile.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-profile-userid) +//! [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-profile-userid) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -23,6 +23,7 @@ ruma_api! { /// The user's avatar URL, if set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, + /// The user's display name, if set. #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index 6333f516..b48c4a2e 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-avatar-url) +//! [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-profile-userid-avatar-url) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -14,11 +14,12 @@ ruma_api! { } request { - /// The new avatar URL for the user. - pub avatar_url: String, /// The user whose avatar URL will be set. #[ruma_api(path)] - pub user_id: UserId + pub user_id: UserId, + + /// The new avatar URL for the user. + pub avatar_url: String, } response {} diff --git a/src/r0/profile/set_display_name.rs b/src/r0/profile/set_display_name.rs index 93898a7e..147740df 100644 --- a/src/r0/profile/set_display_name.rs +++ b/src/r0/profile/set_display_name.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-profile-userid-displayname) +//! [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-profile-userid-displayname) use ruma_api::ruma_api; use ruma_identifiers::UserId; @@ -14,12 +14,13 @@ ruma_api! { } request { - /// The new display name for the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, /// The user whose display name will be set. #[ruma_api(path)] pub user_id: UserId, + + /// The new display name for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, } response {} diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 9a963dc9..0b4b25e7 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) +//! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) use std::convert::TryFrom; @@ -17,15 +17,17 @@ ruma_api! { } request { - /// The event ID to acknowledge up to. - #[ruma_api(path)] - pub event_id: EventId, - /// The type of receipt to send. - #[ruma_api(path)] - pub receipt_type: ReceiptType, /// The room in which to send the event. #[ruma_api(path)] pub room_id: RoomId, + + /// The type of receipt to send. + #[ruma_api(path)] + pub receipt_type: ReceiptType, + + /// The event ID to acknowledge up to. + #[ruma_api(path)] + pub event_id: EventId, } response {} diff --git a/src/r0/redact/redact_event.rs b/src/r0/redact/redact_event.rs index fde2818c..30bc294b 100644 --- a/src/r0/redact/redact_event.rs +++ b/src/r0/redact/redact_event.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) +//! [PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid) use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; @@ -14,20 +14,23 @@ ruma_api! { } request { - /// The ID of the event to redact. - #[ruma_api(path)] - pub event_id: EventId, - /// The reason for the redaction. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, /// The ID of the room of the event to redact. #[ruma_api(path)] pub room_id: RoomId, + + /// The ID of the event to redact. + #[ruma_api(path)] + pub event_id: EventId, + /// The transaction ID for this event. /// /// Clients should generate a unique ID; it will be used by the server to ensure idempotency of requests. #[ruma_api(path)] pub txn_id: String, + + /// The reason for the redaction. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, } response { diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index ee0bb836..e2e7b240 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-search) +//! [POST /_matrix/client/r0/search](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-search) use std::collections::BTreeMap; @@ -29,6 +29,7 @@ ruma_api! { /// If given, this should be a `next_batch` result from a previous call to this endpoint. #[ruma_api(query)] pub next_batch: Option, + /// Describes which categories to search in and their criteria. pub search_categories: Categories, } @@ -52,57 +53,85 @@ pub struct Categories { /// Criteria for searching a category of events. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Criteria { - /// Configures whether any context for the events returned are included in the response. + /// The string to search events for. + pub search_term: String, + + /// The keys to search for. Defaults to all keys. #[serde(skip_serializing_if = "Option::is_none")] - pub event_context: Option, + pub keys: Option>, + /// A `Filter` to apply to the search. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, - /// Requests that the server partitions the result set based on the provided list of keys. - #[serde(skip_serializing_if = "Option::is_none")] - pub groupings: Option, - /// Requests the server return the current state for each room returned. - #[serde(skip_serializing_if = "Option::is_none")] - pub include_state: Option, - /// The keys to search for. Defaults to all keys. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub keys: Vec, + /// The order in which to search for results. #[serde(skip_serializing_if = "Option::is_none")] pub order_by: Option, - /// The string to search events for. - pub search_term: String, + + /// Configures whether any context for the events returned are included in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub event_context: Option, + + /// Requests the server return the current state for each room returned. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_state: Option, + + /// Requests that the server partitions the result set based on the provided list of keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub groupings: Option, } /// Configures whether any context for the events returned are included in the response. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { - /// How many events after the result are returned. - #[serde(skip_serializing_if = "Option::is_none")] - pub after_limit: Option, /// How many events before the result are returned. - #[serde(skip_serializing_if = "Option::is_none")] - pub before_limit: Option, + #[serde( + default = "default_event_context_limit", + skip_serializing_if = "is_default_event_context_limit" + )] + pub before_limit: UInt, + + /// How many events after the result are returned. + #[serde( + default = "default_event_context_limit", + skip_serializing_if = "is_default_event_context_limit" + )] + pub after_limit: UInt, + /// Requests that the server returns the historic profile information for the users that /// sent the events that were returned. + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] pub include_profile: bool, } +fn default_event_context_limit() -> UInt { + UInt::from(5u32) +} + +#[allow(clippy::trivially_copy_pass_by_ref)] +fn is_default_event_context_limit(val: &UInt) -> bool { + *val == default_event_context_limit() +} + /// Context for search results, if requested. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventContextResult { /// Pagination token for the end of the chunk. #[serde(skip_serializing_if = "Option::is_none")] pub end: Option, + /// Events just after the result. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events_after: Vec>, + /// Events just before the result. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub events_before: Vec>, + /// The historic profile information of the users that sent the events returned. #[serde(skip_serializing_if = "Option::is_none")] pub profile_info: Option>, + /// Pagination token for the start of the chunk. #[serde(skip_serializing_if = "Option::is_none")] pub start: Option, @@ -121,6 +150,7 @@ pub struct Grouping { pub enum GroupingKey { /// `room_id` RoomId, + /// `sender` Sender, } @@ -139,9 +169,11 @@ pub enum SearchKeys { /// content.body #[serde(rename = "content.body")] ContentBody, + /// content.name #[serde(rename = "content.name")] ContentName, + /// content.topic #[serde(rename = "content.topic")] ContentTopic, @@ -151,11 +183,12 @@ pub enum SearchKeys { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum OrderBy { + /// Prioritize recent events. + Recent, + /// Prioritize events by a numerical ranking of how closely they matched the search /// criteria. Rank, - /// Prioritize recent events. - Recent, } /// Categories of events that can be searched for. diff --git a/src/r0/server/get_user_info.rs b/src/r0/server/get_user_info.rs index 5b06a70e..4f00ddd8 100644 --- a/src/r0/server/get_user_info.rs +++ b/src/r0/server/get_user_info.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-admin-whois-userid) +//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-admin-whois-userid) use std::{collections::BTreeMap, time::SystemTime}; @@ -24,30 +24,22 @@ ruma_api! { response { /// The Matrix user ID of the user. - pub user_id: UserId, + #[serde(skip_serializing_if = "Option::is_none")] + pub user_id: Option, + /// A map of the user's device identifiers to information about that device. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub devices: BTreeMap, } error: crate::Error } -/// Information about a connection in a user session. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ConnectionInfo { - /// Most recently seen IP address of the session. - pub ip: String, - /// Time when that the session was last active. - #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] - pub last_seen: SystemTime, - /// User agent string last seen in the session. - pub user_agent: String, -} - /// Information about a user's device. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DeviceInfo { /// A list of user sessions on this device. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub sessions: Vec, } @@ -55,5 +47,20 @@ pub struct DeviceInfo { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SessionInfo { /// A list of connections in this session. + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub connections: Vec, } + +/// Information about a connection in a user session. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ConnectionInfo { + /// Most recently seen IP address of the session. + pub ip: Option, + + /// Time when that the session was last active. + #[serde(with = "ruma_serde::time::opt_ms_since_unix_epoch")] + pub last_seen: Option, + + /// User agent string last seen in the session. + pub user_agent: Option, +} diff --git a/src/r0/session/logout.rs b/src/r0/session/logout.rs index 1c33d716..f3bd75e4 100644 --- a/src/r0/session/logout.rs +++ b/src/r0/session/logout.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout) +//! [POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout) use ruma_api::ruma_api; diff --git a/src/r0/session/logout_all.rs b/src/r0/session/logout_all.rs index b70493b9..afc20fe1 100644 --- a/src/r0/session/logout_all.rs +++ b/src/r0/session/logout_all.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-logout-all) +//! [POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all) use ruma_api::ruma_api; diff --git a/src/r0/state/get_state_events.rs b/src/r0/state/get_state_events.rs index 35968905..6947b717 100644 --- a/src/r0/state/get_state_events.rs +++ b/src/r0/state/get_state_events.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) +//! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-state) use ruma_api::ruma_api; use ruma_events::{collections::all::StateEvent, EventJson}; diff --git a/src/r0/state/get_state_events_for_empty_key.rs b/src/r0/state/get_state_events_for_empty_key.rs index 30747c36..42320472 100644 --- a/src/r0/state/get_state_events_for_empty_key.rs +++ b/src/r0/state/get_state_events_for_empty_key.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) +//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-state-eventtype) use ruma_api::ruma_api; use ruma_events::EventType; @@ -19,6 +19,7 @@ ruma_api! { /// The room to look up the state for. #[ruma_api(path)] pub room_id: RoomId, + /// The type of state to look up. #[ruma_api(path)] pub event_type: EventType, diff --git a/src/r0/state/get_state_events_for_key.rs b/src/r0/state/get_state_events_for_key.rs index 5317be65..efd8c364 100644 --- a/src/r0/state/get_state_events_for_key.rs +++ b/src/r0/state/get_state_events_for_key.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) +//! [GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) use ruma_api::ruma_api; use ruma_events::EventType; @@ -19,9 +19,11 @@ ruma_api! { /// The room to look up the state for. #[ruma_api(path)] pub room_id: RoomId, + /// The type of state to look up. #[ruma_api(path)] pub event_type: EventType, + /// The key of the state to look up. #[ruma_api(path)] pub state_key: String, diff --git a/src/r0/tag/create_tag.rs b/src/r0/tag/create_tag.rs index e0337918..36e63af9 100644 --- a/src/r0/tag/create_tag.rs +++ b/src/r0/tag/create_tag.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +//! [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) use ruma_api::ruma_api; use ruma_events::tag::TagInfo; @@ -15,18 +15,21 @@ ruma_api! { } request { - /// The room to tag. - #[ruma_api(path)] - pub room_id: RoomId, - /// The name of the tag to create. - #[ruma_api(path)] - pub tag: String, - /// Info about the tag. - #[ruma_api(body)] - pub tag_info: TagInfo, /// The ID of the user creating the tag. #[ruma_api(path)] pub user_id: UserId, + + /// The room to tag. + #[ruma_api(path)] + pub room_id: RoomId, + + /// The name of the tag to create. + #[ruma_api(path)] + pub tag: String, + + /// Info about the tag. + #[ruma_api(body)] + pub tag_info: TagInfo, } response {} diff --git a/src/r0/tag/delete_tag.rs b/src/r0/tag/delete_tag.rs index 633903d9..5d086ddc 100644 --- a/src/r0/tag/delete_tag.rs +++ b/src/r0/tag/delete_tag.rs @@ -1,4 +1,4 @@ -//! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.4.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) +//! [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; @@ -14,15 +14,17 @@ ruma_api! { } request { - /// The tagged room. - #[ruma_api(path)] - pub room_id: RoomId, - /// The name of the tag to delete. - #[ruma_api(path)] - pub tag: String, /// The user whose tag will be deleted. #[ruma_api(path)] pub user_id: UserId, + + /// The tagged room. + #[ruma_api(path)] + pub room_id: RoomId, + + /// The name of the tag to delete. + #[ruma_api(path)] + pub tag: String, } response {} diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index d02cbe27..e4e0d40d 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) +//! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-rooms-roomid-tags) use ruma_api::ruma_api; use ruma_events::{tag::TagEventContent, EventJson}; @@ -15,12 +15,13 @@ ruma_api! { } request { - /// The room from which tags will be retrieved. - #[ruma_api(path)] - pub room_id: RoomId, /// The user whose tags will be retrieved. #[ruma_api(path)] pub user_id: UserId, + + /// The room from which tags will be retrieved. + #[ruma_api(path)] + pub room_id: RoomId, } response { diff --git a/src/r0/typing/create_typing_event.rs b/src/r0/typing/create_typing_event.rs index 6d1a4d84..23f245ff 100644 --- a/src/r0/typing/create_typing_event.rs +++ b/src/r0/typing/create_typing_event.rs @@ -1,4 +1,4 @@ -//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) +//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-typing-userid) use std::time::Duration; @@ -16,9 +16,19 @@ ruma_api! { } request { + /// The user who has started to type. + #[ruma_api(path)] + pub user_id: UserId, + /// The room in which the user is typing. #[ruma_api(path)] pub room_id: RoomId, + + // TODO: Group the following two body fields into an enum + + /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. + pub typing: bool, + /// The length of time in milliseconds to mark this user as typing. #[serde( with = "ruma_serde::duration::opt_ms", @@ -26,11 +36,6 @@ ruma_api! { skip_serializing_if = "Option::is_none", )] pub timeout: Option, - /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. - pub typing: bool, - /// The user who has started to type. - #[ruma_api(path)] - pub user_id: UserId, } response {} diff --git a/src/r0/voip/get_turn_server_info.rs b/src/r0/voip/get_turn_server_info.rs index 420a3382..dd056ea6 100644 --- a/src/r0/voip/get_turn_server_info.rs +++ b/src/r0/voip/get_turn_server_info.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) +//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-voip-turnserver) use std::time::Duration; @@ -17,15 +17,18 @@ ruma_api! { request {} response { + /// The username to use. + pub username: String, + /// The password to use. pub password: String, + + /// A list of TURN URIs. + pub uris: Vec, + /// The time-to-live in seconds. #[serde(with = "ruma_serde::duration::secs")] pub ttl: Duration, - /// A list of TURN URIs. - pub uris: Vec, - /// The username to use. - pub username: String, } error: crate::Error diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index 3c3dd557..99b076db 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -1,23 +1,9 @@ -//! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-well-known-matrix-client) +//! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.6.0#get-well-known-matrix-client) use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; use url::Url; -/// Information about a discovered homeserver. -#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] -pub struct HomeserverInfo { - /// The base URL for the homeserver for client-server connections. - pub base_url: Url, -} - -/// Information about a discovered identity server. -#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] -pub struct IdentityServerInfo { - /// The base URL for the identity server for client-server connections. - pub base_url: Url, -} - ruma_api! { metadata { description: "Get discovery information about the domain.", @@ -42,3 +28,17 @@ ruma_api! { error: crate::Error } + +/// Information about a discovered homeserver. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] +pub struct HomeserverInfo { + /// The base URL for the homeserver for client-server connections. + pub base_url: Url, +} + +/// Information about a discovered identity server. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] +pub struct IdentityServerInfo { + /// The base URL for the identity server for client-server connections. + pub base_url: Url, +} From ae8a62982395210f8f2f745067f734a052e1f880 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 00:16:43 +0200 Subject: [PATCH 309/350] Remove dependency on the url crate --- Cargo.toml | 1 - src/unversioned/discover_homeserver.rs | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 29aecc18..c3502ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,3 @@ ruma-serde = "0.1.3" serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.52" strum = { version = "0.18.0", features = ["derive"] } -url = { version = "2.1.1", features = ["serde"] } diff --git a/src/unversioned/discover_homeserver.rs b/src/unversioned/discover_homeserver.rs index 99b076db..b82ef0de 100644 --- a/src/unversioned/discover_homeserver.rs +++ b/src/unversioned/discover_homeserver.rs @@ -2,7 +2,6 @@ use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; -use url::Url; ruma_api! { metadata { @@ -33,12 +32,12 @@ ruma_api! { #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct HomeserverInfo { /// The base URL for the homeserver for client-server connections. - pub base_url: Url, + pub base_url: String, } /// Information about a discovered identity server. #[derive(Clone, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)] pub struct IdentityServerInfo { /// The base URL for the identity server for client-server connections. - pub base_url: Url, + pub base_url: String, } From 3db0abe4cc5a18360ed7f6e6e45585a962ec9a14 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 00:16:48 +0200 Subject: [PATCH 310/350] Update change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9fbdc1..a900df4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Breaking changes: +* Update all endpoints to r0.6.0 + * Some of the changes from that might not be listed below, but it should be + easy to figure out what changed from the documentation and compiler errors + if you are using any of the affected endpoints. * Add `server_name` parameter to `r0::join::join_room_by_id_or_alias` * Modify `r0::account::AuthenticationData`: * Rename to `AuthData` @@ -35,6 +39,7 @@ Improvements: * Add missing serde attributes to `get_content_thumbnail` query parameters * Add missing `state` response field to `r0::message::get_message_events` * Normalize `serde_json` imports +* Remove dependeny on the `url` crate # 0.7.2 From fc626d08694bd1f81d8543ee5b77e464b06207bf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 00:41:51 +0200 Subject: [PATCH 311/350] Whitespace and comment wrapping adjustments --- src/error.rs | 32 +++++++++++++++++++ src/r0/account.rs | 2 ++ src/r0/account/add_3pid.rs | 3 +- src/r0/account/bind_3pid.rs | 2 ++ src/r0/account/change_password.rs | 1 + src/r0/account/deactivate.rs | 1 + src/r0/account/delete_3pid.rs | 2 ++ src/r0/account/register.rs | 9 ++++++ ...request_3pid_management_token_via_email.rs | 5 +++ ...equest_3pid_management_token_via_msisdn.rs | 6 ++++ src/r0/account/request_openid_token.rs | 3 ++ ...request_password_change_token_via_email.rs | 5 +++ ...equest_password_change_token_via_msisdn.rs | 5 +++ .../request_registration_token_via_email.rs | 5 +++ .../request_registration_token_via_msisdn.rs | 6 ++++ src/r0/account/unbind_3pid.rs | 2 ++ src/r0/alias/create_alias.rs | 1 + src/r0/alias/get_alias.rs | 1 + src/r0/appservice/set_room_visibility.rs | 2 ++ src/r0/config/get_global_account_data.rs | 1 + src/r0/config/get_room_account_data.rs | 2 ++ src/r0/contact/get_contacts.rs | 3 ++ src/r0/device.rs | 3 ++ src/r0/device/delete_device.rs | 1 + src/r0/device/update_device.rs | 1 + src/r0/directory.rs | 8 +++++ src/r0/directory/get_public_rooms.rs | 5 +++ src/r0/directory/get_public_rooms_filtered.rs | 9 ++++++ src/r0/filter.rs | 20 ++++++++++++ src/r0/keys.rs | 7 ++++ src/r0/keys/get_keys.rs | 20 +++++++----- src/r0/media/get_content.rs | 4 +++ src/r0/media/get_content_as_filename.rs | 5 +++ src/r0/media/get_content_thumbnail.rs | 7 ++++ src/r0/media/get_media_preview.rs | 1 + src/r0/membership.rs | 3 ++ src/r0/membership/get_member_events.rs | 3 ++ src/r0/membership/invite_user.rs | 2 ++ src/r0/membership/joined_members.rs | 1 + src/r0/message/get_message_events.rs | 9 ++++++ src/r0/presence/get_presence.rs | 3 ++ src/r0/push.rs | 1 + src/r0/room.rs | 1 + src/r0/room/create_room.rs | 15 +++++++++ src/r0/room/get_room_event.rs | 1 + src/r0/room/report_content.rs | 3 ++ src/r0/room/upgrade_room.rs | 1 + src/r0/search/search_events.rs | 11 +++++++ src/r0/session/get_login_types.rs | 1 + src/r0/session/login.rs | 13 ++++++++ src/r0/sync/sync_events.rs | 28 ++++++++++++++++ src/r0/thirdparty.rs | 13 ++++++++ .../thirdparty/get_location_for_protocol.rs | 1 + src/r0/thirdparty/get_user_for_protocol.rs | 1 + src/r0/to_device.rs | 1 + src/r0/to_device/send_event_to_device.rs | 2 ++ src/r0/uiaa.rs | 8 +++++ src/r0/user_directory/search_users.rs | 4 +++ src/unversioned/get_supported_versions.rs | 1 + 59 files changed, 308 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 102467ce..fb939caa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -16,118 +16,147 @@ pub enum ErrorKind { #[serde(rename = "M_FORBIDDEN")] #[strum(to_string = "M_FORBIDDEN")] Forbidden, + /// M_UNKNOWN_TOKEN #[serde(rename = "M_UNKNOWN_TOKEN")] #[strum(to_string = "M_UNKNOWN_TOKEN")] UnknownToken, + /// M_MISSING_TOKEN #[serde(rename = "M_MISSING_TOKEN")] #[strum(to_string = "M_MISSING_TOKEN")] MissingToken, + /// M_BAD_JSON #[serde(rename = "M_BAD_JSON")] #[strum(to_string = "M_BAD_JSON")] BadJson, + /// M_NOT_JSON #[serde(rename = "M_NOT_JSON")] #[strum(to_string = "M_NOT_JSON")] NotJson, + /// M_NOT_FOUND #[serde(rename = "M_NOT_FOUND")] #[strum(to_string = "M_NOT_FOUND")] NotFound, + /// M_LIMIT_EXCEEDED #[serde(rename = "M_LIMIT_EXCEEDED")] #[strum(to_string = "M_LIMIT_EXCEEDED")] LimitExceeded, + /// M_UNKNOWN #[serde(rename = "M_UNKNOWN")] #[strum(to_string = "M_UNKNOWN")] Unknown, + /// M_UNRECOGNIZED #[serde(rename = "M_UNRECOGNIZED")] #[strum(to_string = "M_UNRECOGNIZED")] Unrecognized, + /// M_UNAUTHORIZED #[serde(rename = "M_UNAUTHORIZED")] #[strum(to_string = "M_UNAUTHORIZED")] Unauthorized, + /// M_USER_DEACTIVATED #[serde(rename = "M_USER_DEACTIVATED")] #[strum(to_string = "M_USER_DEACTIVATED")] UserDeactivated, + /// M_USER_IN_USE #[serde(rename = "M_USER_IN_USE")] #[strum(to_string = "M_USER_IN_USE")] UserInUse, + /// M_INVALID_USERNAME #[serde(rename = "M_INVALID_USERNAME")] #[strum(to_string = "M_INVALID_USERNAME")] InvalidUsername, + /// M_ROOM_IN_USE #[serde(rename = "M_ROOM_IN_USE")] #[strum(to_string = "M_ROOM_IN_USE")] RoomInUse, + /// M_INVALID_ROOM_STATE #[serde(rename = "M_INVALID_ROOM_STATE")] #[strum(to_string = "M_INVALID_ROOM_STATE")] InvalidRoomState, + /// M_THREEPID_IN_USE #[serde(rename = "M_THREEPID_IN_USE")] #[strum(to_string = "M_THREEPID_IN_USE")] ThreepidInUse, + /// M_THREEPID_NOT_FOUND #[serde(rename = "M_THREEPID_NOT_FOUND")] #[strum(to_string = "M_THREEPID_NOT_FOUND")] ThreepidNotFound, + /// M_THREEPID_AUTH_FAILED #[serde(rename = "M_THREEPID_AUTH_FAILED")] #[strum(to_string = "M_THREEPID_AUTH_FAILED")] ThreepidAuthFailed, + /// M_THREEPID_DENIED #[serde(rename = "M_THREEPID_DENIED")] #[strum(to_string = "M_THREEPID_DENIED")] ThreepidDenied, + /// M_SERVER_NOT_TRUSTED #[serde(rename = "M_SERVER_NOT_TRUSTED")] #[strum(to_string = "M_SERVER_NOT_TRUSTED")] ServerNotTrusted, + /// M_UNSUPPORTED_ROOM_VERSION #[serde(rename = "M_UNSUPPORTED_ROOM_VERSION")] #[strum(to_string = "M_UNSUPPORTED_ROOM_VERSION")] UnsupportedRoomVersion, + /// M_INCOMPATIBLE_ROOM_VERSION #[serde(rename = "M_INCOMPATIBLE_ROOM_VERSION")] #[strum(to_string = "M_INCOMPATIBLE_ROOM_VERSION")] IncompatibleRoomVersion, + /// M_BAD_STATE #[serde(rename = "M_BAD_STATE")] #[strum(to_string = "M_BAD_STATE")] BadState, + /// M_GUEST_ACCESS_FORBIDDEN #[serde(rename = "M_GUEST_ACCESS_FORBIDDEN")] #[strum(to_string = "M_GUEST_ACCESS_FORBIDDEN")] GuestAccessForbidden, + /// M_CAPTCHA_NEEDED #[serde(rename = "M_CAPTCHA_NEEDED")] #[strum(to_string = "M_CAPTCHA_NEEDED")] CaptchaNeeded, + /// M_CAPTCHA_INVALID #[serde(rename = "M_CAPTCHA_INVALID")] #[strum(to_string = "M_CAPTCHA_INVALID")] CaptchaInvalid, + /// M_MISSING_PARAM #[serde(rename = "M_MISSING_PARAM")] #[strum(to_string = "M_MISSING_PARAM")] MissingParam, + /// M_INVALID_PARAM #[serde(rename = "M_INVALID_PARAM")] #[strum(to_string = "M_INVALID_PARAM")] InvalidParam, + /// M_TOO_LARGE #[serde(rename = "M_TOO_LARGE")] #[strum(to_string = "M_TOO_LARGE")] TooLarge, + /// M_EXCLUSIVE #[serde(rename = "M_EXCLUSIVE")] #[strum(to_string = "M_EXCLUSIVE")] @@ -141,6 +170,7 @@ pub struct ErrorBody { /// A value which can be used to handle an error message #[serde(flatten)] pub kind: ErrorKind, + /// A human-readable error message, usually a sentence explaining what went wrong. #[serde(rename = "error")] pub message: String, @@ -151,8 +181,10 @@ pub struct ErrorBody { pub struct Error { /// A value which can be used to handle an error message pub kind: ErrorKind, + /// A human-readable error message, usually a sentence explaining what went wrong. pub message: String, + /// The http status code pub status_code: http::StatusCode, } diff --git a/src/r0/account.rs b/src/r0/account.rs index c015ab2f..f1a70ac8 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -25,6 +25,7 @@ pub struct IdentityServerInfo { /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. pub id_server: String, + /// Access token previously registered with identity server. pub id_access_token: String, } @@ -36,6 +37,7 @@ pub enum ThirdPartyIdRemovalStatus { /// Either the homeserver couldn't determine the right identity server to contact, or the /// identity server refused the operation. NoSupport, + /// Success. Success, } diff --git a/src/r0/account/add_3pid.rs b/src/r0/account/add_3pid.rs index adef2d45..44b663b2 100644 --- a/src/r0/account/add_3pid.rs +++ b/src/r0/account/add_3pid.rs @@ -18,8 +18,10 @@ ruma_api! { /// Additional information for the User-Interactive Authentication API. #[serde(skip_serializing_if = "Option::is_none")] pub auth: Option, + /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The session identifier given by the identity server. pub sid: String, } @@ -28,4 +30,3 @@ ruma_api! { error: UiaaResponse } - diff --git a/src/r0/account/bind_3pid.rs b/src/r0/account/bind_3pid.rs index 81bd7c46..d13c31b2 100644 --- a/src/r0/account/bind_3pid.rs +++ b/src/r0/account/bind_3pid.rs @@ -17,10 +17,12 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. #[serde(flatten)] pub identity_server_info: IdentityServerInfo, + /// The session identifier given by the identity server. pub sid: String, } diff --git a/src/r0/account/change_password.rs b/src/r0/account/change_password.rs index 6eb5f045..8a4223d1 100644 --- a/src/r0/account/change_password.rs +++ b/src/r0/account/change_password.rs @@ -17,6 +17,7 @@ ruma_api! { request { /// The new password for the account. pub new_password: String, + /// Additional authentication information for the user-interactive authentication API. pub auth: Option, } diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 5a21a071..6a1a7fd7 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -20,6 +20,7 @@ ruma_api! { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] pub auth: Option, + /// Identity server from which to unbind the user's third party /// identifier. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/account/delete_3pid.rs b/src/r0/account/delete_3pid.rs index ad95fd7b..3138cdb5 100644 --- a/src/r0/account/delete_3pid.rs +++ b/src/r0/account/delete_3pid.rs @@ -19,8 +19,10 @@ ruma_api! { /// Identity server to delete from. #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, + /// Medium of the 3PID to be removed. pub medium: Medium, + /// Third-party address being removed. pub address: String, } diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 27046397..1c14e99a 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -23,22 +23,26 @@ ruma_api! { /// with a password, e.g., for guest or application service accounts. #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, + /// local part of the desired Matrix ID. /// /// If omitted, the homeserver MUST generate a Matrix ID local part. #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, + /// ID of the client device. /// /// If this does not correspond to a known client device, a new device will be created. /// The server will auto-generate a device_id if this is not specified. #[serde(skip_serializing_if = "Option::is_none")] pub device_id: Option, + /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. #[serde(skip_serializing_if = "Option::is_none")] pub initial_device_display_name: Option, + /// Additional authentication information for the user-interactive authentication API. /// /// Note that this information is not used to define how the registered user should be @@ -47,12 +51,14 @@ ruma_api! { /// with status code 401. #[serde(skip_serializing_if = "Option::is_none")] pub auth: Option, + /// Kind of account to register /// /// Defaults to `User` if omitted. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, + /// If `true`, an `access_token` and `device_id` should not be returned /// from this call, therefore preventing an automatic login. #[serde(default, skip_serializing_if = "ruma_serde::is_default")] @@ -65,8 +71,10 @@ ruma_api! { /// This access token can then be used to authorize other requests. #[serde(skip_serializing_if = "Option::is_none")] pub access_token: Option, + /// The fully-qualified Matrix ID that has been registered. pub user_id: UserId, + /// ID of the registered device. /// /// Will be the same as the corresponding parameter in the request, if one was specified. @@ -84,6 +92,7 @@ pub enum RegistrationKind { /// /// These accounts may have limited permissions and may not be supported by all servers. Guest, + /// A regular user account User, } diff --git a/src/r0/account/request_3pid_management_token_via_email.rs b/src/r0/account/request_3pid_management_token_via_email.rs index dc6ceb7e..3042225b 100644 --- a/src/r0/account/request_3pid_management_token_via_email.rs +++ b/src/r0/account/request_3pid_management_token_via_email.rs @@ -18,13 +18,17 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The email address. pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] @@ -34,6 +38,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/request_3pid_management_token_via_msisdn.rs b/src/r0/account/request_3pid_management_token_via_msisdn.rs index f7e04125..21ce58af 100644 --- a/src/r0/account/request_3pid_management_token_via_msisdn.rs +++ b/src/r0/account/request_3pid_management_token_via_msisdn.rs @@ -18,15 +18,20 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. pub country: String, + /// Phone number to validate. pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] @@ -36,6 +41,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/request_openid_token.rs b/src/r0/account/request_openid_token.rs index ee5166d5..94107189 100644 --- a/src/r0/account/request_openid_token.rs +++ b/src/r0/account/request_openid_token.rs @@ -25,10 +25,13 @@ ruma_api! { response { /// Access token for verifying user's identity. pub access_token: String, + /// Access token type. pub token_type: TokenType, + /// Homeserver domain for verification of user's identity. pub matrix_server_name: String, + /// Seconds until token expiration. #[serde(with = "ruma_serde::duration::secs")] pub expires_in: Duration, diff --git a/src/r0/account/request_password_change_token_via_email.rs b/src/r0/account/request_password_change_token_via_email.rs index ae7096c6..1fd70ae3 100644 --- a/src/r0/account/request_password_change_token_via_email.rs +++ b/src/r0/account/request_password_change_token_via_email.rs @@ -18,13 +18,17 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The email address. pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] @@ -34,6 +38,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/request_password_change_token_via_msisdn.rs b/src/r0/account/request_password_change_token_via_msisdn.rs index 40f865a7..54b22a4b 100644 --- a/src/r0/account/request_password_change_token_via_msisdn.rs +++ b/src/r0/account/request_password_change_token_via_msisdn.rs @@ -16,12 +16,16 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. pub country: String, + /// Phone number to validate. pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, @@ -30,6 +34,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/request_registration_token_via_email.rs b/src/r0/account/request_registration_token_via_email.rs index 38468bfd..dc1c4cd0 100644 --- a/src/r0/account/request_registration_token_via_email.rs +++ b/src/r0/account/request_registration_token_via_email.rs @@ -18,13 +18,17 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// The email address. pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] @@ -34,6 +38,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/request_registration_token_via_msisdn.rs b/src/r0/account/request_registration_token_via_msisdn.rs index cce91ba7..89dac820 100644 --- a/src/r0/account/request_registration_token_via_msisdn.rs +++ b/src/r0/account/request_registration_token_via_msisdn.rs @@ -18,15 +18,20 @@ ruma_api! { request { /// Client-generated secret string used to protect this session. pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. pub country: String, + /// Phone number to validate. pub phone_number: String, + /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] pub next_link: Option, + /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. #[serde(flatten)] #[serde(skip_serializing_if = "Option::is_none")] @@ -36,6 +41,7 @@ ruma_api! { response { /// The session identifier given by the identity server. pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. #[serde(skip_serializing_if = "Option::is_none")] pub submit_url: Option diff --git a/src/r0/account/unbind_3pid.rs b/src/r0/account/unbind_3pid.rs index fec859cb..8bdd7098 100644 --- a/src/r0/account/unbind_3pid.rs +++ b/src/r0/account/unbind_3pid.rs @@ -19,8 +19,10 @@ ruma_api! { /// Identity server to unbind from. #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, + /// Medium of the 3PID to be removed. pub medium: Medium, + /// Third-party address being removed. pub address: String, } diff --git a/src/r0/alias/create_alias.rs b/src/r0/alias/create_alias.rs index 9770d22e..0c84c30c 100644 --- a/src/r0/alias/create_alias.rs +++ b/src/r0/alias/create_alias.rs @@ -17,6 +17,7 @@ ruma_api! { /// The room alias to set. #[ruma_api(path)] pub room_alias: RoomAliasId, + /// The room ID to set. pub room_id: RoomId, } diff --git a/src/r0/alias/get_alias.rs b/src/r0/alias/get_alias.rs index 00ec2100..8e462a7c 100644 --- a/src/r0/alias/get_alias.rs +++ b/src/r0/alias/get_alias.rs @@ -22,6 +22,7 @@ ruma_api! { response { /// The room ID for this room alias. pub room_id: RoomId, + /// A list of servers that are aware of this room ID. pub servers: Vec, } diff --git a/src/r0/appservice/set_room_visibility.rs b/src/r0/appservice/set_room_visibility.rs index 5df0c5d7..f819e762 100644 --- a/src/r0/appservice/set_room_visibility.rs +++ b/src/r0/appservice/set_room_visibility.rs @@ -19,9 +19,11 @@ ruma_api! { /// The protocol (network) ID to update the room list for. #[ruma_api(path)] pub network_id: String, + /// The room ID to add to the directory. #[ruma_api(path)] pub room_id: RoomId, + /// Whether the room should be visible (public) in the directory or not (private). pub visibility: Visibility, } diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs index 41cb40f9..d8c1d763 100644 --- a/src/r0/config/get_global_account_data.rs +++ b/src/r0/config/get_global_account_data.rs @@ -18,6 +18,7 @@ ruma_api! { /// User ID of user for whom to retrieve data. #[ruma_api(path)] pub user_id: UserId, + /// Type of data to retrieve. #[ruma_api(path)] pub event_type: String, diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs index 2f7a978e..a2b39600 100644 --- a/src/r0/config/get_room_account_data.rs +++ b/src/r0/config/get_room_account_data.rs @@ -18,9 +18,11 @@ ruma_api! { /// User ID of user for whom to retrieve data. #[ruma_api(path)] pub user_id: UserId, + /// Room ID for which to retrieve data. #[ruma_api(path)] pub room_id: RoomId, + /// Type of data to retrieve. #[ruma_api(path)] pub event_type: String, diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index 06834c64..06de18bc 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -35,11 +35,14 @@ ruma_api! { pub struct ThirdPartyIdentifier { /// The third party identifier address. pub address: String, + /// The medium of third party identifier. pub medium: Medium, + /// The time when the identifier was validated by the identity server. #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub validated_at: SystemTime, + /// The time when the homeserver associated the third party identifier with the user. #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub added_at: SystemTime, diff --git a/src/r0/device.rs b/src/r0/device.rs index 6e0a8620..0c22c151 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -16,10 +16,13 @@ pub mod update_device; pub struct Device { /// Device ID pub device_id: DeviceId, + /// Public display name of the device. pub display_name: Option, + /// Most recently seen IP address of the session. pub ip: Option, + /// Unix timestamp that the session was last active. #[serde( with = "ruma_serde::time::opt_ms_since_unix_epoch", diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs index 2f5f33f0..19a8df30 100644 --- a/src/r0/device/delete_device.rs +++ b/src/r0/device/delete_device.rs @@ -19,6 +19,7 @@ ruma_api! { /// The device to delete. #[ruma_api(path)] pub device_id: DeviceId, + /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] pub auth: Option, diff --git a/src/r0/device/update_device.rs b/src/r0/device/update_device.rs index 239dd07d..fdd30d67 100644 --- a/src/r0/device/update_device.rs +++ b/src/r0/device/update_device.rs @@ -17,6 +17,7 @@ ruma_api! { /// The device to update. #[ruma_api(path)] pub device_id: DeviceId, + /// The new display name for this device. If this is `None`, the display name won't be /// changed. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/directory.rs b/src/r0/directory.rs index a0bdcc1d..9e8a1099 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -13,25 +13,33 @@ pub struct PublicRoomsChunk { /// Aliases of the room. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub aliases: Vec, + /// The canonical alias of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] pub canonical_alias: Option, + /// The name of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + /// The number of members joined to the room. pub num_joined_members: UInt, + /// The ID of the room. pub room_id: RoomId, + /// The topic of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, + /// Whether the room may be viewed by guest users without joining. pub world_readable: bool, + /// Whether guest users may join the room and participate in it. /// /// If they can, they will be subject to ordinary power level rules like any other user. pub guest_can_join: bool, + /// The URL for the room's avatar, if one is set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index c7a54495..edac36b8 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -20,10 +20,12 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub limit: Option, + /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub since: Option, + /// The server to fetch the public room lists from. /// /// `None` means the server this request is sent to. @@ -35,10 +37,13 @@ ruma_api! { response { /// A paginated chunk of public rooms. pub chunk: Vec, + /// A pagination token for the response. pub next_batch: Option, + /// A pagination token that allows fetching previous results. pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. pub total_room_count_estimate: Option, } diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs index 716df562..9680c55a 100644 --- a/src/r0/directory/get_public_rooms_filtered.rs +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -31,15 +31,19 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub server: Option, + /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, + /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, + /// Filter to apply to the results. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + /// Network to fetch the public room lists from. #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] pub room_network: RoomNetwork, @@ -48,10 +52,13 @@ ruma_api! { response { /// A paginated chunk of public rooms. pub chunk: Vec, + /// A pagination token for the response. pub next_batch: Option, + /// A pagination token that allows fetching previous results. pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. pub total_room_count_estimate: Option, } @@ -73,8 +80,10 @@ pub struct Filter { pub enum RoomNetwork { /// Return rooms from the Matrix network. Matrix, + /// Return rooms from all the networks/protocols the homeserver knows about. All, + /// Return rooms from a specific third party network/protocol. ThirdParty(String), } diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 707a1c7b..ae004c32 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -19,6 +19,7 @@ use serde::{ pub enum EventFormat { /// Client format, as described in the Client API. Client, + /// Raw events from federation. Federation, } @@ -33,43 +34,51 @@ pub struct RoomEventFilter { /// sequence of characters. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_types: Vec, + /// A list of room IDs to exclude. /// /// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// it is listed in the 'rooms' filter. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_rooms: Vec, + /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, + /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. #[serde(default, skip_serializing_if = "Option::is_none")] pub rooms: Option>, + /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even /// if it is listed in the 'senders' filter. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_senders: Vec, + /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. #[serde(default, skip_serializing_if = "Option::is_none")] pub senders: Option>, + /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. #[serde(default, skip_serializing_if = "Option::is_none")] pub types: Option>, + /// If `true` include only events with a URL key in their content. /// If `false`, exclude such events. /// /// If this item is absent then all event types are included. #[serde(skip_serializing_if = "Option::is_none")] pub contains_url: Option, + /// Options to control lazy-loading of membership events. #[serde(flatten)] pub lazy_load_options: LazyLoadOptions, @@ -93,19 +102,24 @@ pub struct RoomFilter { /// Defaults to false if not included. #[serde(skip_serializing_if = "Option::is_none")] pub include_leave: Option, + /// The per user account data to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + /// The message and state update events to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub timeline: Option, + /// The events that aren't recorded in the room history, e.g. typing and receipts, to include /// for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub ephemeral: Option, + /// The state events to include for rooms. #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, + /// A list of room IDs to exclude. /// /// If this list is absent then no rooms are excluded. A matching room will be excluded even if @@ -113,6 +127,7 @@ pub struct RoomFilter { /// `ephemeral`, `state`, `timeline` or `account_data`. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_rooms: Vec, + /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. This filter is applied before the @@ -141,20 +156,24 @@ pub struct Filter { /// sequence of characters. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub not_types: Vec, + /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, + /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. #[serde(default, skip_serializing_if = "Option::is_none")] pub senders: Option>, + /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// match any sequence of characters. #[serde(default, skip_serializing_if = "Option::is_none")] pub types: Option>, + /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded even @@ -225,6 +244,7 @@ impl FilterDefinition { pub enum LazyLoadOptions { /// Disables lazy-loading of membership events. Disabled, + /// Enables lazy-loading of events. Enabled { /// If `true`, sends all membership events for all events, even if they have diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 1d14d27d..0d53dea5 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -111,14 +111,19 @@ impl<'de> Deserialize<'de> for AlgorithmAndDeviceId { pub struct DeviceKeys { /// The ID of the user the device belongs to. Must match the user ID used when logging in. pub user_id: UserId, + /// The ID of the device these keys belong to. Must match the device ID used when logging in. pub device_id: DeviceId, + /// The encryption algorithms supported by this device. pub algorithms: Vec, + /// Public identity keys. pub keys: BTreeMap, + /// Signatures for the device key object. pub signatures: BTreeMap>, + /// Additional data added to the device key information by intermediate servers, and /// not covered by the signatures. #[serde(skip_serializing_if = "Option::is_none")] @@ -137,6 +142,7 @@ pub struct UnsignedDeviceInfo { pub struct SignedKey { /// Base64-encoded 32-byte Curve25519 public key. pub key: String, + /// Signatures for the key object. pub signatures: BTreeMap>, } @@ -147,6 +153,7 @@ pub struct SignedKey { pub enum OneTimeKey { /// A key containing signatures, for the SignedCurve25519 algorithm. SignedKey(SignedKey), + /// A string-valued key, for the Ed25519 and Curve25519 algorithms. Key(String), } diff --git a/src/r0/keys/get_keys.rs b/src/r0/keys/get_keys.rs index 74194f38..a8ec4dd2 100644 --- a/src/r0/keys/get_keys.rs +++ b/src/r0/keys/get_keys.rs @@ -19,8 +19,8 @@ ruma_api! { } request { - /// The time (in milliseconds) to wait when downloading keys from remote servers. - /// 10 seconds is the recommended default. + /// The time (in milliseconds) to wait when downloading keys from remote + /// servers. 10 seconds is the recommended default. #[serde( with = "ruma_serde::duration::opt_ms", default, @@ -28,19 +28,23 @@ ruma_api! { )] pub timeout: Option, - /// The keys to be downloaded. An empty list indicates all devices for the corresponding user. + /// The keys to be downloaded. An empty list indicates all devices for + /// the corresponding user. pub device_keys: BTreeMap>, - /// If the client is fetching keys as a result of a device update received in a sync request, - /// this should be the 'since' token of that sync request, or any later sync token. - /// This allows the server to ensure its response contains the keys advertised by the notification in that sync. + /// If the client is fetching keys as a result of a device update + /// received in a sync request, this should be the 'since' token of that + /// sync request, or any later sync token. This allows the server to + /// ensure its response contains the keys advertised by the notification + /// in that sync. #[serde(skip_serializing_if = "Option::is_none")] pub token: Option, } response { - /// If any remote homeservers could not be reached, they are recorded here. - /// The names of the properties are the names of the unreachable servers. + /// If any remote homeservers could not be reached, they are recorded + /// here. The names of the properties are the names of the unreachable + /// servers. pub failures: BTreeMap, /// Information on the queried devices. diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 22ec5d2f..97fe4eb0 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -16,9 +16,11 @@ ruma_api! { /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] pub server_name: String, + /// Whether to fetch media deemed remote. /// Used to prevent routing loops. Defaults to `true`. #[ruma_api(query)] @@ -29,9 +31,11 @@ ruma_api! { /// The content that was previously uploaded. #[ruma_api(raw_body)] pub file: Vec, + /// The content type of the file that was previously uploaded. #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, + /// The name of the file that was previously uploaded, if set. #[ruma_api(header = CONTENT_DISPOSITION)] pub content_disposition: String, diff --git a/src/r0/media/get_content_as_filename.rs b/src/r0/media/get_content_as_filename.rs index f97692d1..0664b331 100644 --- a/src/r0/media/get_content_as_filename.rs +++ b/src/r0/media/get_content_as_filename.rs @@ -16,12 +16,15 @@ ruma_api! { /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] pub server_name: String, + /// The filename to return in the `Content-Disposition` header. #[ruma_api(path)] pub filename: String, + /// Whether to fetch media deemed remote. /// Used to prevent routing loops. Defaults to `true`. #[ruma_api(query)] @@ -32,9 +35,11 @@ ruma_api! { /// The content that was previously uploaded. #[ruma_api(raw_body)] pub file: Vec, + /// The content type of the file that was previously uploaded. #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, + /// The name of the file that was previously uploaded, if set. #[ruma_api(header = CONTENT_DISPOSITION)] pub content_disposition: String, diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index a6d9a127..54b5ef40 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize}; pub enum Method { /// Crop the original to produce the requested image dimensions. Crop, + /// Maintain the original aspect ratio of the source image. Scale, } @@ -31,20 +32,25 @@ ruma_api! { #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] pub allow_remote: Option, + /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] pub media_id: String, + /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] pub server_name: String, + /// The *desired* height of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] pub height: UInt, + /// The desired resizing method. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] pub method: Option, + /// The *desired* width of the thumbnail. The actual thumbnail may not match the size /// specified. #[ruma_api(query)] @@ -55,6 +61,7 @@ ruma_api! { /// The content type of the thumbnail. #[ruma_api(header = CONTENT_TYPE)] pub content_type: String, + /// A thumbnail of the requested content. #[ruma_api(body)] pub file: Vec, diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index be407264..d387b142 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -19,6 +19,7 @@ ruma_api! { /// URL to get a preview of. #[ruma_api(query)] pub url: String, + /// Preferred point in time (in milliseconds) to return a preview for. #[ruma_api(query)] #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 4acac3db..047276f0 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -40,10 +40,13 @@ pub struct ThirdPartySigned { pub struct Invite3pid { /// Hostname and port of identity server to be used for account lookups. pub id_server: String, + /// An access token registered with the identity server. pub id_access_token: String, + /// Type of third party ID. pub medium: Medium, + /// Third party identifier. pub address: String, } diff --git a/src/r0/membership/get_member_events.rs b/src/r0/membership/get_member_events.rs index 76d83b65..4ca6686c 100644 --- a/src/r0/membership/get_member_events.rs +++ b/src/r0/membership/get_member_events.rs @@ -54,10 +54,13 @@ ruma_api! { pub enum MembershipEventFilter { /// The user has joined. Join, + /// The user has been invited. Invite, + /// The user has left. Leave, + /// The user has been banned. Ban, } diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index 9febe0d7..1f4796f6 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -26,6 +26,7 @@ ruma_api! { /// The room where the user should be invited. #[ruma_api(path)] pub room_id: RoomId, + /// The user to invite. #[ruma_api(body)] pub recipient: InvitationRecipient, @@ -45,6 +46,7 @@ pub enum InvitationRecipient { /// Matrix identifier of user. user_id: UserId, }, + /// Used to invite user by a third party identifer. ThirdPartyId(Invite3pid), } diff --git a/src/r0/membership/joined_members.rs b/src/r0/membership/joined_members.rs index 400ee601..dfd92cbc 100644 --- a/src/r0/membership/joined_members.rs +++ b/src/r0/membership/joined_members.rs @@ -37,6 +37,7 @@ pub struct RoomMember { /// The display name of the user. #[serde(skip_serializing_if = "Option::is_none")] pub display_name: Option, + /// The mxc avatar url of the user. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index 2f70ed81..0248c9e7 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -25,6 +25,7 @@ ruma_api! { /// The room to get events from. #[ruma_api(path)] pub room_id: RoomId, + /// The token to start returning events from. /// /// This token can be obtained from a @@ -32,6 +33,7 @@ ruma_api! { /// returned by a previous request to this endpoint. #[ruma_api(query)] pub from: String, + /// The token to stop returning events at. /// /// This token can be obtained from a prev_batch @@ -40,15 +42,18 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub to: Option, + /// The direction to return events from. #[ruma_api(query)] pub dir: Direction, + /// The maximum number of events to return. /// /// Default: 10. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub limit: Option, + /// A RoomEventFilter to filter returned events with. #[ruma_api(query)] #[serde( @@ -63,12 +68,15 @@ ruma_api! { /// The token the pagination starts from. #[serde(skip_serializing_if = "Option::is_none")] pub start: Option, + /// The token the pagination ends at. #[serde(skip_serializing_if = "Option::is_none")] pub end: Option, + /// A list of room events. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub chunk: Vec>, + /// A list of state events relevant to showing the `chunk`. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub state: Vec>, @@ -83,6 +91,7 @@ pub enum Direction { /// Return events backwards in time from the requested `from` token. #[serde(rename = "b")] Backward, + /// Return events forwards in time from the requested `from` token. #[serde(rename = "f")] Forward, diff --git a/src/r0/presence/get_presence.rs b/src/r0/presence/get_presence.rs index b6e02d6e..bb7184c2 100644 --- a/src/r0/presence/get_presence.rs +++ b/src/r0/presence/get_presence.rs @@ -26,9 +26,11 @@ ruma_api! { /// The state message for this user if one was set. #[serde(skip_serializing_if = "Option::is_none")] pub status_msg: Option, + /// Whether or not the user is currently active. #[serde(skip_serializing_if = "Option::is_none")] pub currently_active: Option, + /// The length of time in milliseconds since an action was performed by the user. #[serde( with = "ruma_serde::duration::opt_ms", @@ -36,6 +38,7 @@ ruma_api! { skip_serializing_if = "Option::is_none", )] pub last_active_ago: Option, + /// The user's presence state. pub presence: PresenceState, } diff --git a/src/r0/push.rs b/src/r0/push.rs index cf922f8d..19d310dd 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -84,6 +84,7 @@ pub enum PushCondition { EventMatch { /// The dot-separated field of the event to match, e.g. `content.body` key: String, + /// The glob-style pattern to match against. pattern: String, }, diff --git a/src/r0/room.rs b/src/r0/room.rs index 52853f4e..6c20c58b 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; pub enum Visibility { /// Indicates that the room will be shown in the published room list. Public, + /// Indicates that the room will not be shown in the published room list. Private, } diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 89ca0dfd..83b6c35f 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -23,43 +23,54 @@ ruma_api! { /// Extra keys to be added to the content of the `m.room.create`. #[serde(skip_serializing_if = "Option::is_none")] pub creation_content: Option, + /// List of state events to send to the new room. /// /// Takes precedence over events set by preset, but gets overriden by /// name and topic keys. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub initial_state: Vec, + /// A list of user IDs to invite to the room. /// /// This will tell the server to invite everyone in the list to the newly created room. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub invite: Vec, + /// List of third party IDs of users to invite. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub invite_3pid: Vec, + /// If set, this sets the `is_direct` flag on room invites. #[serde(skip_serializing_if = "Option::is_none")] pub is_direct: Option, + /// If this is included, an `m.room.name` event will be sent into the room to indicate /// the name of the room. #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] pub power_level_content_override: Option>, + /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, + /// The desired room alias local part. #[serde(skip_serializing_if = "Option::is_none")] pub room_alias_name: Option, + /// Room version to set for the room. Defaults to homeserver's default if not specified. #[serde(skip_serializing_if = "Option::is_none")] pub room_version: Option, + /// If this is included, an `m.room.topic` event will be sent into the room to indicate /// the topic for the room. #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, + /// A public visibility indicates that the room will be shown in the published room /// list. A private visibility will hide the room from the published room list. Rooms /// default to private visibility if this key is not included. @@ -91,8 +102,10 @@ pub struct CreationContent { pub enum RoomPreset { /// `join_rules` is set to `invite` and `history_visibility` is set to `shared`. PrivateChat, + /// `join_rules` is set to `public` and `history_visibility` is set to `shared`. PublicChat, + /// Same as `PrivateChat`, but all initial invitees get the same power level as the creator. TrustedPrivateChat, } @@ -103,8 +116,10 @@ pub struct InitialStateEvent { /// State event type. #[serde(rename = "type")] pub event_type: String, + /// `state_key` of the event to be sent. pub state_key: Option, + /// JSON content of the state event. pub content: JsonValue, } diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs index b38c9e7f..fdf58126 100644 --- a/src/r0/room/get_room_event.rs +++ b/src/r0/room/get_room_event.rs @@ -18,6 +18,7 @@ ruma_api! { /// The ID of the room the event is in. #[ruma_api(path)] pub room_id: RoomId, + /// The ID of the event. #[ruma_api(path)] pub event_id: EventId, diff --git a/src/r0/room/report_content.rs b/src/r0/room/report_content.rs index 40ef14d1..690e3d03 100644 --- a/src/r0/room/report_content.rs +++ b/src/r0/room/report_content.rs @@ -18,11 +18,14 @@ ruma_api! { /// Room in which the event to be reported is located. #[ruma_api(path)] pub room_id: RoomId, + /// Event to report. #[ruma_api(path)] pub event_id: EventId, + /// Integer between -100 and 0 rating offensivness. pub score: Int, + /// Reason to report content. May be blank. pub reason: String, } diff --git a/src/r0/room/upgrade_room.rs b/src/r0/room/upgrade_room.rs index 5a152b3e..58e7e925 100644 --- a/src/r0/room/upgrade_room.rs +++ b/src/r0/room/upgrade_room.rs @@ -17,6 +17,7 @@ ruma_api! { /// ID of the room to be upgraded. #[ruma_api(path)] pub room_id: RoomId, + /// New version for the room. pub new_version: String, } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index e2e7b240..1e07ff62 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -204,18 +204,23 @@ pub struct ResultCategories { pub struct RoomEventJsons { /// An approximate count of the total number of results found. pub count: UInt, + /// Any groups that were requested. pub groups: BTreeMap>, + /// Token that can be used to get the next batch of results, by passing as the `next_batch` /// parameter to the next call. If this field is absent, there are no more results. #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, + /// List of results in the requested order. pub results: Vec, + /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub state: BTreeMap>>, + /// List of words which should be highlighted, useful for stemming which may /// change the query terms. #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -230,8 +235,10 @@ pub struct ResultGroup { /// results in this group. #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, + /// Key that can be used to order different groups. pub order: UInt, + /// Which results are in this group. pub results: Vec, } @@ -242,9 +249,11 @@ pub struct SearchResult { /// Context for result, if requested. #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, + /// A number that describes how closely this result matches the search. Higher is closer. #[serde(skip_serializing_if = "Option::is_none")] pub rank: Option, + /// The event that matched. #[serde(skip_serializing_if = "Option::is_none")] pub result: Option>, @@ -256,6 +265,7 @@ pub struct UserProfile { /// The user's avatar URL, if set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, + /// The user's display name, if set. #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, @@ -266,6 +276,7 @@ pub struct UserProfile { pub enum RoomIdOrUserId { /// Represents a room ID. RoomId(RoomId), + /// Represents a user ID. UserId(UserId), } diff --git a/src/r0/session/get_login_types.rs b/src/r0/session/get_login_types.rs index a07da00c..0e30d789 100644 --- a/src/r0/session/get_login_types.rs +++ b/src/r0/session/get_login_types.rs @@ -30,6 +30,7 @@ pub enum LoginType { /// A password is supplied to authenticate. #[serde(rename = "m.login.password")] Password, + /// Token-based login. #[serde(rename = "m.login.token")] Token, diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index f9444bf9..7c0216b2 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -20,12 +20,15 @@ ruma_api! { /// Identification information for the user. #[serde(flatten)] pub user: UserInfo, + /// The authentication mechanism. #[serde(flatten)] pub login_info: LoginInfo, + /// ID of the client device #[serde(skip_serializing_if = "Option::is_none")] pub device_id: Option, + /// A display name to assign to the newly-created device. Ignored if device_id corresponds /// to a known device. #[serde(skip_serializing_if = "Option::is_none")] @@ -35,19 +38,23 @@ ruma_api! { response { /// The fully-qualified Matrix ID that has been registered. pub user_id: UserId, + /// An access token for the account. pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. /// /// Deprecated: Clients should extract the server_name from user_id (by splitting at the /// first colon) if they require it. #[serde(skip_serializing_if = "Option::is_none")] pub home_server: Option, + /// ID of the logged-in device. /// /// Will be the same as the corresponging parameter in the request, if one was /// specified. pub device_id: String, + /// Client configuration provided by the server. /// /// If present, clients SHOULD use the provided object to reconfigure themselves. @@ -64,18 +71,22 @@ pub enum UserInfo { /// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier' /// field). MatrixId(String), + /// Third party identifier (as part of the 'identifier' field). ThirdPartyId { /// Third party identifier for the user. address: String, + /// The medium of the identifier. medium: Medium, }, + /// Same as third-party identification with medium == msisdn, but with a non-canonicalised /// phone number. PhoneNumber { /// The country that the phone number is from. country: String, + /// The phone number. phone: String, }, @@ -91,6 +102,7 @@ pub enum LoginInfo { /// The password. password: String, }, + /// Token-based login. #[serde(rename = "m.login.token")] Token { @@ -105,6 +117,7 @@ pub struct DiscoveryInfo { /// Information about the homeserver to connect to. #[serde(rename = "m.homeserver")] pub homeserver: HomeserverInfo, + /// Information about the identity server to connect to. #[serde(rename = "m.identity_server")] pub identity_server: Option, diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 9a9add73..489191ae 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -34,6 +34,7 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub filter: Option, + /// A point in time to continue a sync from. /// /// Should be a token from the `next_batch` field of a previous `/sync` @@ -41,14 +42,17 @@ ruma_api! { #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] pub since: Option, + /// Controls whether to include the full state for all rooms the user is a member of. #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_api(query)] pub full_state: bool, + /// Controls whether the client is automatically marked as online by polling this API. #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_api(query)] pub set_presence: SetPresence, + /// The maximum time to poll in milliseconds before returning this request. #[serde( with = "ruma_serde::duration::opt_ms", @@ -62,20 +66,26 @@ ruma_api! { response { /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, + /// Updates to rooms. pub rooms: Rooms, + /// Updates to the presence status of other users. pub presence: Presence, + /// The global private data created by this user. pub account_data: AccountData, + /// Messages sent dirrectly between devices. #[serde(default, skip_serializing_if = "ToDevice::is_empty")] pub to_device: ToDevice, + /// Information on E2E device updates. /// /// Only present on an incremental sync. #[serde(skip_serializing_if = "Option::is_none")] pub device_lists: Option, + /// For each key algorithm, the number of unclaimed one-time keys /// currently held on the server for a device. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -91,8 +101,10 @@ ruma_api! { pub enum SetPresence { /// Do not set the presence of the user calling this API. Offline, + /// Mark client as online explicitly. Assumed by default. Online, + /// Mark client as being idle. Unavailable, } @@ -121,6 +133,7 @@ pub enum Filter { #[serde(with = "ruma_serde::json_string")] /// A complete filter definition serialized to JSON. FilterDefinition(FilterDefinition), + /// The ID of a filter saved on the server. FilterId(String), } @@ -130,8 +143,10 @@ pub enum Filter { pub struct Rooms { /// The rooms that the user has left or been banned from. pub leave: BTreeMap, + /// The rooms that the user has joined. pub join: BTreeMap, + /// The rooms that the user has been invited to. pub invite: BTreeMap, } @@ -142,8 +157,10 @@ pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. pub timeline: Timeline, + /// The state updates for the room up to the start of the timeline. pub state: State, + /// The private data that this user has attached to this room. #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, @@ -155,17 +172,22 @@ pub struct JoinedRoom { /// Information about the room which clients may need to correctly render it /// to users. pub summary: RoomSummary, + /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, + /// The timeline of messages and state changes in the room. pub timeline: Timeline, + /// Updates to the state, between the time indicated by the `since` parameter, and the start /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not /// given, or `full_state` is true). pub state: State, + /// The private data that this user has attached to this room. #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// room. e.g. typing. pub ephemeral: Ephemeral, @@ -177,6 +199,7 @@ pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. #[serde(skip_serializing_if = "Option::is_none")] pub highlight_count: Option, + /// The total number of unread notifications for this room. #[serde(skip_serializing_if = "Option::is_none")] pub notification_count: Option, @@ -188,10 +211,12 @@ pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. #[serde(skip_serializing_if = "Option::is_none")] pub limited: Option, + /// A token that can be supplied to to the `from` parameter of the /// `/rooms/{roomId}/messages` endpoint. #[serde(skip_serializing_if = "Option::is_none")] pub prev_batch: Option, + /// A list of events. pub events: Vec>, } @@ -224,6 +249,7 @@ pub struct RoomSummary { /// one. Required if room name or canonical aliases are not set or empty. #[serde(rename = "m.heroes", default, skip_serializing_if = "Vec::is_empty")] pub heroes: Vec, + /// Number of users whose membership status is `join`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. @@ -232,6 +258,7 @@ pub struct RoomSummary { skip_serializing_if = "Option::is_none" )] pub joined_member_count: Option, + /// Number of users whose membership status is `invite`. /// Required if field has changed since last sync; otherwise, it may be /// omitted. @@ -289,6 +316,7 @@ pub struct DeviceLists { /// share an encrypted room with the client since the previous sync #[serde(default, skip_serializing_if = "Vec::is_empty")] pub changed: Vec, + /// List of users who no longer share encrypted rooms since the previous sync /// response. #[serde(default, skip_serializing_if = "Vec::is_empty")] diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index 99a3566f..91f890e2 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -18,12 +18,16 @@ use serde::{Deserialize, Serialize}; pub struct Protocol { /// Fields which may be used to identify a third party user. pub user_fields: Vec, + /// Fields which may be used to identify a third party location. pub location_fields: Vec, + /// A content URI representing an icon for the third party protocol. pub icon: String, + /// The type definitions for the fields defined in `user_fields` and `location_fields`. pub field_types: BTreeMap, + /// A list of objects representing independent instances of configuration. pub instances: Vec, } @@ -33,11 +37,14 @@ pub struct Protocol { pub struct ProtocolInstance { /// A human-readable description for the protocol, such as the name. pub desc: String, + /// An optional content URI representing the protocol. #[serde(skip_serializing_if = "Option::is_none")] pub icon: Option, + /// Preset values for `fields` the client may use to search by. pub fields: BTreeMap, + /// A unique identifier across all instances. pub network_id: String, } @@ -47,6 +54,7 @@ pub struct ProtocolInstance { pub struct FieldType { /// A regular expression for validation of a field's value. pub regexp: String, + /// A placeholder serving as a valid example of the field value. pub placeholder: String, } @@ -56,8 +64,10 @@ pub struct FieldType { pub struct Location { /// An alias for a matrix room. pub alias: RoomAliasId, + /// The protocol ID that the third party location is a part of. pub protocol: String, + /// Information used to identify this third party location. pub fields: BTreeMap, } @@ -67,8 +77,10 @@ pub struct Location { pub struct User { /// A matrix user ID representing a third party user. pub userid: UserId, + /// The protocol ID that the third party user is a part of. pub protocol: String, + /// Information used to identify this third party user. pub fields: BTreeMap, } @@ -79,6 +91,7 @@ pub struct User { pub enum Medium { /// Email address identifier Email, + /// Phone number identifier MSISDN, } diff --git a/src/r0/thirdparty/get_location_for_protocol.rs b/src/r0/thirdparty/get_location_for_protocol.rs index e0c30b17..d3aab76d 100644 --- a/src/r0/thirdparty/get_location_for_protocol.rs +++ b/src/r0/thirdparty/get_location_for_protocol.rs @@ -20,6 +20,7 @@ ruma_api! { /// The protocol used to communicate to the third party network. #[ruma_api(path)] pub protocol: String, + /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] diff --git a/src/r0/thirdparty/get_user_for_protocol.rs b/src/r0/thirdparty/get_user_for_protocol.rs index ab9c74a1..424c4c82 100644 --- a/src/r0/thirdparty/get_user_for_protocol.rs +++ b/src/r0/thirdparty/get_user_for_protocol.rs @@ -20,6 +20,7 @@ ruma_api! { /// The protocol used to communicate to the third party network. #[ruma_api(path)] pub protocol: String, + /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352. #[ruma_api(query_map)] diff --git a/src/r0/to_device.rs b/src/r0/to_device.rs index 6e68ce68..f75176d8 100644 --- a/src/r0/to_device.rs +++ b/src/r0/to_device.rs @@ -18,6 +18,7 @@ pub mod send_event_to_device; pub enum DeviceIdOrAllDevices { /// Represents a device Id for one of a user's devices. DeviceId(DeviceId), + /// Represents all devices for a user. AllDevices, } diff --git a/src/r0/to_device/send_event_to_device.rs b/src/r0/to_device/send_event_to_device.rs index f31e9eff..a0187ad7 100644 --- a/src/r0/to_device/send_event_to_device.rs +++ b/src/r0/to_device/send_event_to_device.rs @@ -22,9 +22,11 @@ ruma_api! { /// Type of event being sent to each device. #[ruma_api(path)] pub event_type: EventType, + /// A request identifier unique to the access token used to send the request. #[ruma_api(path)] pub txn_id: String, + /// A map of users to devices to a message event to be sent to the user's /// device. Individual message events can be sent to devices, but all /// events must be of the same type. diff --git a/src/r0/uiaa.rs b/src/r0/uiaa.rs index 14b7a97a..273317bf 100644 --- a/src/r0/uiaa.rs +++ b/src/r0/uiaa.rs @@ -22,13 +22,16 @@ pub enum AuthData { /// The login type that the client is attempting to complete. #[serde(rename = "type")] kind: String, + /// The value of the session key given by the homeserver. #[serde(skip_serializing_if = "Option::is_none")] session: Option, + /// Parameters submitted for a particular authentication stage. #[serde(flatten)] auth_parameters: BTreeMap, }, + /// Used by the client to acknowledge that the user has completed a UIAA /// stage through the fallback method. FallbackAcknowledgement { @@ -44,14 +47,18 @@ pub enum AuthData { pub struct UiaaInfo { /// List of authentication flows available for this endpoint. pub flows: Vec, + /// List of stages in the current flow completed by the client. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub completed: Vec, + /// Authentication parameters required for the client to complete authentication. pub params: JsonValue, + /// Session key for client to use to complete authentication. #[serde(skip_serializing_if = "Option::is_none")] pub session: Option, + /// Authentication-related errors for previous request returned by homeserver. #[serde(flatten, skip_serializing_if = "Option::is_none")] pub auth_error: Option, @@ -73,6 +80,7 @@ pub struct AuthFlow { pub enum UiaaResponse { /// User-Interactive Authentication API response AuthResponse(UiaaInfo), + /// Matrix error response MatrixError(MatrixError), } diff --git a/src/r0/user_directory/search_users.rs b/src/r0/user_directory/search_users.rs index a0b54cee..998488cd 100644 --- a/src/r0/user_directory/search_users.rs +++ b/src/r0/user_directory/search_users.rs @@ -18,6 +18,7 @@ ruma_api! { request { /// The term to search for. pub search_term: String, + /// The maximum number of results to return. /// /// Defaults to 10. @@ -28,6 +29,7 @@ ruma_api! { 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, } @@ -40,9 +42,11 @@ ruma_api! { 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, diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 874c334a..9e6e466d 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -19,6 +19,7 @@ ruma_api! { response { /// A list of Matrix client API protocol versions supported by the homeserver. pub versions: Vec, + /// Experimental features supported by the server. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub unstable_features: BTreeMap From 56f2054df58d7f242b713ec2eb8fc769bf7de713 Mon Sep 17 00:00:00 2001 From: poljar Date: Tue, 5 May 2020 11:55:41 +0200 Subject: [PATCH 312/350] to_device: Use a RawValue for sending to-device messages --- src/r0/to_device/send_event_to_device.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/r0/to_device/send_event_to_device.rs b/src/r0/to_device/send_event_to_device.rs index a0187ad7..f84a33ab 100644 --- a/src/r0/to_device/send_event_to_device.rs +++ b/src/r0/to_device/send_event_to_device.rs @@ -3,8 +3,9 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; +use ruma_events::EventType; use ruma_identifiers::UserId; +use serde_json::value::RawValue as RawJsonValue; use super::DeviceIdOrAllDevices; @@ -27,10 +28,13 @@ ruma_api! { #[ruma_api(path)] pub txn_id: String, - /// A map of users to devices to a message event to be sent to the user's - /// device. Individual message events can be sent to devices, but all - /// events must be of the same type. - pub messages: BTreeMap>> + /// A map of users to devices to a content for a message event to be + /// sent to the user's device. Individual message events can be sent + /// to devices, but all events must be of the same type. + /// The content's type for this field will be updated in a future + /// release, until then you can create a value using + /// `serde_json::value::to_raw_value`. + pub messages: BTreeMap>> } response {} From 5cedf1a96302c1542a640bc3980536bb87abfd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 5 May 2020 13:50:48 +0200 Subject: [PATCH 313/350] keys: Make the device display name optional. --- src/r0/keys.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 0d53dea5..73f3eb25 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -134,7 +134,7 @@ pub struct DeviceKeys { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UnsignedDeviceInfo { /// The display name which the user set on the device. - pub device_display_name: String, + pub device_display_name: Option, } /// A key for the SignedCurve25519 algorithm From 7d80a7f23dbd22b709b1dd859decfd17a881f140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 5 May 2020 14:26:26 +0200 Subject: [PATCH 314/350] sync_events: Make all fields in the response optional except next_batch. As per spec only the next_batch token is required in a sync response. This patch makes all of them optional and creates default values when parsing a response. Serialization is skipped for all of them if they are empty containers. --- src/r0/sync/sync_events.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 489191ae..7c6a4ed5 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -68,12 +68,15 @@ ruma_api! { pub next_batch: String, /// Updates to rooms. + #[serde(default, skip_serializing_if = "Rooms::is_empty")] pub rooms: Rooms, /// Updates to the presence status of other users. + #[serde(default, skip_serializing_if = "Presence::is_empty")] pub presence: Presence, /// The global private data created by this user. + #[serde(default, skip_serializing_if = "AccountData::is_empty")] pub account_data: AccountData, /// Messages sent dirrectly between devices. @@ -139,7 +142,7 @@ pub enum Filter { } /// Updates to rooms. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Rooms { /// The rooms that the user has left or been banned from. pub leave: BTreeMap, @@ -151,6 +154,12 @@ pub struct Rooms { pub invite: BTreeMap, } +impl Rooms { + fn is_empty(&self) -> bool { + self.leave.is_empty() && self.join.is_empty() && self.invite.is_empty() + } +} + /// Historical updates to left rooms. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct LeftRoom { @@ -229,12 +238,18 @@ pub struct State { } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct AccountData { /// A list of events. pub events: Vec>, } +impl AccountData { + fn is_empty(&self) -> bool { + self.events.is_empty() + } +} + /// Ephemeral events not recorded in the timeline or state of the room. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Ephemeral { @@ -284,14 +299,20 @@ pub struct InviteState { } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Presence { /// A list of events. pub events: Vec>, } +impl Presence { + fn is_empty(&self) -> bool { + self.events.is_empty() + } +} + /// Messages sent dirrectly between devices. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct ToDevice { /// A list of to-device events. pub events: Vec>, @@ -303,12 +324,6 @@ impl ToDevice { } } -impl Default for ToDevice { - fn default() -> Self { - Self { events: Vec::new() } - } -} - /// Information on E2E device udpates. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DeviceLists { From b10e5e9ed1b8c51a58a8f5bf70b0ddf816430c5b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 22:51:16 +0200 Subject: [PATCH 315/350] Add get_media_preview module declaration --- src/r0/media.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r0/media.rs b/src/r0/media.rs index 8eb4184c..91064a52 100644 --- a/src/r0/media.rs +++ b/src/r0/media.rs @@ -5,3 +5,4 @@ pub mod get_content; pub mod get_content_as_filename; pub mod get_content_thumbnail; pub mod get_media_config; +pub mod get_media_preview; From 2bb96b5a2b030139f0c1503a5ceb056d5921304e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 22:51:46 +0200 Subject: [PATCH 316/350] Use serde_json::value::RawValue instead of serde_json::Value in most endpoints --- Cargo.toml | 4 + src/r0/config/set_global_account_data.rs | 6 +- src/r0/config/set_room_account_data.rs | 6 +- src/r0/media/get_media_preview.rs | 38 ++- src/r0/room/create_room.rs | 6 +- .../state/get_state_events_for_empty_key.rs | 6 +- src/r0/state/get_state_events_for_key.rs | 4 +- src/r0/uiaa.rs | 264 ++++++++++-------- 8 files changed, 202 insertions(+), 132 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3502ef8..c0e19c4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,7 @@ ruma-serde = "0.1.3" serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.52" strum = { version = "0.18.0", features = ["derive"] } + +[dev-dependencies] +maplit = "1.0.2" +matches = "0.1.8" diff --git a/src/r0/config/set_global_account_data.rs b/src/r0/config/set_global_account_data.rs index 184f4cf1..9214271c 100644 --- a/src/r0/config/set_global_account_data.rs +++ b/src/r0/config/set_global_account_data.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::UserId; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -16,8 +16,10 @@ ruma_api! { request { /// Arbitrary JSON to store as config data. + /// + /// To create a `Box`, use `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub data: JsonValue, + pub data: Box, /// The event type of the account_data to set. /// diff --git a/src/r0/config/set_room_account_data.rs b/src/r0/config/set_room_account_data.rs index 26949547..457ee643 100644 --- a/src/r0/config/set_room_account_data.rs +++ b/src/r0/config/set_room_account_data.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -16,8 +16,10 @@ ruma_api! { request { /// Arbitrary JSON to store as config data. + /// + /// To create a `Box`, use `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub data: JsonValue, + pub data: Box, /// The event type of the account_data to set. /// diff --git a/src/r0/media/get_media_preview.rs b/src/r0/media/get_media_preview.rs index d387b142..ea96ccd6 100644 --- a/src/r0/media/get_media_preview.rs +++ b/src/r0/media/get_media_preview.rs @@ -3,7 +3,7 @@ use std::time::SystemTime; use ruma_api::ruma_api; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -32,8 +32,42 @@ ruma_api! { /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` /// field, and `og:image` returns the MXC URI to the image, if any. #[ruma_api(body)] - pub data: Option, + pub data: Option>, } error: crate::Error } + +#[cfg(test)] +mod tests { + use serde_json::{ + from_value as from_json_value, json, + value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue}, + }; + + // Since BTreeMap> deserialization doesn't seem to + // work, test that Option works + #[test] + fn raw_json_deserialize() { + type OptRawJson = Option>; + + assert!(from_json_value::(json!(null)) + .unwrap() + .is_none()); + assert!(from_json_value::(json!("test")) + .unwrap() + .is_some()); + assert!(from_json_value::(json!({ "a": "b" })) + .unwrap() + .is_some()); + } + + // For completeness sake, make sure serialization works too + #[test] + fn raw_json_serialize() { + assert!(to_raw_json_value(&json!(null)).is_ok()); + assert!(to_raw_json_value(&json!("string")).is_ok()); + assert!(to_raw_json_value(&json!({})).is_ok()); + assert!(to_raw_json_value(&json!({ "a": "b" })).is_ok()); + } +} diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 83b6c35f..b276a32f 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -4,7 +4,7 @@ use ruma_api::ruma_api; use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; use super::Visibility; use crate::r0::membership::Invite3pid; @@ -121,5 +121,7 @@ pub struct InitialStateEvent { pub state_key: Option, /// JSON content of the state event. - pub content: JsonValue, + /// + /// To create a `Box`, use `serde_json::value::to_raw_value`. + pub content: Box, } diff --git a/src/r0/state/get_state_events_for_empty_key.rs b/src/r0/state/get_state_events_for_empty_key.rs index 42320472..c9400be0 100644 --- a/src/r0/state/get_state_events_for_empty_key.rs +++ b/src/r0/state/get_state_events_for_empty_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -27,8 +27,10 @@ ruma_api! { response { /// The content of the state event. + /// + /// To create a `Box`, use `serde_json::value::to_raw_value`. #[ruma_api(body)] - pub content: JsonValue, + pub content: Box, } error: crate::Error diff --git a/src/r0/state/get_state_events_for_key.rs b/src/r0/state/get_state_events_for_key.rs index efd8c364..ad30024a 100644 --- a/src/r0/state/get_state_events_for_key.rs +++ b/src/r0/state/get_state_events_for_key.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_events::EventType; use ruma_identifiers::RoomId; -use serde_json::Value as JsonValue; +use serde_json::value::RawValue as RawJsonValue; ruma_api! { metadata { @@ -32,7 +32,7 @@ ruma_api! { response { /// The content of the state event. #[ruma_api(body)] - pub content: JsonValue, + pub content: Box, } error: crate::Error diff --git a/src/r0/uiaa.rs b/src/r0/uiaa.rs index 273317bf..73994d17 100644 --- a/src/r0/uiaa.rs +++ b/src/r0/uiaa.rs @@ -7,14 +7,16 @@ use std::{ use ruma_api::{error::ResponseDeserializationError, EndpointError}; use serde::{Deserialize, Serialize}; -use serde_json::{from_slice as from_json_slice, to_vec as to_json_vec, Value as JsonValue}; +use serde_json::{ + from_slice as from_json_slice, to_vec as to_json_vec, value::RawValue as RawJsonValue, + Value as JsonValue, +}; use crate::error::{Error as MatrixError, ErrorBody}; /// Additional authentication information for the user-interactive authentication API. #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(untagged)] -#[cfg_attr(test, derive(PartialEq))] pub enum AuthData { /// Used for sending UIAA authentication requests to the homeserver directly /// from the client. @@ -28,6 +30,7 @@ pub enum AuthData { session: Option, /// Parameters submitted for a particular authentication stage. + // FIXME: RawJsonValue doesn't work here, is that a bug? #[serde(flatten)] auth_parameters: BTreeMap, }, @@ -43,7 +46,6 @@ pub enum AuthData { /// Information about available authentication flows and status for /// User-Interactive Authenticiation API. #[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(test, derive(PartialEq))] pub struct UiaaInfo { /// List of authentication flows available for this endpoint. pub flows: Vec, @@ -52,8 +54,11 @@ pub struct UiaaInfo { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub completed: Vec, - /// Authentication parameters required for the client to complete authentication. - pub params: JsonValue, + /// Authentication parameters required for the client to complete + /// authentication. + /// + /// To create a `Box`, use `serde_json::value::to_raw_value`. + pub params: Box, /// Session key for client to use to complete authentication. #[serde(skip_serializing_if = "Option::is_none")] @@ -129,12 +134,13 @@ impl From for http::Response> { #[cfg(test)] mod tests { - use std::collections::BTreeMap; - + use maplit::btreemap; + use matches::assert_matches; use ruma_api::EndpointError; use serde_json::{ - from_slice as from_json_slice, from_value as from_json_value, json, - to_value as to_json_value, Value as JsonValue, + from_slice as from_json_slice, from_str as from_json_str, from_value as from_json_value, + json, to_value as to_json_value, value::to_raw_value as to_raw_json_value, + Value as JsonValue, }; use super::{AuthData, AuthFlow, UiaaInfo, UiaaResponse}; @@ -142,40 +148,40 @@ mod tests { #[test] fn test_serialize_authentication_data_direct_request() { - let mut auth_parameters = BTreeMap::new(); - auth_parameters.insert( - "example_credential".into(), - JsonValue::String("verypoorsharedsecret".into()), - ); let authentication_data = AuthData::DirectRequest { kind: "example.type.foo".to_string(), session: Some("ZXY000".to_string()), - auth_parameters, + auth_parameters: btreemap! { + "example_credential".to_owned() => json!("verypoorsharedsecret") + }, }; assert_eq!( - json!({ "type": "example.type.foo", "session": "ZXY000", "example_credential": "verypoorsharedsecret" }), + json!({ + "type": "example.type.foo", + "session": "ZXY000", + "example_credential": "verypoorsharedsecret", + }), to_json_value(authentication_data).unwrap() ); } #[test] fn test_deserialize_authentication_data_direct_request() { - let mut auth_parameters = BTreeMap::new(); - auth_parameters.insert( - "example_credential".into(), - JsonValue::String("verypoorsharedsecret".into()), - ); - let authentication_data = AuthData::DirectRequest { - kind: "example.type.foo".into(), - session: Some("opaque_session_id".to_string()), - auth_parameters, - }; - let json = json!({ "type": "example.type.foo", "session": "opaque_session_id", "example_credential": "verypoorsharedsecret", }); + let json = json!({ + "type": "example.type.foo", + "session": "opaque_session_id", + "example_credential": "verypoorsharedsecret", + }); - assert_eq!( + assert_matches!( from_json_value::(json).unwrap(), - authentication_data + AuthData::DirectRequest { kind, session: Some(session), auth_parameters } + if kind == "example.type.foo" + && session == "opaque_session_id" + && auth_parameters == btreemap!{ + "example_credential".to_owned() => json!("verypoorsharedsecret") + } ); } @@ -193,31 +199,28 @@ mod tests { #[test] fn test_deserialize_authentication_data_fallback() { - let authentication_data = AuthData::FallbackAcknowledgement { - session: "opaque_session_id".to_string(), - }; let json = json!({ "session": "opaque_session_id" }); - assert_eq!( + assert_matches!( from_json_value::(json).unwrap(), - authentication_data + AuthData::FallbackAcknowledgement { session } + if session == "opaque_session_id" ); } #[test] fn test_serialize_uiaa_info() { - let params = json!({ - "example.type.baz": { - "example_key": "foobar" - } - }); - let uiaa_info = UiaaInfo { flows: vec![AuthFlow { stages: vec!["m.login.password".to_string(), "m.login.dummy".to_string()], }], completed: vec!["m.login.password".to_string()], - params, + params: to_raw_json_value(&json!({ + "example.type.baz": { + "example_key": "foobar" + } + })) + .unwrap(), session: None, auth_error: None, }; @@ -239,13 +242,13 @@ mod tests { let json = json!({ "errcode": "M_FORBIDDEN", "error": "Invalid password", - "completed": [ "example.type.foo" ], + "completed": ["example.type.foo"], "flows": [ { - "stages": [ "example.type.foo", "example.type.bar" ] + "stages": ["example.type.foo", "example.type.bar"] }, { - "stages": [ "example.type.foo", "example.type.baz" ] + "stages": ["example.type.foo", "example.type.baz"] } ], "params": { @@ -256,59 +259,77 @@ mod tests { "session": "xxxxxx" }); - let uiaa_info = UiaaInfo { - auth_error: Some(ErrorBody { - kind: ErrorKind::Forbidden, - message: "Invalid password".to_string(), - }), - completed: vec!["example.type.foo".to_string()], - flows: vec![ - AuthFlow { - stages: vec![ - "example.type.foo".to_string(), - "example.type.bar".to_string(), - ], - }, - AuthFlow { - stages: vec![ - "example.type.foo".to_string(), - "example.type.baz".to_string(), - ], - }, - ], - params: json!({ - "example.type.baz": { - "example_key": "foobar" - } - }), - session: Some("xxxxxx".to_string()), - }; - assert_eq!(from_json_value::(json).unwrap(), uiaa_info); + assert_matches!( + from_json_value::(json).unwrap(), + UiaaInfo { + auth_error: Some(ErrorBody { + kind: ErrorKind::Forbidden, + message: error_message, + }), + completed, + flows, + params, + session: Some(session), + } if error_message == "Invalid password" + && completed == vec!["example.type.foo".to_string()] + && flows == vec![ + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.bar".to_string(), + ], + }, + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.baz".to_string(), + ], + }, + ] + && from_json_str::(params.get()).unwrap() == json!({ + "example.type.baz": { + "example_key": "foobar" + } + }) + && session == "xxxxxx" + ); } #[test] fn test_try_uiaa_response_into_http_response() { - let params = json!({ - "example.type.baz": { - "example_key": "foobar" - } - }); - let uiaa_info = UiaaInfo { flows: vec![AuthFlow { stages: vec!["m.login.password".to_string(), "m.login.dummy".to_string()], }], completed: vec!["m.login.password".to_string()], - params, + params: to_raw_json_value(&json!({ + "example.type.baz": { + "example_key": "foobar" + } + })) + .unwrap(), session: None, auth_error: None, }; - let uiaa_response: http::Response> = - UiaaResponse::AuthResponse(uiaa_info.clone()).into(); + let uiaa_response: http::Response> = UiaaResponse::AuthResponse(uiaa_info).into(); - assert_eq!( + assert_matches!( from_json_slice::(uiaa_response.body()).unwrap(), - uiaa_info, + UiaaInfo { + flows, + completed, + params, + session: None, + auth_error: None, + } if flows == vec![AuthFlow { + stages: vec!["m.login.password".to_string(), "m.login.dummy".to_string()], + }] + && completed == vec!["m.login.password".to_string()] + && from_json_str::(params.get()).unwrap() == json!({ + "example.type.baz": { + "example_key": "foobar" + } + }) ); assert_eq!( uiaa_response.status(), @@ -324,10 +345,10 @@ mod tests { "completed": [ "example.type.foo" ], "flows": [ { - "stages": [ "example.type.foo", "example.type.bar" ] + "stages": [ "example.type.foo", "example.type.bar" ] }, { - "stages": [ "example.type.foo", "example.type.baz" ] + "stages": [ "example.type.foo", "example.type.baz" ] } ], "params": { @@ -338,47 +359,50 @@ mod tests { "session": "xxxxxx" })) .unwrap(); + let http_response = http::Response::builder() .status(http::StatusCode::UNAUTHORIZED) .body(json.into()) .unwrap(); - let uiaa_info = UiaaInfo { - auth_error: Some(ErrorBody { - kind: ErrorKind::Forbidden, - message: "Invalid password".to_string(), - }), - completed: vec!["example.type.foo".to_string()], - flows: vec![ - AuthFlow { - stages: vec![ - "example.type.foo".to_string(), - "example.type.bar".to_string(), - ], - }, - AuthFlow { - stages: vec![ - "example.type.foo".to_string(), - "example.type.baz".to_string(), - ], - }, - ], - params: json!({ - "example.type.baz": { - "example_key": "foobar" - } - }), - session: Some("xxxxxx".to_string()), + let parsed_uiaa_info = match UiaaResponse::try_from_response(http_response).unwrap() { + UiaaResponse::AuthResponse(uiaa_info) => uiaa_info, + _ => panic!("Expected UiaaResponse::AuthResponse"), }; - let parsed_uiaa_info = match UiaaResponse::try_from_response(http_response) { - Ok(auth_response) => match auth_response { - UiaaResponse::AuthResponse(uiaa_info) => Some(uiaa_info), - _ => None, - }, - _ => None, - }; - - assert_eq!(parsed_uiaa_info, Some(uiaa_info)); + assert_matches!( + parsed_uiaa_info, + UiaaInfo { + auth_error: Some(ErrorBody { + kind: ErrorKind::Forbidden, + message: error_message, + }), + completed, + flows, + params, + session: Some(session), + } if error_message == "Invalid password" + && completed == vec!["example.type.foo".to_string()] + && flows == vec![ + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.bar".to_string(), + ], + }, + AuthFlow { + stages: vec![ + "example.type.foo".to_string(), + "example.type.baz".to_string(), + ], + }, + ] + && from_json_str::(params.get()).unwrap() == json!({ + "example.type.baz": { + "example_key": "foobar" + } + }) + && session == "xxxxxx" + ); } } From 55df111a97ba1060b1bf26b91d03797cdc03d9ef Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 23:10:29 +0200 Subject: [PATCH 317/350] Canonicalize spec links --- src/r0/account/deactivate.rs | 2 +- src/r0/account/request_password_change_token_via_email.rs | 2 +- src/r0/account/request_password_change_token_via_msisdn.rs | 2 +- src/r0/account/request_registration_token_via_msisdn.rs | 2 +- src/r0/media/get_content.rs | 2 +- src/r0/membership/invite_user.rs | 2 +- src/r0/room/create_room.rs | 2 +- src/unversioned/get_supported_versions.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/r0/account/deactivate.rs b/src/r0/account/deactivate.rs index 6a1a7fd7..a46b666a 100644 --- a/src/r0/account/deactivate.rs +++ b/src/r0/account/deactivate.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-deactivate) +//! [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-deactivate) use ruma_api::ruma_api; diff --git a/src/r0/account/request_password_change_token_via_email.rs b/src/r0/account/request_password_change_token_via_email.rs index 1fd70ae3..f796191f 100644 --- a/src/r0/account/request_password_change_token_via_email.rs +++ b/src/r0/account/request_password_change_token_via_email.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-email-requesttoken) +//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password-email-requesttoken) use js_int::UInt; use ruma_api::ruma_api; diff --git a/src/r0/account/request_password_change_token_via_msisdn.rs b/src/r0/account/request_password_change_token_via_msisdn.rs index 54b22a4b..7e14e2ad 100644 --- a/src/r0/account/request_password_change_token_via_msisdn.rs +++ b/src/r0/account/request_password_change_token_via_msisdn.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/account/password/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-msisdn-requesttoken) +//! [POST /_matrix/client/r0/account/password/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password-msisdn-requesttoken) use js_int::UInt; use ruma_api::ruma_api; diff --git a/src/r0/account/request_registration_token_via_msisdn.rs b/src/r0/account/request_registration_token_via_msisdn.rs index 89dac820..afe7e53b 100644 --- a/src/r0/account/request_registration_token_via_msisdn.rs +++ b/src/r0/account/request_registration_token_via_msisdn.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/register/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-register-msisdn-requesttoken) +//! [POST /_matrix/client/r0/register/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register-msisdn-requesttoken) use js_int::UInt; use ruma_api::ruma_api; diff --git a/src/r0/media/get_content.rs b/src/r0/media/get_content.rs index 97fe4eb0..94d625a4 100644 --- a/src/r0/media/get_content.rs +++ b/src/r0/media/get_content.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-media-r0-download-servername-mediaid) +//! [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-download-servername-mediaid) use ruma_api::ruma_api; diff --git a/src/r0/membership/invite_user.rs b/src/r0/membership/invite_user.rs index 1f4796f6..497da5d6 100644 --- a/src/r0/membership/invite_user.rs +++ b/src/r0/membership/invite_user.rs @@ -4,7 +4,7 @@ //! [by their Matrix identifier][invite-by-user-id], and one to invite a user //! [by their third party identifier][invite-by-3pid]. //! -//! [invite-by-user-id]: https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-rooms-roomid-invite +//! [invite-by-user-id]: https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-invite //! [invite-by-3pid]: https://matrix.org/docs/spec/client_server/r0.6.0#id101 use ruma_api::ruma_api; use ruma_identifiers::{RoomId, UserId}; diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index b276a32f..d905db50 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom) +//! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-createroom) use ruma_api::ruma_api; use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; diff --git a/src/unversioned/get_supported_versions.rs b/src/unversioned/get_supported_versions.rs index 9e6e466d..f248c17e 100644 --- a/src/unversioned/get_supported_versions.rs +++ b/src/unversioned/get_supported_versions.rs @@ -1,4 +1,4 @@ -//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-versions) +//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-versions) use std::collections::BTreeMap; From ecb498be673cedecfe26ae1af243deaf02004845 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 5 May 2020 23:10:58 +0200 Subject: [PATCH 318/350] Bump version --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a900df4f..240bcc3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [unreleased] +# 0.8.0 + Breaking changes: * Update all endpoints to r0.6.0 diff --git a/Cargo.toml b/Cargo.toml index c0e19c4b..81c3bbd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0-rc.6" +version = "0.8.0" edition = "2018" [dependencies] From e36e9a68acb7094e4e99b101a62c3dbe0e1ae4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 6 May 2020 09:54:43 +0200 Subject: [PATCH 319/350] message/state: The event id is required in the response when sending events. --- src/r0/message/create_message_event.rs | 2 +- src/r0/state/create_state_event_for_empty_key.rs | 2 +- src/r0/state/create_state_event_for_key.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index 850f5eaf..671265ac 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -41,7 +41,7 @@ ruma_api! { response { /// A unique identifier for the event. - pub event_id: Option, + pub event_id: EventId, } error: crate::Error diff --git a/src/r0/state/create_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs index c73543d8..6c5b980f 100644 --- a/src/r0/state/create_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -33,7 +33,7 @@ ruma_api! { response { /// A unique identifier for the event. - pub event_id: Option, + pub event_id: EventId, } error: crate::Error diff --git a/src/r0/state/create_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs index 0b3d1646..0754d72a 100644 --- a/src/r0/state/create_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -37,7 +37,7 @@ ruma_api! { response { /// A unique identifier for the event. - pub event_id: Option, + pub event_id: EventId, } error: crate::Error From 7a22bc7a45500d8d4eff4c6b21b5b64a69d22553 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 14:42:30 +0200 Subject: [PATCH 320/350] Add comments to explain required event_id fields --- src/r0/message/create_message_event.rs | 2 ++ src/r0/state/create_state_event_for_empty_key.rs | 2 ++ src/r0/state/create_state_event_for_key.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index 671265ac..2a7a31b5 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_message_event.rs @@ -41,6 +41,8 @@ ruma_api! { response { /// A unique identifier for the event. + // This is not declared required in r0.6.0, but that was a bug that has now been fixed: + // https://github.com/matrix-org/matrix-doc/pull/2525 pub event_id: EventId, } diff --git a/src/r0/state/create_state_event_for_empty_key.rs b/src/r0/state/create_state_event_for_empty_key.rs index 6c5b980f..1fe4083a 100644 --- a/src/r0/state/create_state_event_for_empty_key.rs +++ b/src/r0/state/create_state_event_for_empty_key.rs @@ -33,6 +33,8 @@ ruma_api! { response { /// A unique identifier for the event. + // This is not declared required in r0.6.0, but that was a bug that has now been fixed: + // https://github.com/matrix-org/matrix-doc/pull/2525 pub event_id: EventId, } diff --git a/src/r0/state/create_state_event_for_key.rs b/src/r0/state/create_state_event_for_key.rs index 0754d72a..6f546666 100644 --- a/src/r0/state/create_state_event_for_key.rs +++ b/src/r0/state/create_state_event_for_key.rs @@ -37,6 +37,8 @@ ruma_api! { response { /// A unique identifier for the event. + // This is not declared required in r0.6.0, but that was a bug that has now been fixed: + // https://github.com/matrix-org/matrix-doc/pull/2525 pub event_id: EventId, } From c28645b945bcd35bcc133d36c9d948ea7bf39e2c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 7 May 2020 14:43:29 +0200 Subject: [PATCH 321/350] Update change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 240bcc3e..a2961d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # [unreleased] +Breaking changes: + +* The `event_id` in the response for the message and state sending endpoints is now required + * r0.6.0 doesn't say they are required, but this has been fixed for the next version of the spec + # 0.8.0 Breaking changes: From 62bf717e62a10994603d6ce57f33adafcc80f22b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 10 May 2020 11:24:30 +0200 Subject: [PATCH 322/350] Update sync_events tests --- src/r0/sync/sync_events.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 7c6a4ed5..e90c6fd2 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -342,10 +342,12 @@ pub struct DeviceLists { mod tests { use std::{convert::TryInto, time::Duration}; + use matches::assert_matches; + use super::{Filter, Request, SetPresence}; #[test] - fn serialize_sync_request() { + fn serialize_all_params() { let req: http::Request> = Request { filter: Some(Filter::FilterId("66696p746572".into())), since: Some("s72594_4483_1934".into()), @@ -368,11 +370,18 @@ mod tests { } #[test] - fn deserialize_sync_request_with_query_params() { + fn deserialize_all_query_params() { let uri = http::Uri::builder() .scheme("https") .authority("matrix.org") - .path_and_query("/_matrix/client/r0/sync?filter=myfilter&since=myts&full_state=false&set_presence=offline&timeout=5000") + .path_and_query( + "/_matrix/client/r0/sync\ + ?filter=myfilter\ + &since=myts\ + &full_state=false\ + &set_presence=offline\ + &timeout=5000", + ) .build() .unwrap(); @@ -383,12 +392,7 @@ mod tests { .try_into() .unwrap(); - match req.filter { - Some(Filter::FilterId(id)) if id == "myfilter" => {} - _ => { - panic!("Not the expected filter ID."); - } - } + assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "myfilter"); assert_eq!(req.since, Some("myts".into())); assert_eq!(req.full_state, false); assert_eq!(req.set_presence, SetPresence::Offline); @@ -396,7 +400,7 @@ mod tests { } #[test] - fn deserialize_sync_request_without_query_params() { + fn deserialize_no_query_params() { let uri = http::Uri::builder() .scheme("https") .authority("matrix.org") @@ -411,10 +415,10 @@ mod tests { .try_into() .unwrap(); - assert!(req.filter.is_none()); - assert!(req.since.is_none()); + assert_matches!(req.filter, None); + assert_eq!(req.since, None); assert_eq!(req.full_state, false); assert_eq!(req.set_presence, SetPresence::Online); - assert!(req.timeout.is_none()); + assert_eq!(req.timeout, None); } } From 519ab3ff0af402c1f0f4d75ed1aac3cf88cc31f7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 17 May 2020 18:50:32 +0200 Subject: [PATCH 323/350] Implement Display for r0::keys::AlgorithmAndDeviceId --- CHANGELOG.md | 4 ++++ src/r0/keys.rs | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2961d37..923414b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ Breaking changes: * The `event_id` in the response for the message and state sending endpoints is now required * r0.6.0 doesn't say they are required, but this has been fixed for the next version of the spec +Improvements: + +* `r0::keys::AlgorithmAndDeviceId` now implements `Display` + # 0.8.0 Breaking changes: diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 73f3eb25..21a40267 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -3,7 +3,7 @@ use std::{ collections::BTreeMap, convert::TryFrom, - fmt::{Debug, Display, Error as FmtError, Formatter}, + fmt::{self, Debug, Display, Formatter}, }; use ruma_events::Algorithm; @@ -35,7 +35,7 @@ pub enum KeyAlgorithm { } impl Display for KeyAlgorithm { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let algorithm_str = match *self { KeyAlgorithm::Ed25519 => "ed25519", KeyAlgorithm::Curve25519 => "curve25519", @@ -62,13 +62,18 @@ impl TryFrom<&'_ str> for KeyAlgorithm { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub DeviceId); +impl Display for AlgorithmAndDeviceId { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{}:{}", self.0, self.1) + } +} + impl Serialize for AlgorithmAndDeviceId { fn serialize(&self, serializer: S) -> Result where S: Serializer, { - let s = format!("{}:{}", self.0, self.1); - serializer.serialize_str(&s) + serializer.serialize_str(&self.to_string()) } } From 89dcb5710b9e7d87fed8af89080fcf6f6449d90f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 10 May 2020 12:13:31 +0200 Subject: [PATCH 324/350] Add another test for sync_events request deserialization --- src/r0/sync/sync_events.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index e90c6fd2..bb02b62e 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -421,4 +421,31 @@ mod tests { assert_eq!(req.set_presence, SetPresence::Online); assert_eq!(req.timeout, None); } + + #[test] + fn deserialize_some_query_params() { + let uri = http::Uri::builder() + .scheme("https") + .authority("matrix.org") + .path_and_query( + "/_matrix/client/r0/sync\ + ?filter=EOKFFmdZYF\ + &timeout=0", + ) + .build() + .unwrap(); + + let req: Request = http::Request::builder() + .uri(uri) + .body(Vec::::new()) + .unwrap() + .try_into() + .unwrap(); + + assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "EOKFFmdZYF"); + assert_eq!(req.since, None); + assert_eq!(req.full_state, false); + assert_eq!(req.set_presence, SetPresence::Online); + assert_eq!(req.timeout, Some(Duration::from_millis(0))); + } } From a42b335bfea6cf65a70c92d89572391f2b8e1aa1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 19 May 2020 12:37:03 +0200 Subject: [PATCH 325/350] Update dependencies --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81c3bbd0..4b7827f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,13 +15,13 @@ edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.5", features = ["serde"] } -ruma-api = "0.16.0" -ruma-common = "0.1.1" -ruma-events = "0.21.0" +ruma-api = "0.16.1" +ruma-common = "0.1.2" +ruma-events = "0.21.2" ruma-identifiers = "0.16.1" -ruma-serde = "0.1.3" -serde = { version = "1.0.106", features = ["derive"] } -serde_json = "1.0.52" +ruma-serde = "0.2.1" +serde = { version = "1.0.110", features = ["derive"] } +serde_json = "1.0.53" strum = { version = "0.18.0", features = ["derive"] } [dev-dependencies] From 3a3ccabbf22c34da5c9de7cac54d9fbd3e571dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Tue, 19 May 2020 18:45:38 +0200 Subject: [PATCH 326/350] Fix get_content_thumbnail response --- src/r0/media/get_content_thumbnail.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/media/get_content_thumbnail.rs b/src/r0/media/get_content_thumbnail.rs index 54b5ef40..ad73e327 100644 --- a/src/r0/media/get_content_thumbnail.rs +++ b/src/r0/media/get_content_thumbnail.rs @@ -63,7 +63,7 @@ ruma_api! { pub content_type: String, /// A thumbnail of the requested content. - #[ruma_api(body)] + #[ruma_api(raw_body)] pub file: Vec, } From 6d93ec1d1ad8537a9a5a0c4dcdfae1e30888f189 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 21 May 2020 23:29:44 +0200 Subject: [PATCH 327/350] Fix accidentally-private field --- CHANGELOG.md | 4 ++++ src/r0/device/get_devices.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 923414b9..6ae2dc3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Bug fixes: + +* Make `r0::device::get_devices::Response::devices` public + Breaking changes: * The `event_id` in the response for the message and state sending endpoints is now required diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs index b9f8d474..acfe4fce 100644 --- a/src/r0/device/get_devices.rs +++ b/src/r0/device/get_devices.rs @@ -16,7 +16,7 @@ ruma_api! { request {} response { - devices: Vec, + pub devices: Vec, } error: crate::Error From b5fa684dfce969f78f37905215abfb31db65fdab Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 21 May 2020 23:36:07 +0200 Subject: [PATCH 328/350] Update sync_events::DeviceLists field types --- CHANGELOG.md | 1 + src/r0/sync/sync_events.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ae2dc3d..4c7b61d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Breaking changes: * The `event_id` in the response for the message and state sending endpoints is now required * r0.6.0 doesn't say they are required, but this has been fixed for the next version of the spec +* Updated the type of `r0::sync::sync_events::DeviceLists` fields Improvements: diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index bb02b62e..2a6c4828 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -330,12 +330,12 @@ pub struct DeviceLists { /// List of users who have updated their device identity keys or who now /// share an encrypted room with the client since the previous sync #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub changed: Vec, + pub changed: Vec, /// List of users who no longer share encrypted rooms since the previous sync /// response. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub left: Vec, + pub left: Vec, } #[cfg(test)] From 195bff8c05e8e3a9ee58353c0a5d6f05cd7cd994 Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Fri, 22 May 2020 14:55:54 +0200 Subject: [PATCH 329/350] Fix build - Add required documentation to `devices` field - Import `UserId` on `sync_events` --- src/r0/device/get_devices.rs | 1 + src/r0/sync/sync_events.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs index acfe4fce..0e6fef51 100644 --- a/src/r0/device/get_devices.rs +++ b/src/r0/device/get_devices.rs @@ -16,6 +16,7 @@ ruma_api! { request {} response { + /// A list of all registered devices for this user pub devices: Vec, } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 2a6c4828..a253698c 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -14,7 +14,7 @@ use ruma_events::{ to_device::AnyToDeviceEvent, EventJson, }; -use ruma_identifiers::RoomId; +use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; use crate::r0::{filter::FilterDefinition, keys::KeyAlgorithm}; From fe80737c5882dbea485b87ae9c365ae22c8ab58b Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Fri, 22 May 2020 15:17:28 +0200 Subject: [PATCH 330/350] Change Device fields according to the spec Fields `ip` and `last_seen` should be named `last_seen_ip` and `last_seen_ts` according to the spec. https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices --- src/r0/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/device.rs b/src/r0/device.rs index 0c22c151..685dab81 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -21,7 +21,7 @@ pub struct Device { pub display_name: Option, /// Most recently seen IP address of the session. - pub ip: Option, + pub last_seen_ip: Option, /// Unix timestamp that the session was last active. #[serde( @@ -29,5 +29,5 @@ pub struct Device { default, skip_serializing_if = "Option::is_none" )] - pub last_seen: Option, + pub last_seen_ts: Option, } From 866885bb3894898c2458228d6a8fb738654004dc Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Fri, 22 May 2020 15:59:54 +0200 Subject: [PATCH 331/350] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7b61d3..19ce76e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bug fixes: * Make `r0::device::get_devices::Response::devices` public +* Change `r0::device::Device` fields according to the spec Breaking changes: From fa8a45ed9ff0e0de6d90d67de0712b45106e589e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 22 May 2020 17:59:12 +0200 Subject: [PATCH 332/350] Update changelog, bump version --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ce76e3..20208d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # [unreleased] +# 0.9.0 + Bug fixes: +* Fix (de)serialization for `r0::media::get_content_thumnail::Response` * Make `r0::device::get_devices::Response::devices` public * Change `r0::device::Device` fields according to the spec diff --git a/Cargo.toml b/Cargo.toml index 4b7827f8..d46bfa39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "ruma-client-api" readme = "README.md" repository = "https://github.com/ruma/ruma-client-api" -version = "0.8.0" +version = "0.9.0" edition = "2018" [dependencies] From 9e198132d0f60bf0850a2c745e04118a5347c3c1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 24 May 2020 15:53:23 +0200 Subject: [PATCH 333/350] Make avatar_url in set_avatar_url request optional --- CHANGELOG.md | 6 +++++- src/r0/profile/set_avatar_url.rs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20208d1e..2ef69f61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,22 @@ # [unreleased] +Breaking changes: + +* Make `avatar_url` in `r0::profile::set_avatar_url::Request` an `Option` + # 0.9.0 Bug fixes: * Fix (de)serialization for `r0::media::get_content_thumnail::Response` * Make `r0::device::get_devices::Response::devices` public -* Change `r0::device::Device` fields according to the spec Breaking changes: * The `event_id` in the response for the message and state sending endpoints is now required * r0.6.0 doesn't say they are required, but this has been fixed for the next version of the spec * Updated the type of `r0::sync::sync_events::DeviceLists` fields +* Change `r0::device::Device` fields according to the spec Improvements: diff --git a/src/r0/profile/set_avatar_url.rs b/src/r0/profile/set_avatar_url.rs index b48c4a2e..b6d6064e 100644 --- a/src/r0/profile/set_avatar_url.rs +++ b/src/r0/profile/set_avatar_url.rs @@ -19,7 +19,9 @@ ruma_api! { pub user_id: UserId, /// The new avatar URL for the user. - pub avatar_url: String, + /// + /// `None` is used to unset the avatar. + pub avatar_url: Option, } response {} From 07689ecb8b1c68090250163d2d6a8c0da36dc1e8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 24 May 2020 15:54:22 +0200 Subject: [PATCH 334/350] Use event_type enum in r0::room::create_room::InitialStateEvent --- src/r0/room/create_room.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index d905db50..4bf85537 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-createroom) use ruma_api::ruma_api; -use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; +use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson, EventType}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; @@ -114,8 +114,9 @@ pub enum RoomPreset { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InitialStateEvent { /// State event type. + // FIXME: This should really only be a subset of the EventType enum. #[serde(rename = "type")] - pub event_type: String, + pub event_type: EventType, /// `state_key` of the event to be sent. pub state_key: Option, From 9643dbc27f548a7d90b62aab0df65f31dda1b57b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 26 May 2020 09:54:25 +0200 Subject: [PATCH 335/350] Update type of canonical_alias in PublicRoomsChunk --- CHANGELOG.md | 2 ++ src/r0/directory.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef69f61..fb5d7f97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Breaking changes: * Make `avatar_url` in `r0::profile::set_avatar_url::Request` an `Option` +* Update type of `canonical_alias` in `r0::directory::PublicRoomsChunk` from + `Option` to `Option` # 0.9.0 diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 9e8a1099..16a3664e 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -16,7 +16,7 @@ pub struct PublicRoomsChunk { /// The canonical alias of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] - pub canonical_alias: Option, + pub canonical_alias: Option, /// The name of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] From 429e5a5bbeab53755c0b8e462cf650454308a07e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 26 May 2020 10:12:23 +0200 Subject: [PATCH 336/350] Update create_room::CreationContent --- CHANGELOG.md | 7 ++++++ src/r0/room/create_room.rs | 46 +++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb5d7f97..e8b3ad5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ Breaking changes: * Make `avatar_url` in `r0::profile::set_avatar_url::Request` an `Option` * Update type of `canonical_alias` in `r0::directory::PublicRoomsChunk` from `Option` to `Option` +* Update `r0::room::create_room::CreationContent` + * Change `federated`s type from `Option` to `bool` + * Add `predecessor` field + +Improvements: + +* Add method `into_event_content` for `r0::room::create_room::CreationContent` # 0.9.0 diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 4bf85537..f69cb0bb 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,8 +1,14 @@ //! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-createroom) use ruma_api::ruma_api; -use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson, EventType}; -use ruma_identifiers::{RoomId, UserId}; +use ruma_events::{ + room::{ + create::{CreateEventContent, PreviousRoom}, + power_levels::PowerLevelsEventContent, + }, + EventJson, EventType, +}; +use ruma_identifiers::{RoomId, RoomVersionId, UserId}; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; @@ -87,13 +93,43 @@ ruma_api! { } /// Extra options to be added to the `m.room.create` event. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +/// +/// This is the same as the event content struct for `m.room.create`, but without some fields that +/// servers are supposed to ignore. +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreationContent { /// Whether users on other servers can join this room. /// /// Defaults to `true` if key does not exist. - #[serde(rename = "m.federate", skip_serializing_if = "Option::is_none")] - pub federate: Option, + #[serde( + rename = "m.federate", + default = "ruma_serde::default_true", + skip_serializing_if = "ruma_serde::is_true" + )] + pub federate: bool, + /// A reference to the room this room replaces, if the previous room was upgraded. + #[serde(skip_serializing_if = "Option::is_none")] + pub predecessor: Option, +} + +impl CreationContent { + /// Given a `CreationContent` and the other fields that a homeserver has to fill, construct + /// a `CreateEventContent`. + pub fn into_event_content( + Self { + federate, + predecessor, + }: Self, + creator: UserId, + room_version: RoomVersionId, + ) -> CreateEventContent { + CreateEventContent { + creator, + federate, + room_version, + predecessor, + } + } } /// A convenience parameter for setting a few default state events. From b064daf23dbf970933e83ce3b84a2563c5e646e7 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Tue, 26 May 2020 07:19:10 -0500 Subject: [PATCH 337/350] Add room visibility endpoints --- CHANGELOG.md | 1 + src/r0/directory.rs | 2 ++ src/r0/directory/get_room_visibility.rs | 29 +++++++++++++++++++++++++ src/r0/directory/set_room_visibility.rs | 29 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 src/r0/directory/get_room_visibility.rs create mode 100644 src/r0/directory/set_room_visibility.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b3ad5e..20961308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Breaking changes: Improvements: * Add method `into_event_content` for `r0::room::create_room::CreationContent` +* Add room visibility endpoints: `r0::directory::{get_room_visibility, set_room_visibility}`. # 0.9.0 diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 16a3664e..e6ae3669 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -2,6 +2,8 @@ pub mod get_public_rooms; pub mod get_public_rooms_filtered; +pub mod get_room_visibility; +pub mod set_room_visibility; use js_int::UInt; use ruma_identifiers::{RoomAliasId, RoomId}; diff --git a/src/r0/directory/get_room_visibility.rs b/src/r0/directory/get_room_visibility.rs new file mode 100644 index 00000000..19ba1c4e --- /dev/null +++ b/src/r0/directory/get_room_visibility.rs @@ -0,0 +1,29 @@ +//! [GET /_matrix/client/r0/directory/list/room/{roomId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-directory-list-room-roomid) + +use ruma_api::ruma_api; + +use crate::r0::room::Visibility; + +ruma_api! { + metadata { + description: "Get the visibility of a public room on a directory.", + name: "get_room_visibility", + method: GET, + path: "/_matrix/client/r0/directory/list/room/:room_id", + rate_limited: false, + requires_authentication: false, + } + + request { + /// The ID of the room of which to request the visibility. + #[ruma_api(path)] + pub room_id: String, + } + + response { + /// Visibility of the room. + pub visibility: Visibility, + } + + error: crate::Error +} diff --git a/src/r0/directory/set_room_visibility.rs b/src/r0/directory/set_room_visibility.rs new file mode 100644 index 00000000..a8d3ad35 --- /dev/null +++ b/src/r0/directory/set_room_visibility.rs @@ -0,0 +1,29 @@ +//! [PUT /_matrix/client/r0/directory/list/room/{roomId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-directory-list-room-roomid) + +use ruma_api::ruma_api; + +use crate::r0::room::Visibility; + +ruma_api! { + metadata { + description: "Set the visibility of a public room on a directory.", + name: "set_room_visibility", + method: PUT, + path: "/_matrix/client/r0/directory/list/room/:room_id", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The ID of the room of which to set the visibility. + #[ruma_api(path)] + pub room_id: String, + + /// New visibility setting for the room. + pub visibility: Visibility, + } + + response {} + + error: crate::Error +} From c725288cd099690c1d13f1a9b9e57228bc860a62 Mon Sep 17 00:00:00 2001 From: iinuwa Date: Wed, 27 May 2020 06:53:28 -0500 Subject: [PATCH 338/350] Use RoomId instead of String for room visibility endpoints --- src/r0/directory/get_room_visibility.rs | 3 ++- src/r0/directory/set_room_visibility.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/r0/directory/get_room_visibility.rs b/src/r0/directory/get_room_visibility.rs index 19ba1c4e..5ab16326 100644 --- a/src/r0/directory/get_room_visibility.rs +++ b/src/r0/directory/get_room_visibility.rs @@ -1,6 +1,7 @@ //! [GET /_matrix/client/r0/directory/list/room/{roomId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-directory-list-room-roomid) use ruma_api::ruma_api; +use ruma_identifiers::RoomId; use crate::r0::room::Visibility; @@ -17,7 +18,7 @@ ruma_api! { request { /// The ID of the room of which to request the visibility. #[ruma_api(path)] - pub room_id: String, + pub room_id: RoomId, } response { diff --git a/src/r0/directory/set_room_visibility.rs b/src/r0/directory/set_room_visibility.rs index a8d3ad35..dc04c5cd 100644 --- a/src/r0/directory/set_room_visibility.rs +++ b/src/r0/directory/set_room_visibility.rs @@ -1,6 +1,7 @@ //! [PUT /_matrix/client/r0/directory/list/room/{roomId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-directory-list-room-roomid) use ruma_api::ruma_api; +use ruma_identifiers::RoomId; use crate::r0::room::Visibility; @@ -17,7 +18,7 @@ ruma_api! { request { /// The ID of the room of which to set the visibility. #[ruma_api(path)] - pub room_id: String, + pub room_id: RoomId, /// New visibility setting for the room. pub visibility: Visibility, From 80726d054696bca7879a563124a43b14af5828ca Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 31 May 2020 23:16:15 +0200 Subject: [PATCH 339/350] Use PushCondition from ruma_events instead of declaring a separate one --- src/r0/push.rs | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/r0/push.rs b/src/r0/push.rs index 19d310dd..e967b852 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -19,6 +19,7 @@ pub mod set_pushrule_actions; pub mod set_pushrule_enabled; pub use ruma_common::push::Action; +pub use ruma_events::push_rules::PushCondition; /// The kinds of push rules that are available #[derive( @@ -76,39 +77,6 @@ pub struct PushRule { pub pattern: Option, } -/// A condition for a push rule -#[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(tag = "kind", rename_all = "snake_case")] // Using internally tagged enum representation to match the spec -pub enum PushCondition { - /// This is a glob pattern match on a field of the event. - EventMatch { - /// The dot-separated field of the event to match, e.g. `content.body` - key: String, - - /// The glob-style pattern to match against. - pattern: String, - }, - - /// This matches unencrypted messages where `content.body` contains - /// the owner's display name in that room. - ContainsDisplayName, - - /// This matches the current number of members in the room. - RoomMemberCount { - /// A decimal integer optionally prefixed by one of, ==, <, >, >= or <=. - /// Default prefix is ==. - is: String, - }, - - /// This takes into account the current power levels in the room, ensuring the - /// sender of the event has high enough power to trigger the notification. - SenderNotificationPermission { - /// A string that determines the power level the sender must have to - /// trigger notifications of a given type, such as `room`. - key: String, - }, -} - /// Defines a pusher #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Pusher { From da4abacf69142bf6aa5986ebf185a136a55888c7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 31 May 2020 23:18:22 +0200 Subject: [PATCH 340/350] Use Ruleset type from ruma_events in get_pushrules endpoints --- CHANGELOG.md | 2 ++ src/r0/push/get_pushrules_all.rs | 7 ++----- src/r0/push/get_pushrules_global_scope.rs | 7 ++----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20961308..cd472a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Breaking changes: * Update `r0::room::create_room::CreationContent` * Change `federated`s type from `Option` to `bool` * Add `predecessor` field +* Update `r0::push::get_pushrules_all` and `r0::push::get_pushrules_global_scope` to use the + `Ruleset` type from `ruma_events` Improvements: diff --git a/src/r0/push/get_pushrules_all.rs b/src/r0/push/get_pushrules_all.rs index ac08ddfe..cb6feaa4 100644 --- a/src/r0/push/get_pushrules_all.rs +++ b/src/r0/push/get_pushrules_all.rs @@ -1,10 +1,7 @@ //! [GET /_matrix/client/r0/pushrules/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::BTreeMap; - use ruma_api::ruma_api; - -use super::{PushRule, RuleKind}; +use ruma_events::push_rules::Ruleset; ruma_api! { metadata { @@ -20,7 +17,7 @@ ruma_api! { response { /// The global ruleset - pub global: BTreeMap> + pub global: Ruleset, } error: crate::Error diff --git a/src/r0/push/get_pushrules_global_scope.rs b/src/r0/push/get_pushrules_global_scope.rs index 5857e64e..eedcce43 100644 --- a/src/r0/push/get_pushrules_global_scope.rs +++ b/src/r0/push/get_pushrules_global_scope.rs @@ -1,10 +1,7 @@ //! [GET /_matrix/client/r0/pushrules/global/](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-pushrules) -use std::collections::BTreeMap; - use ruma_api::ruma_api; - -use super::{PushRule, RuleKind}; +use ruma_events::push_rules::Ruleset; ruma_api! { metadata { @@ -21,7 +18,7 @@ ruma_api! { response { /// The global ruleset. #[ruma_api(body)] - pub global: BTreeMap>, + pub global: Ruleset, } error: crate::Error From 584aab397921e49bdbca7612aa488c025949bd44 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 31 May 2020 23:31:18 +0200 Subject: [PATCH 341/350] Use ruma-events from git so people using this crate from git don't have breakage in r0::push --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d46bfa39..c6817483 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ http = "0.2.1" js_int = { version = "0.1.5", features = ["serde"] } ruma-api = "0.16.1" ruma-common = "0.1.2" -ruma-events = "0.21.2" +ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "7395f94" } ruma-identifiers = "0.16.1" ruma-serde = "0.2.1" serde = { version = "1.0.110", features = ["derive"] } From a892d7f65495efe674477bd9679e546fd6099b12 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 1 Jun 2020 01:19:56 +0200 Subject: [PATCH 342/350] Update dependencies --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c6817483..1ed9dd53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,9 @@ js_int = { version = "0.1.5", features = ["serde"] } ruma-api = "0.16.1" ruma-common = "0.1.2" ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "7395f94" } -ruma-identifiers = "0.16.1" -ruma-serde = "0.2.1" -serde = { version = "1.0.110", features = ["derive"] } +ruma-identifiers = "0.16.2" +ruma-serde = "0.2.2" +serde = { version = "1.0.111", features = ["derive"] } serde_json = "1.0.53" strum = { version = "0.18.0", features = ["derive"] } From b7bdb4aa52c87b2b48c40fca92db7eb4079548e1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 1 Jun 2020 01:21:06 +0200 Subject: [PATCH 343/350] Update get_capabilites endpoint --- src/r0/capabilities/get_capabilities.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs index 43f42ff0..b4f1e97a 100644 --- a/src/r0/capabilities/get_capabilities.rs +++ b/src/r0/capabilities/get_capabilities.rs @@ -1,6 +1,7 @@ -//! [GET /_matrix/client/r0/capabilities](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities) +//! [GET /_matrix/client/r0/capabilities](https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-capabilities) use ruma_api::ruma_api; +use ruma_identifiers::RoomVersionId; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; use std::collections::BTreeMap; @@ -56,17 +57,17 @@ pub struct RoomVersionsCapability { pub default: String, /// A detailed description of the room versions the server supports. - pub available: BTreeMap, + pub available: BTreeMap, } /// The stability of a room version #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum RoomVersionStability { - /// An unstable room version + /// Support for the given version is stable. #[serde(rename = "stable")] Stable, - /// A stable room version + /// Support for the given version is unstable. #[serde(rename = "unstable")] Unstable, } From 6fcdeac896edff659abe4ed32e45170e939034a1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 1 Jun 2020 01:35:28 +0200 Subject: [PATCH 344/350] Clarify search_users documentation based on the latest spec version --- src/r0/user_directory/search_users.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r0/user_directory/search_users.rs b/src/r0/user_directory/search_users.rs index 998488cd..96842259 100644 --- a/src/r0/user_directory/search_users.rs +++ b/src/r0/user_directory/search_users.rs @@ -1,4 +1,4 @@ -//! [POST /_matrix/client/r0/user_directory/search](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-user-directory-search) +//! [POST /_matrix/client/r0/user_directory/search](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-user-directory-search) use js_int::UInt; use ruma_api::ruma_api; @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; ruma_api! { metadata { - description: "Performs a search for users on the homeserver.", + description: "Performs a search for users.", method: POST, name: "search_users", path: "/_matrix/client/r0/user_directory/search", From 6214b3ac6e965c1c55db107c379078d199735e3d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 12:08:08 +0200 Subject: [PATCH 345/350] Fix event types in get_context --- src/r0/context/get_context.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index a02e9ce4..37c88d00 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::only, EventJson}; +use ruma_events::{collections::all, EventJson}; use ruma_identifiers::{EventId, RoomId}; use crate::r0::filter::RoomEventFilter; @@ -51,20 +51,20 @@ ruma_api! { /// A list of room events that happened just before the requested event, /// in reverse-chronological order. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events_before: Vec>, + pub events_before: Vec>, /// Details of the requested event. #[serde(skip_serializing_if = "Option::is_none")] - pub event: Option>, + pub event: Option>, /// A list of room events that happened just after the requested event, /// in chronological order. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events_after: Vec>, + pub events_after: Vec>, /// The state of the room at the last event returned. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub state: Vec>, + pub state: Vec>, } error: crate::Error From eea1046366e70b70bf5e9dd49c230bec61ba46c9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 12:51:25 +0200 Subject: [PATCH 346/350] Fix (de)serialization for filter in get_context --- src/r0/context/get_context.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index 37c88d00..14cdc610 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -35,7 +35,11 @@ ruma_api! { /// A RoomEventFilter to filter returned events with. #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] + #[serde( + with = "ruma_serde::json_string", + default, + skip_serializing_if = "Option::is_none" + )] pub filter: Option, } From 9fb2c42f06d1d19565aea804ca815e02c104ce0c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 21:00:17 +0200 Subject: [PATCH 347/350] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd472a62..d129619c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Breaking changes: * Add `predecessor` field * Update `r0::push::get_pushrules_all` and `r0::push::get_pushrules_global_scope` to use the `Ruleset` type from `ruma_events` +* Fix event types in `r0::context::get_context` Improvements: From 5365ee3afe838e8f4711c52a969be60ae7a00323 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 21:13:58 +0200 Subject: [PATCH 348/350] Use PresenceState from ruma_common, deprecate SetPresence --- CHANGELOG.md | 7 ++++++- Cargo.toml | 2 +- src/r0/sync/sync_events.rs | 33 +++++++++------------------------ 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d129619c..5bfc9d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,12 @@ Breaking changes: Improvements: * Add method `into_event_content` for `r0::room::create_room::CreationContent` -* Add room visibility endpoints: `r0::directory::{get_room_visibility, set_room_visibility}`. +* Add room visibility endpoints: `r0::directory::{get_room_visibility, set_room_visibility}`. + +Deprecations: + +* `r0::sync::sync_events::SetPresence` has been renamed to `PresenceState`. It is still available + under its previous name, but only for one release. # 0.9.0 diff --git a/Cargo.toml b/Cargo.toml index 1ed9dd53..8f7ac04e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" http = "0.2.1" js_int = { version = "0.1.5", features = ["serde"] } ruma-api = "0.16.1" -ruma-common = "0.1.2" +ruma-common = "0.1.3" ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "7395f94" } ruma-identifiers = "0.16.2" ruma-serde = "0.2.2" diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index a253698c..dad8a069 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -51,7 +51,7 @@ ruma_api! { /// Controls whether the client is automatically marked as online by polling this API. #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_api(query)] - pub set_presence: SetPresence, + pub set_presence: PresenceState, /// The maximum time to poll in milliseconds before returning this request. #[serde( @@ -98,25 +98,10 @@ ruma_api! { error: crate::Error } -/// Whether to set presence or not during sync. -#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "lowercase")] -pub enum SetPresence { - /// Do not set the presence of the user calling this API. - Offline, +pub use ruma_common::presence::PresenceState; - /// Mark client as online explicitly. Assumed by default. - Online, - - /// Mark client as being idle. - Unavailable, -} - -impl Default for SetPresence { - fn default() -> Self { - Self::Online - } -} +#[deprecated = "use `PresenceState` instead"] +pub use self::PresenceState as SetPresence; /// A filter represented either as its full JSON definition or the ID of a saved filter. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -344,7 +329,7 @@ mod tests { use matches::assert_matches; - use super::{Filter, Request, SetPresence}; + use super::{Filter, PresenceState, Request}; #[test] fn serialize_all_params() { @@ -352,7 +337,7 @@ mod tests { filter: Some(Filter::FilterId("66696p746572".into())), since: Some("s72594_4483_1934".into()), full_state: true, - set_presence: SetPresence::Offline, + set_presence: PresenceState::Offline, timeout: Some(Duration::from_millis(30000)), } .try_into() @@ -395,7 +380,7 @@ mod tests { assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "myfilter"); assert_eq!(req.since, Some("myts".into())); assert_eq!(req.full_state, false); - assert_eq!(req.set_presence, SetPresence::Offline); + assert_eq!(req.set_presence, PresenceState::Offline); assert_eq!(req.timeout, Some(Duration::from_millis(5000))); } @@ -418,7 +403,7 @@ mod tests { assert_matches!(req.filter, None); assert_eq!(req.since, None); assert_eq!(req.full_state, false); - assert_eq!(req.set_presence, SetPresence::Online); + assert_eq!(req.set_presence, PresenceState::Online); assert_eq!(req.timeout, None); } @@ -445,7 +430,7 @@ mod tests { assert_matches!(req.filter, Some(Filter::FilterId(id)) if id == "EOKFFmdZYF"); assert_eq!(req.since, None); assert_eq!(req.full_state, false); - assert_eq!(req.set_presence, SetPresence::Online); + assert_eq!(req.set_presence, PresenceState::Online); assert_eq!(req.timeout, Some(Duration::from_millis(0))); } } From 81c7849ae803a4bee07b49ef2715c7b4d416923e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 21:16:39 +0200 Subject: [PATCH 349/350] Update pinned version of ruma-events --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8f7ac04e..6f1654ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ http = "0.2.1" js_int = { version = "0.1.5", features = ["serde"] } ruma-api = "0.16.1" ruma-common = "0.1.3" -ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "7395f94" } +ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "c1ee72d" } ruma-identifiers = "0.16.2" ruma-serde = "0.2.2" serde = { version = "1.0.111", features = ["derive"] } From 632eb9d520028816c5fb7224bd0aca8d1e3793f1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Jun 2020 22:45:58 +0200 Subject: [PATCH 350/350] Update crate authors --- Cargo.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6f1654ea..17e4ce78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,9 @@ [package] -authors = ["Jimmy Cuadra "] +authors = [ + "Jimmy Cuadra ", + "Jonas Platte ", + "Isaiah Inuwa ", +] categories = ["api-bindings", "web-programming"] description = "Types for the endpoints in the Matrix client-server API." documentation = "https://docs.rs/ruma-client-api"