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] 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, + } +}