client-api: Transition from r0 to versioned endpoints
This commit is contained in:
parent
c4d2eacc38
commit
4787bab6ac
@ -70,8 +70,8 @@ pub mod v1 {
|
||||
pub fn try_into_sync_response(
|
||||
self,
|
||||
next_batch: impl Into<String>,
|
||||
) -> serde_json::Result<ruma_client_api::r0::sync::sync_events::Response> {
|
||||
use ruma_client_api::r0::sync::sync_events;
|
||||
) -> serde_json::Result<ruma_client_api::sync::sync_events::v3::Response> {
|
||||
use ruma_client_api::sync::sync_events;
|
||||
use ruma_identifiers::RoomId;
|
||||
use serde::Deserialize;
|
||||
use tracing::warn;
|
||||
@ -81,7 +81,7 @@ pub mod v1 {
|
||||
room_id: Option<Box<RoomId>>,
|
||||
}
|
||||
|
||||
let mut response = sync_events::Response::new(next_batch.into());
|
||||
let mut response = sync_events::v3::Response::new(next_batch.into());
|
||||
|
||||
for raw_event in self.events {
|
||||
let helper = raw_event.deserialize_as::<EventDeHelper>()?;
|
||||
@ -110,7 +110,7 @@ pub mod v1 {
|
||||
#[cfg(test)]
|
||||
mod helper_tests {
|
||||
use super::{AnyRoomEvent, IncomingRequest, Raw};
|
||||
use ruma_client_api::r0::sync::sync_events;
|
||||
use ruma_client_api::sync::sync_events;
|
||||
use ruma_identifiers::room_id;
|
||||
use serde_json::json;
|
||||
|
||||
|
56
crates/ruma-client-api/src/account/add_3pid.rs
Normal file
56
crates/ruma-client-api/src/account/add_3pid.rs
Normal file
@ -0,0 +1,56 @@
|
||||
//! `POST /_matrix/client/*/account/3pid/add`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3pidadd
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Add contact information to a user's account",
|
||||
method: POST,
|
||||
name: "add_3pid",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/add",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/add",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Additional information for the User-Interactive Authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: &'a SessionId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret and session identifier.
|
||||
pub fn new(client_secret: &'a ClientSecret, sid: &'a SessionId) -> Self {
|
||||
Self { auth: None, client_secret, sid }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
62
crates/ruma-client-api/src/account/bind_3pid.rs
Normal file
62
crates/ruma-client-api/src/account/bind_3pid.rs
Normal file
@ -0,0 +1,62 @@
|
||||
//! `POST /_matrix/client/*/account/3pid/bind`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3pidbind
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Bind a 3PID to a user's account on an identity server",
|
||||
method: POST,
|
||||
name: "bind_3pid",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/bind",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/bind",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// The ID server to send the onward request to as a hostname with an
|
||||
/// appended colon and port number if the port is not the default.
|
||||
#[serde(flatten)]
|
||||
pub identity_server_info: IdentityServerInfo<'a>,
|
||||
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: &'a SessionId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, identity server information and
|
||||
/// session identifier.
|
||||
pub fn new(
|
||||
client_secret: &'a ClientSecret,
|
||||
identity_server_info: IdentityServerInfo<'a>,
|
||||
sid: &'a SessionId,
|
||||
) -> Self {
|
||||
Self { client_secret, identity_server_info, sid }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
62
crates/ruma-client-api/src/account/change_password.rs
Normal file
62
crates/ruma-client-api/src/account/change_password.rs
Normal file
@ -0,0 +1,62 @@
|
||||
//! `POST /_matrix/client/*/account/password`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3accountpassword
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Change the password of the current user's account.",
|
||||
method: POST,
|
||||
name: "change_password",
|
||||
r0_path: "/_matrix/client/r0/account/password",
|
||||
stable_path: "/_matrix/client/v3/account/password",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The new password for the account.
|
||||
pub new_password: &'a str,
|
||||
|
||||
/// True to revoke the user's other access tokens, and their associated devices if the
|
||||
/// request succeeds.
|
||||
///
|
||||
/// Defaults to true.
|
||||
///
|
||||
/// When false, the server can still take advantage of the soft logout method for the user's
|
||||
/// remaining devices.
|
||||
#[serde(default = "ruma_serde::default_true", skip_serializing_if = "ruma_serde::is_true")]
|
||||
pub logout_devices: bool,
|
||||
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given password.
|
||||
pub fn new(new_password: &'a str) -> Self {
|
||||
Self { new_password, logout_devices: true, auth: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
//! `GET /_matrix/client/*/register/m.login.registration_token/validity`
|
||||
|
||||
pub mod v1 {
|
||||
//! `/v1/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv1registermloginregistration_tokenvalidity
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Checks to see if the given registration token is valid.",
|
||||
method: GET,
|
||||
name: "check_registration_token_validity",
|
||||
unstable_path: "/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity",
|
||||
stable_path: "/_matrix/client/v1/register/m.login.registration_token/validity",
|
||||
rate_limited: true,
|
||||
authentication: None,
|
||||
added: 1.2,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The registration token to check the validity of.
|
||||
#[ruma_api(query)]
|
||||
pub registration_token: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A flag to indicate that the registration token is valid.
|
||||
pub valid: bool,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given registration token.
|
||||
pub fn new(registration_token: &'a str) -> Self {
|
||||
Self { registration_token }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given validity flag.
|
||||
pub fn new(valid: bool) -> Self {
|
||||
Self { valid }
|
||||
}
|
||||
}
|
||||
}
|
60
crates/ruma-client-api/src/account/deactivate.rs
Normal file
60
crates/ruma-client-api/src/account/deactivate.rs
Normal file
@ -0,0 +1,60 @@
|
||||
//! `POST /_matrix/client/*/account/deactivate`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3accountdeactivate
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use crate::{
|
||||
account::ThirdPartyIdRemovalStatus,
|
||||
uiaa::{AuthData, IncomingAuthData, UiaaResponse},
|
||||
};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Deactivate the current user's account.",
|
||||
method: POST,
|
||||
name: "deactivate",
|
||||
r0_path: "/_matrix/client/r0/account/deactivate",
|
||||
stable_path: "/_matrix/client/v3/account/deactivate",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
|
||||
/// Identity server from which to unbind the user's third party
|
||||
/// identifier.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id_server: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Result of unbind operation.
|
||||
pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
|
||||
}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl Request<'_> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given unbind result.
|
||||
pub fn new(id_server_unbind_result: ThirdPartyIdRemovalStatus) -> Self {
|
||||
Self { id_server_unbind_result }
|
||||
}
|
||||
}
|
||||
}
|
51
crates/ruma-client-api/src/account/delete_3pid.rs
Normal file
51
crates/ruma-client-api/src/account/delete_3pid.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! POST /_matrix/client/*/account/3pid/delete
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3piddelete
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::thirdparty::Medium;
|
||||
|
||||
use crate::account::ThirdPartyIdRemovalStatus;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete a 3PID from a user's account on an identity server.",
|
||||
method: POST,
|
||||
name: "delete_3pid",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/delete",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/delete",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Identity server to delete from.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id_server: Option<&'a str>,
|
||||
|
||||
/// Medium of the 3PID to be removed.
|
||||
pub medium: Medium,
|
||||
|
||||
/// Third-party address being removed.
|
||||
pub address: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Result of unbind operation.
|
||||
pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given medium and address.
|
||||
pub fn new(medium: Medium, address: &'a str) -> Self {
|
||||
Self { id_server: None, medium, address }
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/account/get_3pids.rs
Normal file
48
crates/ruma-client-api/src/account/get_3pids.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `GET /_matrix/client/*/account/3pid`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3account3pid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::thirdparty::ThirdPartyIdentifier;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a list of 3rd party contacts associated with the user's account.",
|
||||
method: GET,
|
||||
name: "get_3pids",
|
||||
r0_path: "/_matrix/client/r0/account/3pid",
|
||||
stable_path: "/_matrix/client/v3/account/3pid",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// A list of third party identifiers the homeserver has associated with the user's account.
|
||||
#[serde(default)]
|
||||
#[cfg_attr(not(feature = "compat"), serde(skip_serializing_if = "Vec::is_empty"))]
|
||||
pub threepids: Vec<ThirdPartyIdentifier>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given third party identifiers.
|
||||
pub fn new(threepids: Vec<ThirdPartyIdentifier>) -> Self {
|
||||
Self { threepids }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
//! `GET /_matrix/client/*/register/available`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3registeravailable
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Checks to see if a username is available, and valid, for the server.",
|
||||
method: GET,
|
||||
name: "get_username_availability",
|
||||
r0_path: "/_matrix/client/r0/register/available",
|
||||
stable_path: "/_matrix/client/v3/register/available",
|
||||
rate_limited: true,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The username to check the availability of.
|
||||
#[ruma_api(query)]
|
||||
pub username: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A flag to indicate that the username is available.
|
||||
/// This should always be true when the server replies with 200 OK.
|
||||
pub available: bool,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given username.
|
||||
pub fn new(username: &'a str) -> Self {
|
||||
Self { username }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given availability flag.
|
||||
pub fn new(available: bool) -> Self {
|
||||
Self { available }
|
||||
}
|
||||
}
|
||||
}
|
148
crates/ruma-client-api/src/account/register.rs
Normal file
148
crates/ruma-client-api/src/account/register.rs
Normal file
@ -0,0 +1,148 @@
|
||||
//! `POST /_matrix/client/*/register`
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
|
||||
use super::{LoginType, RegistrationKind};
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Register an account on this homeserver.",
|
||||
method: POST,
|
||||
name: "register",
|
||||
r0_path: "/_matrix/client/r0/register",
|
||||
stable_path: "/_matrix/client/v3/register",
|
||||
rate_limited: true,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// The desired password for the account.
|
||||
///
|
||||
/// May be empty for accounts that should not be able to log in again
|
||||
/// with a password, e.g., for guest or application service accounts.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub password: Option<&'a str>,
|
||||
|
||||
/// Localpart 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<&'a str>,
|
||||
|
||||
/// 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 DeviceId>,
|
||||
|
||||
/// 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<&'a str>,
|
||||
|
||||
/// 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<AuthData<'a>>,
|
||||
|
||||
/// Kind of account to register
|
||||
///
|
||||
/// Defaults to `User` if omitted.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub kind: RegistrationKind,
|
||||
|
||||
/// If `true`, an `access_token` and `device_id` should not be returned
|
||||
/// from this call, therefore preventing an automatic login.
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub inhibit_login: bool,
|
||||
|
||||
/// Login `type` used by Appservices.
|
||||
///
|
||||
/// Appservices can [bypass the registration flows][admin] entirely by providing their
|
||||
/// token in the header and setting this login `type` to `m.login.application_service`.
|
||||
///
|
||||
/// [admin]: https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub login_type: Option<&'a LoginType>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An access token for the account.
|
||||
///
|
||||
/// This access token can then be used to authorize other requests.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub access_token: Option<String>,
|
||||
|
||||
/// The fully-qualified Matrix ID that has been registered.
|
||||
pub user_id: Box<UserId>,
|
||||
|
||||
/// ID of the registered device.
|
||||
///
|
||||
/// Will be the same as the corresponding parameter in the request, if one was specified.
|
||||
pub device_id: Option<Box<DeviceId>>,
|
||||
}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl Request<'_> {
|
||||
/// Creates a new `Request` with all parameters defaulted.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user ID.
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { access_token: None, user_id, device_id: None }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of account being registered.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum RegistrationKind {
|
||||
/// A guest account
|
||||
///
|
||||
/// These accounts may have limited permissions and may not be supported by all servers.
|
||||
Guest,
|
||||
|
||||
/// A regular user account
|
||||
User,
|
||||
}
|
||||
|
||||
impl Default for RegistrationKind {
|
||||
fn default() -> Self {
|
||||
Self::User
|
||||
}
|
||||
}
|
||||
|
||||
/// The login type.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum LoginType {
|
||||
/// An appservice-specific login type
|
||||
#[serde(rename = "m.login.application_service")]
|
||||
ApplicationService,
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
//! `POST /_matrix/client/*/account/3pid/email/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3pidemailrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request a 3PID management token with a 3rd party email.",
|
||||
method: POST,
|
||||
name: "request_3pid_management_token_via_email",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/email/requestToken",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/email/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// The email address.
|
||||
pub email: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the email.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
|
||||
/// Optional identity server hostname and access token.
|
||||
///
|
||||
/// Deprecated since r0.6.0.
|
||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||
pub identity_server_info: Option<IdentityServerInfo<'a>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will
|
||||
/// result in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the client secret, email and send-attempt counter.
|
||||
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
//! `POST /_matrix/client/*/account/3pid/msisdn/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3pidmsisdnrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request a 3PID management token with a phone number.",
|
||||
method: POST,
|
||||
name: "request_3pid_management_token_via_msisdn",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/msisdn/requestToken",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/msisdn/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// Two-letter ISO 3166 country code for the phone number.
|
||||
pub country: &'a str,
|
||||
|
||||
/// Phone number to validate.
|
||||
pub phone_number: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the SMS.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
|
||||
/// Optional identity server hostname and access token.
|
||||
///
|
||||
/// Deprecated since r0.6.0.
|
||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||
pub identity_server_info: Option<IdentityServerInfo<'a>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will
|
||||
/// result in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||
/// send-attempt counter.
|
||||
pub fn new(
|
||||
client_secret: &'a ClientSecret,
|
||||
country: &'a str,
|
||||
phone_number: &'a str,
|
||||
send_attempt: UInt,
|
||||
) -> Self {
|
||||
Self {
|
||||
client_secret,
|
||||
country,
|
||||
phone_number,
|
||||
send_attempt,
|
||||
next_link: None,
|
||||
identity_server_info: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
69
crates/ruma-client-api/src/account/request_openid_token.rs
Normal file
69
crates/ruma-client-api/src/account/request_openid_token.rs
Normal file
@ -0,0 +1,69 @@
|
||||
//! `POST /_matrix/client/*/user/{userId}/openid/request_token`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridopenidrequest_token
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::authentication::TokenType;
|
||||
use ruma_identifiers::{ServerName, UserId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request an OpenID 1.0 token to verify identity with a third party.",
|
||||
name: "request_openid_token",
|
||||
method: POST,
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/openid/request_token",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/openid/request_token",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// User ID of authenticated user.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: &'a UserId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Access token for verifying user's identity.
|
||||
pub access_token: String,
|
||||
|
||||
/// Access token type.
|
||||
pub token_type: TokenType,
|
||||
|
||||
/// Homeserver domain for verification of user's identity.
|
||||
pub matrix_server_name: Box<ServerName>,
|
||||
|
||||
/// Seconds until token expiration.
|
||||
#[serde(with = "ruma_serde::duration::secs")]
|
||||
pub expires_in: Duration,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID.
|
||||
pub fn new(user_id: &'a UserId) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given access token, token type, server name and
|
||||
/// expiration duration.
|
||||
pub fn new(
|
||||
access_token: String,
|
||||
token_type: TokenType,
|
||||
matrix_server_name: Box<ServerName>,
|
||||
expires_in: Duration,
|
||||
) -> Self {
|
||||
Self { access_token, token_type, matrix_server_name, expires_in }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
//! `POST /_matrix/client/*/account/password/email/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3accountpasswordemailrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request that a password change token is sent to the given email address.",
|
||||
method: POST,
|
||||
name: "request_password_change_token_via_email",
|
||||
r0_path: "/_matrix/client/r0/account/password/email/requestToken",
|
||||
stable_path: "/_matrix/client/v3/account/password/email/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// The email address.
|
||||
pub email: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the email.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
|
||||
/// Optional identity server hostname and access token.
|
||||
///
|
||||
/// Deprecated since r0.6.0.
|
||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||
pub identity_server_info: Option<IdentityServerInfo<'a>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will result
|
||||
/// in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
||||
/// counter.
|
||||
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
//! `POST /_matrix/client/*/account/password/msisdn/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3accountpasswordmsisdnrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request that a password change token is sent to the given phone number.",
|
||||
method: POST,
|
||||
name: "request_password_change_token_via_msisdn",
|
||||
r0_path: "/_matrix/client/r0/account/password/msisdn/requestToken",
|
||||
stable_path: "/_matrix/client/v3/account/password/msisdn/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// Two-letter ISO 3166 country code for the phone number.
|
||||
pub country: &'a str,
|
||||
|
||||
/// Phone number to validate.
|
||||
pub phone_number: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the SMS.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will result
|
||||
/// in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||
/// send-attempt counter.
|
||||
pub fn new(
|
||||
client_secret: &'a ClientSecret,
|
||||
country: &'a str,
|
||||
phone_number: &'a str,
|
||||
send_attempt: UInt,
|
||||
) -> Self {
|
||||
Self { client_secret, country, phone_number, send_attempt, next_link: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
//! `POST /_matrix/client/*/register/email/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3registeremailrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request a registration token with a 3rd party email.",
|
||||
method: POST,
|
||||
name: "request_registration_token_via_email",
|
||||
r0_path: "/_matrix/client/r0/register/email/requestToken",
|
||||
stable_path: "/_matrix/client/v3/register/email/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// The email address.
|
||||
pub email: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the email.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
|
||||
/// Optional identity server hostname and access token.
|
||||
///
|
||||
/// Deprecated since r0.6.0.
|
||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||
pub identity_server_info: Option<IdentityServerInfo<'a>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will result
|
||||
/// in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
||||
/// counter.
|
||||
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
//! `POST /_matrix/client/*/register/msisdn/requestToken`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3registermsisdnrequesttoken
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{ClientSecret, SessionId};
|
||||
|
||||
use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Request a registration token with a phone number.",
|
||||
method: POST,
|
||||
name: "request_registration_token_via_msisdn",
|
||||
r0_path: "/_matrix/client/r0/register/msisdn/requestToken",
|
||||
stable_path: "/_matrix/client/v3/register/msisdn/requestToken",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: &'a ClientSecret,
|
||||
|
||||
/// Two-letter ISO 3166 country code for the phone number.
|
||||
pub country: &'a str,
|
||||
|
||||
/// Phone number to validate.
|
||||
pub phone_number: &'a str,
|
||||
|
||||
/// Used to distinguish protocol level retries from requests to re-send the SMS.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// Return URL for identity server to redirect the client back to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
|
||||
/// Optional identity server hostname and access token.
|
||||
///
|
||||
/// Deprecated since r0.6.0.
|
||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||
pub identity_server_info: Option<IdentityServerInfo<'a>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: Box<SessionId>,
|
||||
|
||||
/// URL to submit validation token to.
|
||||
///
|
||||
/// If omitted, verification happens without client.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will result
|
||||
/// in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub submit_url: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||
/// send-attempt counter.
|
||||
pub fn new(
|
||||
client_secret: &'a ClientSecret,
|
||||
country: &'a str,
|
||||
phone_number: &'a str,
|
||||
send_attempt: UInt,
|
||||
) -> Self {
|
||||
Self {
|
||||
client_secret,
|
||||
country,
|
||||
phone_number,
|
||||
send_attempt,
|
||||
next_link: None,
|
||||
identity_server_info: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given session identifier.
|
||||
pub fn new(sid: Box<SessionId>) -> Self {
|
||||
Self { sid, submit_url: None }
|
||||
}
|
||||
}
|
||||
}
|
58
crates/ruma-client-api/src/account/unbind_3pid.rs
Normal file
58
crates/ruma-client-api/src/account/unbind_3pid.rs
Normal file
@ -0,0 +1,58 @@
|
||||
//! `POST /_matrix/client/*/account/3pid/unbind`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3account3pidunbind
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::thirdparty::Medium;
|
||||
|
||||
use crate::account::ThirdPartyIdRemovalStatus;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Unbind a 3PID from a user's account on an identity server.",
|
||||
method: POST,
|
||||
name: "unbind_3pid",
|
||||
r0_path: "/_matrix/client/r0/account/3pid/unbind",
|
||||
stable_path: "/_matrix/client/v3/account/3pid/unbind",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Identity server to unbind from.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id_server: Option<&'a str>,
|
||||
|
||||
/// Medium of the 3PID to be removed.
|
||||
pub medium: Medium,
|
||||
|
||||
/// Third-party address being removed.
|
||||
pub address: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Result of unbind operation.
|
||||
pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given medium and third-party address.
|
||||
pub fn new(medium: Medium, address: &'a str) -> Self {
|
||||
Self { id_server: None, medium, address }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given unbind result.
|
||||
pub fn new(id_server_unbind_result: ThirdPartyIdRemovalStatus) -> Self {
|
||||
Self { id_server_unbind_result }
|
||||
}
|
||||
}
|
||||
}
|
47
crates/ruma-client-api/src/account/whoami.rs
Normal file
47
crates/ruma-client-api/src/account/whoami.rs
Normal file
@ -0,0 +1,47 @@
|
||||
//! `GET /_matrix/client/*/account/whoami`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3accountwhoami
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get information about the owner of a given access token.",
|
||||
method: GET,
|
||||
name: "whoami",
|
||||
r0_path: "/_matrix/client/r0/account/whoami",
|
||||
stable_path: "/_matrix/client/v3/account/whoami",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// The id of the user that owns the access token.
|
||||
pub user_id: Box<UserId>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given user ID.
|
||||
pub fn new(user_id: Box<UserId>) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
}
|
51
crates/ruma-client-api/src/alias/create_alias.rs
Normal file
51
crates/ruma-client-api/src/alias/create_alias.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! `PUT /_matrix/client/*/directory/room/{roomAlias}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3directoryroomroomalias
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Add an alias to a room.",
|
||||
method: PUT,
|
||||
name: "create_alias",
|
||||
r0_path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
stable_path: "/_matrix/client/v3/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room alias to set.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
|
||||
/// The room ID to set.
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room alias and room id.
|
||||
pub fn new(room_alias: &'a RoomAliasId, room_id: &'a RoomId) -> Self {
|
||||
Self { room_alias, room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/alias/delete_alias.rs
Normal file
48
crates/ruma-client-api/src/alias/delete_alias.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `DELETE /_matrix/client/*/directory/room/{roomAlias}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3directoryroomroomalias
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomAliasId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Remove an alias from a room.",
|
||||
method: DELETE,
|
||||
name: "delete_alias",
|
||||
r0_path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
stable_path: "/_matrix/client/v3/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room alias to remove.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room alias.
|
||||
pub fn new(room_alias: &'a RoomAliasId) -> Self {
|
||||
Self { room_alias }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
53
crates/ruma-client-api/src/alias/get_alias.rs
Normal file
53
crates/ruma-client-api/src/alias/get_alias.rs
Normal file
@ -0,0 +1,53 @@
|
||||
//! `GET /_matrix/client/*/directory/room/{roomAlias}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3directoryroomroomalias
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId, ServerName};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Resolve a room alias to a room ID.",
|
||||
method: GET,
|
||||
name: "get_alias",
|
||||
r0_path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
stable_path: "/_matrix/client/v3/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room alias.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room ID for this room alias.
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// A list of servers that are aware of this room ID.
|
||||
pub servers: Vec<Box<ServerName>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room alias id.
|
||||
pub fn new(room_alias: &'a RoomAliasId) -> Self {
|
||||
Self { room_alias }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room id and servers
|
||||
pub fn new(room_id: Box<RoomId>, servers: Vec<Box<ServerName>>) -> Self {
|
||||
Self { room_id, servers }
|
||||
}
|
||||
}
|
||||
}
|
57
crates/ruma-client-api/src/appservice/set_room_visibility.rs
Normal file
57
crates/ruma-client-api/src/appservice/set_room_visibility.rs
Normal file
@ -0,0 +1,57 @@
|
||||
//! `PUT /_matrix/client/*/directory/list/appservice/{networkId}/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/application-service-api/#put_matrixclientv3directorylistappservicenetworkidroomid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::room::Visibility;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Updates the visibility of a given room on the application service's room directory.",
|
||||
method: PUT,
|
||||
name: "set_room_visibility",
|
||||
r0_path: "/_matrix/client/r0/directory/list/appservice/:network_id/:room_id",
|
||||
stable_path: "/_matrix/client/v3/directory/list/appservice/:network_id/:room_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The protocol (network) ID to update the room list for.
|
||||
#[ruma_api(path)]
|
||||
pub network_id: &'a str,
|
||||
|
||||
/// The room ID to add to the directory.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// Whether the room should be visible (public) in the directory or not (private).
|
||||
pub visibility: Visibility,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given network ID, room ID and visibility.
|
||||
pub fn new(network_id: &'a str, room_id: &'a RoomId, visibility: Visibility) -> Self {
|
||||
Self { network_id, room_id, visibility }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
80
crates/ruma-client-api/src/backup/add_backup_key_session.rs
Normal file
80
crates/ruma-client-api/src/backup/add_backup_key_session.rs
Normal file
@ -0,0 +1,80 @@
|
||||
//! `PUT /_matrix/client/*/room_keys/keys/{roomId}/{sessionId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3room_keyskeysroomidsessionid
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::KeyBackupData;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Store several keys in the backup.",
|
||||
method: PUT,
|
||||
name: "add_backup_key_session",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The ID of the megolm session whose key is requested.
|
||||
#[ruma_api(path)]
|
||||
pub session_id: &'a str,
|
||||
|
||||
/// The key information to backup.
|
||||
#[ruma_api(body)]
|
||||
pub session_data: Raw<KeyBackupData>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version, room_id, session_id and session_data.
|
||||
pub fn new(
|
||||
version: &'a str,
|
||||
room_id: &'a RoomId,
|
||||
session_id: &'a str,
|
||||
session_data: Raw<KeyBackupData>,
|
||||
) -> Self {
|
||||
Self { version, room_id, session_id, session_data }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an new `Response` with the given etag and count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
76
crates/ruma-client-api/src/backup/add_backup_key_sessions.rs
Normal file
76
crates/ruma-client-api/src/backup/add_backup_key_sessions.rs
Normal file
@ -0,0 +1,76 @@
|
||||
//! `PUT /_matrix/client/*/room_keys/keys/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3room_keyskeysroomid
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::KeyBackupData;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Store several sessions in the backup.",
|
||||
method: PUT,
|
||||
name: "add_backup_key_sessions",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// A map from session IDs to key data.
|
||||
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version, room_id and sessions.
|
||||
pub fn new(
|
||||
version: &'a str,
|
||||
room_id: &'a RoomId,
|
||||
sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||
) -> Self {
|
||||
Self { version, room_id, sessions }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an new `Response` with the given etag and count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
66
crates/ruma-client-api/src/backup/add_backup_keys.rs
Normal file
66
crates/ruma-client-api/src/backup/add_backup_keys.rs
Normal file
@ -0,0 +1,66 @@
|
||||
//! `PUT /_matrix/client/*/room_keys/keys`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3room_keyskeys
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::backup::RoomKeyBackup;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Store several keys in the backup.",
|
||||
method: PUT,
|
||||
name: "add_backup_keys",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
pub rooms: BTreeMap<Box<RoomId>, RoomKeyBackup>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version and room key backups.
|
||||
pub fn new(version: &'a str, rooms: BTreeMap<Box<RoomId>, RoomKeyBackup>) -> Self {
|
||||
Self { version, rooms }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given etag and key count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
52
crates/ruma-client-api/src/backup/create_backup.rs
Normal file
52
crates/ruma-client-api/src/backup/create_backup.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! `POST /_matrix/client/*/room_keys/version`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3room_keysversion
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Creates a new backup.",
|
||||
method: POST,
|
||||
name: "create_backup",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/version",
|
||||
stable_path: "/_matrix/client/v3/room_keys/version",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The algorithm used for storing backups.
|
||||
#[ruma_api(body)]
|
||||
pub algorithm: Raw<BackupAlgorithm>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The backup version.
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given backup algorithm.
|
||||
pub fn new(algorithm: Raw<BackupAlgorithm>) -> Self {
|
||||
Self { algorithm }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given version.
|
||||
pub fn new(version: String) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/backup/delete_backup.rs
Normal file
48
crates/ruma-client-api/src/backup/delete_backup.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `DELETE /_matrix/client/*/room_keys/version/{version}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3room_keysversionversion
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete an existing backup.",
|
||||
method: DELETE,
|
||||
name: "delete_backup",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/version/:version",
|
||||
r0_path: "/_matrix/client/r0/room_keys/version/:version",
|
||||
stable_path: "/_matrix/client/v3/room_keys/version/:version",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
#[ruma_api(path)]
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version, room_id and sessions.
|
||||
pub fn new(version: &'a str) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
//! `DELETE /_matrix/client/*/room_keys/keys/{roomId}/{sessionId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3room_keyskeysroomidsessionid
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete a key from the backup",
|
||||
method: DELETE,
|
||||
name: "delete_backup_key_session",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The ID of the megolm session whose key is requested.
|
||||
#[ruma_api(path)]
|
||||
pub session_id: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version, room_id and session_id.
|
||||
pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self {
|
||||
Self { version, room_id, session_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an new `Response` with the given etag and count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
//! `DELETE /_matrix/client/*/room_keys/keys/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3room_keyskeysroomid
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete keys from the backup for a given room.",
|
||||
method: DELETE,
|
||||
name: "delete_backup_key_sessions",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version and room_id.
|
||||
|
||||
pub fn new(version: &'a str, room_id: &'a RoomId) -> Self {
|
||||
Self { version, room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an new `Response` with the given etag and count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
59
crates/ruma-client-api/src/backup/delete_backup_keys.rs
Normal file
59
crates/ruma-client-api/src/backup/delete_backup_keys.rs
Normal file
@ -0,0 +1,59 @@
|
||||
//! `DELETE /_matrix/client/*/room_keys/keys`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3room_keyskeys
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete all keys in a backup.",
|
||||
method: DELETE,
|
||||
name: "delete_backup_keys",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version.
|
||||
pub fn new(version: &'a str) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an new `Response` with the given etag and count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
}
|
134
crates/ruma-client-api/src/backup/get_backup.rs
Normal file
134
crates/ruma-client-api/src/backup/get_backup.rs
Normal file
@ -0,0 +1,134 @@
|
||||
//! `GET /_matrix/client/*/room_keys/version/{version}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3room_keysversionversion
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_serde::Raw;
|
||||
use serde::{ser, Deserialize, Deserializer, Serialize};
|
||||
use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue};
|
||||
|
||||
use crate::backup::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get information about an existing backup.",
|
||||
method: GET,
|
||||
name: "get_backup",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/version/:version",
|
||||
stable_path: "/_matrix/client/v3/room_keys/version/:version",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
#[ruma_api(path)]
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
#[ruma_api(manual_body_serde)]
|
||||
response: {
|
||||
/// The algorithm used for storing backups.
|
||||
pub algorithm: Raw<BackupAlgorithm>,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The backup version.
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version.
|
||||
pub fn new(version: &'a str) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the gien algorithm, key count, etag and version.
|
||||
pub fn new(
|
||||
algorithm: Raw<BackupAlgorithm>,
|
||||
count: UInt,
|
||||
etag: String,
|
||||
version: String,
|
||||
) -> Self {
|
||||
Self { algorithm, count, etag, version }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(in crate::backup) struct ResponseBodyRepr {
|
||||
pub algorithm: Box<RawJsonValue>,
|
||||
pub auth_data: Box<RawJsonValue>,
|
||||
pub count: UInt,
|
||||
pub etag: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub(in crate::backup) struct RefResponseBodyRepr<'a> {
|
||||
pub algorithm: &'a RawJsonValue,
|
||||
pub auth_data: &'a RawJsonValue,
|
||||
pub count: UInt,
|
||||
pub etag: &'a str,
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub(in crate::backup) struct AlgorithmWithData {
|
||||
pub algorithm: Box<RawJsonValue>,
|
||||
pub auth_data: Box<RawJsonValue>,
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ResponseBody {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let ResponseBodyRepr { algorithm, auth_data, count, etag, version } =
|
||||
ResponseBodyRepr::deserialize(deserializer)?;
|
||||
|
||||
let algorithm = Raw::from_json(
|
||||
to_raw_json_value(&AlgorithmWithData { algorithm, auth_data }).unwrap(),
|
||||
);
|
||||
|
||||
Ok(Self { algorithm, count, etag, version })
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ResponseBody {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let ResponseBody { algorithm, count, etag, version } = self;
|
||||
let AlgorithmWithData { algorithm, auth_data } =
|
||||
algorithm.deserialize_as().map_err(ser::Error::custom)?;
|
||||
|
||||
let repr = RefResponseBodyRepr {
|
||||
algorithm: &algorithm,
|
||||
auth_data: &auth_data,
|
||||
count: *count,
|
||||
etag,
|
||||
version,
|
||||
};
|
||||
|
||||
repr.serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
65
crates/ruma-client-api/src/backup/get_backup_key_session.rs
Normal file
65
crates/ruma-client-api/src/backup/get_backup_key_session.rs
Normal file
@ -0,0 +1,65 @@
|
||||
//! `GET /_matrix/client/*/room_keys/keys/{roomId}/{sessionId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3room_keyskeysroomidsessionid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::KeyBackupData;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve a key from the backup",
|
||||
method: GET,
|
||||
name: "get_backup_key_session",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The ID of the megolm session whose key is requested.
|
||||
#[ruma_api(path)]
|
||||
pub session_id: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Information about the requested backup key.
|
||||
#[ruma_api(body)]
|
||||
pub key_data: Raw<KeyBackupData>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version, room_id and session_id.
|
||||
pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self {
|
||||
Self { version, room_id, session_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given key_data.
|
||||
pub fn new(key_data: Raw<KeyBackupData>) -> Self {
|
||||
Self { key_data }
|
||||
}
|
||||
}
|
||||
}
|
62
crates/ruma-client-api/src/backup/get_backup_key_sessions.rs
Normal file
62
crates/ruma-client-api/src/backup/get_backup_key_sessions.rs
Normal file
@ -0,0 +1,62 @@
|
||||
//! `GET /_matrix/client/*/room_keys/keys/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3room_keyskeysroomid
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::KeyBackupData;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve sessions from the backup for a given room.",
|
||||
method: GET,
|
||||
name: "get_backup_key_sessions",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys/:room_id",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys/:room_id",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The ID of the room that the requested key is for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A map of session IDs to key data.
|
||||
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version and room_id.
|
||||
pub fn new(version: &'a str, room_id: &'a RoomId) -> Self {
|
||||
Self { version, room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given sessions.
|
||||
pub fn new(sessions: BTreeMap<String, Raw<KeyBackupData>>) -> Self {
|
||||
Self { sessions }
|
||||
}
|
||||
}
|
||||
}
|
57
crates/ruma-client-api/src/backup/get_backup_keys.rs
Normal file
57
crates/ruma-client-api/src/backup/get_backup_keys.rs
Normal file
@ -0,0 +1,57 @@
|
||||
//! `GET /_matrix/client/*/room_keys/keys`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3room_keyskeys
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::backup::RoomKeyBackup;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve all keys from a backup.",
|
||||
method: GET,
|
||||
name: "get_backup_keys",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/keys",
|
||||
r0_path: "/_matrix/client/r0/room_keys/keys",
|
||||
stable_path: "/_matrix/client/v3/room_keys/keys",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
///
|
||||
/// Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
pub rooms: BTreeMap<Box<RoomId>, RoomKeyBackup>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version.
|
||||
pub fn new(version: &'a str) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room key backups.
|
||||
pub fn new(rooms: BTreeMap<Box<RoomId>, RoomKeyBackup>) -> Self {
|
||||
Self { rooms }
|
||||
}
|
||||
}
|
||||
}
|
111
crates/ruma-client-api/src/backup/get_latest_backup.rs
Normal file
111
crates/ruma-client-api/src/backup/get_latest_backup.rs
Normal file
@ -0,0 +1,111 @@
|
||||
//! `GET /_matrix/client/*/room_keys/version`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3room_keysversion
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_serde::Raw;
|
||||
use serde::{ser, Deserialize, Deserializer, Serialize};
|
||||
use serde_json::value::to_raw_value as to_raw_json_value;
|
||||
|
||||
use crate::backup::{
|
||||
get_backup::v3::{AlgorithmWithData, RefResponseBodyRepr, ResponseBodyRepr},
|
||||
BackupAlgorithm,
|
||||
};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get information about the latest backup.",
|
||||
method: GET,
|
||||
name: "get_latest_backup",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/version",
|
||||
r0_path: "/_matrix/client/r0/room_keys/version",
|
||||
stable_path: "/_matrix/client/v3/room_keys/version",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
#[ruma_api(manual_body_serde)]
|
||||
response: {
|
||||
/// The algorithm used for storing backups.
|
||||
pub algorithm: Raw<BackupAlgorithm>,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
|
||||
/// An opaque string representing stored keys in the backup.
|
||||
///
|
||||
/// Clients can compare it with the etag value they received in the request of their last
|
||||
/// key storage request.
|
||||
pub etag: String,
|
||||
|
||||
/// The backup version.
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given algorithm, key count, etag and version.
|
||||
pub fn new(
|
||||
algorithm: Raw<BackupAlgorithm>,
|
||||
count: UInt,
|
||||
etag: String,
|
||||
version: String,
|
||||
) -> Self {
|
||||
Self { algorithm, count, etag, version }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ResponseBody {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let ResponseBodyRepr { algorithm, auth_data, count, etag, version } =
|
||||
ResponseBodyRepr::deserialize(deserializer)?;
|
||||
|
||||
let algorithm = Raw::from_json(
|
||||
to_raw_json_value(&AlgorithmWithData { algorithm, auth_data }).unwrap(),
|
||||
);
|
||||
|
||||
Ok(Self { algorithm, count, etag, version })
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ResponseBody {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let ResponseBody { algorithm, count, etag, version } = self;
|
||||
let AlgorithmWithData { algorithm, auth_data } =
|
||||
algorithm.deserialize_as().map_err(ser::Error::custom)?;
|
||||
|
||||
let repr = RefResponseBodyRepr {
|
||||
algorithm: &algorithm,
|
||||
auth_data: &auth_data,
|
||||
count: *count,
|
||||
etag,
|
||||
version,
|
||||
};
|
||||
|
||||
repr.serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
54
crates/ruma-client-api/src/backup/update_backup.rs
Normal file
54
crates/ruma-client-api/src/backup/update_backup.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! `POST /_matrix/client/*/room_keys/version`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3room_keysversion
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::backup::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Update information about an existing backup.",
|
||||
method: POST,
|
||||
name: "update_backup",
|
||||
unstable_path: "/_matrix/client/unstable/room_keys/version/:version",
|
||||
stable_path: "/_matrix/client/v3/room_keys/version/:version",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The backup version.
|
||||
#[ruma_api(path)]
|
||||
pub version: &'a str,
|
||||
|
||||
/// The algorithm used for storing backups.
|
||||
#[ruma_api(body)]
|
||||
pub algorithm: Raw<BackupAlgorithm>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given backup version and algorithm.
|
||||
pub fn new(version: &'a str, algorithm: Raw<BackupAlgorithm>) -> Self {
|
||||
Self { version, algorithm }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,13 @@
|
||||
|
||||
use std::{borrow::Cow, collections::BTreeMap};
|
||||
|
||||
use iter::{CapabilitiesIter, CapabilityRef};
|
||||
use maplit::btreemap;
|
||||
use ruma_identifiers::RoomVersionId;
|
||||
use ruma_serde::StringEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{from_value as from_json_value, to_value as to_json_value, Value as JsonValue};
|
||||
|
||||
use iter::{CapabilitiesIter, CapabilityRef};
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
pub mod get_capabilities;
|
54
crates/ruma-client-api/src/capabilities/get_capabilities.rs
Normal file
54
crates/ruma-client-api/src/capabilities/get_capabilities.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! `GET /_matrix/client/*/capabilities`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3capabilities
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use crate::capabilities::Capabilities;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Gets information about the server's supported feature set and other relevant capabilities.",
|
||||
method: GET,
|
||||
name: "get_capabilities",
|
||||
r0_path: "/_matrix/client/r0/capabilities",
|
||||
stable_path: "/_matrix/client/v3/capabilities",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// The capabilities the server supports
|
||||
pub capabilities: Capabilities,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given capabilities.
|
||||
pub fn new(capabilities: Capabilities) -> Self {
|
||||
Self { capabilities }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Capabilities> for Response {
|
||||
fn from(capabilities: Capabilities) -> Self {
|
||||
Self::new(capabilities)
|
||||
}
|
||||
}
|
||||
}
|
59
crates/ruma-client-api/src/config/get_global_account_data.rs
Normal file
59
crates/ruma-client-api/src/config/get_global_account_data.rs
Normal file
@ -0,0 +1,59 @@
|
||||
//! `GET /_matrix/client/*/user/{userId}/account_data/{type}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3useruseridaccount_datatype
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::AnyGlobalAccountDataEventContent;
|
||||
use ruma_identifiers::UserId;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Gets global account data for a user.",
|
||||
name: "get_global_account_data",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/account_data/:event_type",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/account_data/:event_type",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// User ID of user for whom to retrieve data.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// Type of data to retrieve.
|
||||
#[ruma_api(path)]
|
||||
pub event_type: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Account data content for the given type.
|
||||
///
|
||||
/// Use `ruma_events::RawExt` for deserialization.
|
||||
#[ruma_api(body)]
|
||||
pub account_data: Raw<AnyGlobalAccountDataEventContent>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID and event type.
|
||||
pub fn new(user_id: &'a UserId, event_type: &'a str) -> Self {
|
||||
Self { user_id, event_type }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given account data.
|
||||
pub fn new(account_data: Raw<AnyGlobalAccountDataEventContent>) -> Self {
|
||||
Self { account_data }
|
||||
}
|
||||
}
|
||||
}
|
63
crates/ruma-client-api/src/config/get_room_account_data.rs
Normal file
63
crates/ruma-client-api/src/config/get_room_account_data.rs
Normal file
@ -0,0 +1,63 @@
|
||||
//! `GET /_matrix/client/*/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3useruseridroomsroomidaccount_datatype
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::AnyRoomAccountDataEventContent;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use ruma_serde::Raw;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Gets account data room for a user for a given room",
|
||||
name: "get_room_account_data",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// User ID of user for whom to retrieve data.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// Room ID for which to retrieve data.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// Type of data to retrieve.
|
||||
#[ruma_api(path)]
|
||||
pub event_type: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Account data content for the given type.
|
||||
///
|
||||
/// Use `ruma_events::RawExt` for deserialization.
|
||||
#[ruma_api(body)]
|
||||
pub account_data: Raw<AnyRoomAccountDataEventContent>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID, room ID and event type.
|
||||
pub fn new(user_id: &'a UserId, room_id: &'a RoomId, event_type: &'a str) -> Self {
|
||||
Self { user_id, room_id, event_type }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given account data.
|
||||
pub fn new(account_data: Raw<AnyRoomAccountDataEventContent>) -> Self {
|
||||
Self { account_data }
|
||||
}
|
||||
}
|
||||
}
|
63
crates/ruma-client-api/src/config/set_global_account_data.rs
Normal file
63
crates/ruma-client-api/src/config/set_global_account_data.rs
Normal file
@ -0,0 +1,63 @@
|
||||
//! `PUT /_matrix/client/*/user/{userId}/account_data/{type}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridaccount_datatype
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Sets global account data.",
|
||||
method: PUT,
|
||||
name: "set_global_account_data",
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/account_data/:event_type",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/account_data/:event_type",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// 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: &'a UserId,
|
||||
|
||||
/// The event type of the account_data to set.
|
||||
///
|
||||
/// Custom types should be namespaced to avoid clashes.
|
||||
#[ruma_api(path)]
|
||||
pub event_type: &'a str,
|
||||
|
||||
/// Arbitrary JSON to store as config data.
|
||||
///
|
||||
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
||||
#[ruma_api(body)]
|
||||
pub data: &'a RawJsonValue,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given data, event type and user ID.
|
||||
pub fn new(data: &'a RawJsonValue, event_type: &'a str, user_id: &'a UserId) -> Self {
|
||||
Self { user_id, event_type, data }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
72
crates/ruma-client-api/src/config/set_room_account_data.rs
Normal file
72
crates/ruma-client-api/src/config/set_room_account_data.rs
Normal file
@ -0,0 +1,72 @@
|
||||
//! `PUT /_matrix/client/*/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3useruseridroomsroomidaccount_datatype
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Associate account data with a room.",
|
||||
method: PUT,
|
||||
name: "set_room_account_data",
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Arbitrary JSON to store as config data.
|
||||
///
|
||||
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
|
||||
#[ruma_api(body)]
|
||||
pub data: &'a RawJsonValue,
|
||||
|
||||
/// The event type of the account_data to set.
|
||||
///
|
||||
/// Custom types should be namespaced to avoid clashes.
|
||||
#[ruma_api(path)]
|
||||
pub event_type: &'a str,
|
||||
|
||||
/// The ID of the room to set account_data on.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a 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: &'a UserId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given data, event type, room ID and user ID.
|
||||
pub fn new(
|
||||
data: &'a RawJsonValue,
|
||||
event_type: &'a str,
|
||||
room_id: &'a RoomId,
|
||||
user_id: &'a UserId,
|
||||
) -> Self {
|
||||
Self { data, event_type, room_id, user_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
108
crates/ruma-client-api/src/context/get_context.rs
Normal file
108
crates/ruma-client-api/src/context/get_context.rs
Normal file
@ -0,0 +1,108 @@
|
||||
//! `GET /_matrix/client/*/rooms/{roomId}/context/{eventId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidcontexteventid
|
||||
|
||||
use js_int::{uint, UInt};
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::{AnyRoomEvent, AnyStateEvent};
|
||||
use ruma_identifiers::{EventId, RoomId};
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::filter::{IncomingRoomEventFilter, RoomEventFilter};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get the events immediately preceding and following a given event.",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/context/:event_id",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/context/:event_id",
|
||||
name: "get_context",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to get events from.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The event to get context around.
|
||||
#[ruma_api(path)]
|
||||
pub event_id: &'a EventId,
|
||||
|
||||
/// The maximum number of events to return.
|
||||
///
|
||||
/// Defaults to 10.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
|
||||
pub limit: UInt,
|
||||
|
||||
/// A RoomEventFilter to filter returned events with.
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_serde::json_string",
|
||||
default,
|
||||
skip_serializing_if = "RoomEventFilter::is_empty"
|
||||
)]
|
||||
pub filter: RoomEventFilter<'a>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// A token that can be used to paginate backwards with.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub start: Option<String>,
|
||||
|
||||
/// A token that can be used to paginate forwards with.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub end: Option<String>,
|
||||
|
||||
/// A list of room events that happened just before the requested event,
|
||||
/// in reverse-chronological order.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub events_before: Vec<Raw<AnyRoomEvent>>,
|
||||
|
||||
/// Details of the requested event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub event: Option<Raw<AnyRoomEvent>>,
|
||||
|
||||
/// A list of room events that happened just after the requested event,
|
||||
/// in chronological order.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub events_after: Vec<Raw<AnyRoomEvent>>,
|
||||
|
||||
/// The state of the room at the last event returned.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub state: Vec<Raw<AnyStateEvent>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id and event id.
|
||||
pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self {
|
||||
Self { room_id, event_id, limit: default_limit(), filter: RoomEventFilter::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_limit() -> UInt {
|
||||
uint!(10)
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn is_default_limit(val: &UInt) -> bool {
|
||||
*val == default_limit()
|
||||
}
|
||||
}
|
54
crates/ruma-client-api/src/device/delete_device.rs
Normal file
54
crates/ruma-client-api/src/device/delete_device.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! `DELETE /_matrix/client/*/devices/{deviceId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#delete_matrixclientv3devicesdeviceid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete a device for authenticated user.",
|
||||
method: DELETE,
|
||||
name: "delete_device",
|
||||
r0_path: "/_matrix/client/r0/devices/:device_id",
|
||||
stable_path: "/_matrix/client/v3/devices/:device_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The device to delete.
|
||||
#[ruma_api(path)]
|
||||
pub device_id: &'a DeviceId,
|
||||
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given device ID.
|
||||
pub fn new(device_id: &'a DeviceId) -> Self {
|
||||
Self { device_id, auth: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
53
crates/ruma-client-api/src/device/delete_devices.rs
Normal file
53
crates/ruma-client-api/src/device/delete_devices.rs
Normal file
@ -0,0 +1,53 @@
|
||||
//! `POST /_matrix/client/*/delete_devices`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3delete_devices
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Delete specified devices.",
|
||||
method: POST,
|
||||
r0_path: "/_matrix/client/r0/delete_devices",
|
||||
stable_path: "/_matrix/client/v3/delete_devices",
|
||||
name: "delete_devices",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// List of devices to delete.
|
||||
pub devices: &'a [Box<DeviceId>],
|
||||
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given device list.
|
||||
pub fn new(devices: &'a [Box<DeviceId>]) -> Self {
|
||||
Self { devices, auth: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
53
crates/ruma-client-api/src/device/get_device.rs
Normal file
53
crates/ruma-client-api/src/device/get_device.rs
Normal file
@ -0,0 +1,53 @@
|
||||
//! `GET /_matrix/client/*/devices/{deviceId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devicesdeviceid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
use crate::device::Device;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a device for authenticated user.",
|
||||
method: GET,
|
||||
name: "get_device",
|
||||
r0_path: "/_matrix/client/r0/devices/:device_id",
|
||||
stable_path: "/_matrix/client/v3/devices/:device_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The device to retrieve.
|
||||
#[ruma_api(path)]
|
||||
pub device_id: &'a DeviceId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Information about the device.
|
||||
#[ruma_api(body)]
|
||||
pub device: Device,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given device ID.
|
||||
pub fn new(device_id: &'a DeviceId) -> Self {
|
||||
Self { device_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given device.
|
||||
pub fn new(device: Device) -> Self {
|
||||
Self { device }
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/device/get_devices.rs
Normal file
48
crates/ruma-client-api/src/device/get_devices.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `GET /_matrix/client/*/devices`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devices
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use crate::device::Device;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get registered devices for authenticated user.",
|
||||
method: GET,
|
||||
name: "get_devices",
|
||||
r0_path: "/_matrix/client/r0/devices",
|
||||
stable_path: "/_matrix/client/v3/devices",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// A list of all registered devices for this user
|
||||
pub devices: Vec<Device>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given devices.
|
||||
pub fn new(devices: Vec<Device>) -> Self {
|
||||
Self { devices }
|
||||
}
|
||||
}
|
||||
}
|
54
crates/ruma-client-api/src/device/update_device.rs
Normal file
54
crates/ruma-client-api/src/device/update_device.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! `PUT /_matrix/client/*/devices/{deviceId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3devicesdeviceid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Update metadata for a device.",
|
||||
method: PUT,
|
||||
name: "update_device",
|
||||
r0_path: "/_matrix/client/r0/devices/:device_id",
|
||||
stable_path: "/_matrix/client/v3/devices/:device_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The device to update.
|
||||
#[ruma_api(path)]
|
||||
pub device_id: &'a DeviceId,
|
||||
|
||||
/// The new display name for this device.
|
||||
///
|
||||
/// If this is `None`, the display name won't be changed.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub display_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given device ID.
|
||||
pub fn new(device_id: &'a DeviceId) -> Self {
|
||||
Self { device_id, display_name: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
130
crates/ruma-client-api/src/directory/get_public_rooms.rs
Normal file
130
crates/ruma-client-api/src/directory/get_public_rooms.rs
Normal file
@ -0,0 +1,130 @@
|
||||
//! `GET /_matrix/client/*/publicRooms`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3publicrooms
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::directory::PublicRoomsChunk;
|
||||
use ruma_identifiers::ServerName;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get the list of rooms in this homeserver's public directory.",
|
||||
method: GET,
|
||||
name: "get_public_rooms",
|
||||
r0_path: "/_matrix/client/r0/publicRooms",
|
||||
stable_path: "/_matrix/client/v3/publicRooms",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// Limit for the number of results to return.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub limit: Option<UInt>,
|
||||
|
||||
/// Pagination token from a previous request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub since: Option<&'a str>,
|
||||
|
||||
/// The server to fetch the public room lists from.
|
||||
///
|
||||
/// `None` means the server this request is sent to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub server: Option<&'a ServerName>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
|
||||
/// A pagination token for the response.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_batch: Option<String>,
|
||||
|
||||
/// A pagination token that allows fetching previous results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_batch: Option<String>,
|
||||
|
||||
/// An estimate on the total number of public rooms, if the server has an estimate.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room list chunk.
|
||||
pub fn new(chunk: Vec<PublicRoomsChunk>) -> Self {
|
||||
Self { chunk, next_batch: None, prev_batch: None, total_room_count_estimate: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
||||
mod tests {
|
||||
use js_int::uint;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[test]
|
||||
fn construct_request_from_refs() {
|
||||
use ruma_api::{MatrixVersion, OutgoingRequest as _, SendAccessToken};
|
||||
use ruma_identifiers::server_name;
|
||||
|
||||
let req = super::Request {
|
||||
limit: Some(uint!(10)),
|
||||
since: Some("hello"),
|
||||
server: Some(server_name!("test.tld")),
|
||||
}
|
||||
.try_into_http_request::<Vec<u8>>(
|
||||
"https://homeserver.tld",
|
||||
SendAccessToken::IfRequired("auth_tok"),
|
||||
&[MatrixVersion::V1_1],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let uri = req.uri();
|
||||
let query = uri.query().unwrap();
|
||||
|
||||
assert_eq!(uri.path(), "/_matrix/client/v3/publicRooms");
|
||||
assert!(query.contains("since=hello"));
|
||||
assert!(query.contains("limit=10"));
|
||||
assert!(query.contains("server=test.tld"));
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
#[test]
|
||||
fn construct_response_from_refs() {
|
||||
use ruma_api::OutgoingResponse as _;
|
||||
|
||||
let res = super::Response {
|
||||
chunk: vec![],
|
||||
next_batch: Some("next_batch_token".into()),
|
||||
prev_batch: Some("prev_batch_token".into()),
|
||||
total_room_count_estimate: Some(uint!(10)),
|
||||
}
|
||||
.try_into_http_response::<Vec<u8>>()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(res.body()),
|
||||
r#"{"chunk":[],"next_batch":"next_batch_token","prev_batch":"prev_batch_token","total_room_count_estimate":10}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
//! `POST /_matrix/client/*/publicRooms`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3publicrooms
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::directory::{
|
||||
Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork,
|
||||
};
|
||||
use ruma_identifiers::ServerName;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get the list of rooms in this homeserver's public directory.",
|
||||
method: POST,
|
||||
name: "get_public_rooms_filtered",
|
||||
r0_path: "/_matrix/client/r0/publicRooms",
|
||||
stable_path: "/_matrix/client/v3/publicRooms",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// The server to fetch the public room lists from.
|
||||
///
|
||||
/// `None` means the server this request is sent to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub server: Option<&'a ServerName>,
|
||||
|
||||
/// Limit for the number of results to return.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub limit: Option<UInt>,
|
||||
|
||||
/// Pagination token from a previous request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub since: Option<&'a str>,
|
||||
|
||||
/// Filter to apply to the results.
|
||||
#[serde(default, skip_serializing_if = "Filter::is_empty")]
|
||||
pub filter: Filter<'a>,
|
||||
|
||||
/// Network to fetch the public room lists from.
|
||||
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub room_network: RoomNetwork<'a>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
|
||||
/// A pagination token for the response.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_batch: Option<String>,
|
||||
|
||||
/// A pagination token that allows fetching previous results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_batch: Option<String>,
|
||||
|
||||
/// An estimate on the total number of public rooms, if the server has an estimate.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request<'_> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
52
crates/ruma-client-api/src/directory/get_room_visibility.rs
Normal file
52
crates/ruma-client-api/src/directory/get_room_visibility.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! `GET /_matrix/client/*/directory/list/room/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3directorylistroomroomid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::room::Visibility;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get the visibility of a public room on a directory.",
|
||||
name: "get_room_visibility",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/client/r0/directory/list/room/:room_id",
|
||||
stable_path: "/_matrix/client/v3/directory/list/room/:room_id",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The ID of the room of which to request the visibility.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Visibility of the room.
|
||||
pub visibility: Visibility,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given visibility.
|
||||
pub fn new(visibility: Visibility) -> Self {
|
||||
Self { visibility }
|
||||
}
|
||||
}
|
||||
}
|
53
crates/ruma-client-api/src/directory/set_room_visibility.rs
Normal file
53
crates/ruma-client-api/src/directory/set_room_visibility.rs
Normal file
@ -0,0 +1,53 @@
|
||||
//! `PUT /_matrix/client/*/directory/list/room/{roomId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3directorylistroomroomid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::room::Visibility;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Set the visibility of a public room on a directory.",
|
||||
name: "set_room_visibility",
|
||||
method: PUT,
|
||||
r0_path: "/_matrix/client/r0/directory/list/room/:room_id",
|
||||
stable_path: "/_matrix/client/v3/directory/list/room/:room_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The ID of the room of which to set the visibility.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// New visibility setting for the room.
|
||||
pub visibility: Visibility,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID and visibility.
|
||||
pub fn new(room_id: &'a RoomId, visibility: Visibility) -> Self {
|
||||
Self { room_id, visibility }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
//! [GET /.well-known/matrix/client](https://matrix.org/docs/spec/client_server/r0.6.1#get-well-known-matrix-client)
|
||||
//! `GET /.well-known/matrix/client` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#getwell-knownmatrixclient
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -7,7 +9,7 @@ ruma_api! {
|
||||
metadata: {
|
||||
description: "Get discovery information about the domain.",
|
||||
method: GET,
|
||||
name: "discover_homeserver",
|
||||
name: "client_well_known",
|
||||
stable_path: "/.well-known/matrix/client",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
@ -1,4 +1,6 @@
|
||||
//! [GET /_matrix/client/versions](https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-versions)
|
||||
//! `GET /_matrix/client/versions` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientversions
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -6,13 +6,12 @@ pub mod get_filter;
|
||||
mod lazy_load;
|
||||
mod url;
|
||||
|
||||
pub use lazy_load::LazyLoadOptions;
|
||||
pub use url::UrlFilter;
|
||||
|
||||
use js_int::UInt;
|
||||
pub use lazy_load::LazyLoadOptions;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use ruma_serde::{Outgoing, StringEnum};
|
||||
use serde::Serialize;
|
||||
pub use url::UrlFilter;
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
103
crates/ruma-client-api/src/filter/create_filter.rs
Normal file
103
crates/ruma-client-api/src/filter/create_filter.rs
Normal file
@ -0,0 +1,103 @@
|
||||
//! `POST /_matrix/client/*/user/{userId}/filter`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridfilter
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
use crate::filter::{FilterDefinition, IncomingFilterDefinition};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Create a new filter for event retrieval.",
|
||||
method: POST,
|
||||
name: "create_filter",
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/filter",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/filter",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// 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: &'a UserId,
|
||||
|
||||
/// The filter definition.
|
||||
#[ruma_api(body)]
|
||||
pub filter: FilterDefinition<'a>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The ID of the filter that was created.
|
||||
pub filter_id: String,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID and filter definition.
|
||||
pub fn new(user_id: &'a UserId, filter: FilterDefinition<'a>) -> Self {
|
||||
Self { user_id, filter }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given filter ID.
|
||||
pub fn new(filter_id: String) -> Self {
|
||||
Self { filter_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
||||
mod tests {
|
||||
use matches::assert_matches;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
#[test]
|
||||
fn deserialize_request() {
|
||||
use ruma_api::IncomingRequest as _;
|
||||
|
||||
use super::IncomingRequest;
|
||||
|
||||
assert_matches!(
|
||||
IncomingRequest::try_from_http_request(
|
||||
http::Request::builder()
|
||||
.method(http::Method::POST)
|
||||
.uri("https://matrix.org/_matrix/client/r0/user/@foo:bar.com/filter")
|
||||
.body(b"{}" as &[u8])
|
||||
.unwrap(),
|
||||
&["@foo:bar.com"]
|
||||
),
|
||||
Ok(IncomingRequest { user_id, filter })
|
||||
if user_id == "@foo:bar.com" && filter.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[test]
|
||||
fn serialize_request() {
|
||||
use ruma_api::{MatrixVersion, OutgoingRequest, SendAccessToken};
|
||||
use ruma_identifiers::user_id;
|
||||
|
||||
use crate::filter::FilterDefinition;
|
||||
|
||||
assert_matches!(
|
||||
super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default())
|
||||
.try_into_http_request::<Vec<u8>>(
|
||||
"https://matrix.org",
|
||||
SendAccessToken::IfRequired("tok"),
|
||||
&[MatrixVersion::V1_1]
|
||||
),
|
||||
Ok(res) if res.body() == b"{}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
89
crates/ruma-client-api/src/filter/get_filter.rs
Normal file
89
crates/ruma-client-api/src/filter/get_filter.rs
Normal file
@ -0,0 +1,89 @@
|
||||
//! `GET /_matrix/client/*/user/{userId}/filter/{filterId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3useruseridfilterfilterid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
use crate::filter::IncomingFilterDefinition;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve a previously created filter.",
|
||||
method: GET,
|
||||
name: "get_filter",
|
||||
r0_path: "/_matrix/client/r0/user/:user_id/filter/:filter_id",
|
||||
stable_path: "/_matrix/client/v3/user/:user_id/filter/:filter_id",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The user ID to download a filter for.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The ID of the filter to download.
|
||||
#[ruma_api(path)]
|
||||
pub filter_id: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The filter definition.
|
||||
#[ruma_api(body)]
|
||||
pub filter: IncomingFilterDefinition,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID and filter ID.
|
||||
pub fn new(user_id: &'a UserId, filter_id: &'a str) -> Self {
|
||||
Self { user_id, filter_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given filter definition.
|
||||
pub fn new(filter: IncomingFilterDefinition) -> Self {
|
||||
Self { filter }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, any(feature = "client", feature = "server")))]
|
||||
mod tests {
|
||||
use matches::assert_matches;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[test]
|
||||
fn deserialize_response() {
|
||||
use ruma_api::IncomingResponse;
|
||||
|
||||
assert_matches!(
|
||||
super::Response::try_from_http_response(
|
||||
http::Response::builder().body(b"{}" as &[u8]).unwrap(),
|
||||
),
|
||||
Ok(super::Response { filter }) if filter.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
#[test]
|
||||
fn serialize_response() {
|
||||
use ruma_api::OutgoingResponse;
|
||||
|
||||
use crate::filter::IncomingFilterDefinition;
|
||||
|
||||
assert_matches!(
|
||||
super::Response::new(IncomingFilterDefinition::default())
|
||||
.try_into_http_response::<Vec<u8>>(),
|
||||
Ok(res) if res.body() == b"{}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
72
crates/ruma-client-api/src/keys/claim_keys.rs
Normal file
72
crates/ruma-client-api/src/keys/claim_keys.rs
Normal file
@ -0,0 +1,72 @@
|
||||
//! `POST /_matrix/client/*/keys/claim`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysclaim
|
||||
|
||||
use std::{collections::BTreeMap, time::Duration};
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::encryption::OneTimeKey;
|
||||
use ruma_identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId};
|
||||
use ruma_serde::Raw;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Claims one-time keys for use in pre-key messages.",
|
||||
method: POST,
|
||||
name: "claim_keys",
|
||||
r0_path: "/_matrix/client/r0/keys/claim",
|
||||
stable_path: "/_matrix/client/v3/keys/claim",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The time (in milliseconds) to wait when downloading keys from remote servers.
|
||||
/// 10 seconds is the recommended default.
|
||||
#[serde(
|
||||
with = "ruma_serde::duration::opt_ms",
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
)]
|
||||
pub timeout: Option<Duration>,
|
||||
|
||||
/// The keys to be claimed.
|
||||
pub one_time_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// If any remote homeservers could not be reached, they are recorded here.
|
||||
/// The names of the properties are the names of the unreachable servers.
|
||||
pub failures: BTreeMap<String, JsonValue>,
|
||||
|
||||
/// One-time keys for the queried devices.
|
||||
pub one_time_keys: BTreeMap<Box<UserId>, OneTimeKeys>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given key claims and the recommended 10 second timeout.
|
||||
pub fn new(
|
||||
one_time_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
|
||||
) -> Self {
|
||||
Self { timeout: Some(Duration::from_secs(10)), one_time_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given keys and no failures.
|
||||
pub fn new(one_time_keys: BTreeMap<Box<UserId>, OneTimeKeys>) -> Self {
|
||||
Self { failures: BTreeMap::new(), one_time_keys }
|
||||
}
|
||||
}
|
||||
|
||||
/// The one-time keys for a given device.
|
||||
pub type OneTimeKeys = BTreeMap<Box<DeviceId>, BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>;
|
||||
}
|
63
crates/ruma-client-api/src/keys/get_key_changes.rs
Normal file
63
crates/ruma-client-api/src/keys/get_key_changes.rs
Normal file
@ -0,0 +1,63 @@
|
||||
//! `GET /_matrix/client/*/keys/changes`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3keyschanges
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Gets a list of users who have updated their device identity keys since a previous sync token.",
|
||||
method: GET,
|
||||
name: "get_key_changes",
|
||||
r0_path: "/_matrix/client/r0/keys/changes",
|
||||
stable_path: "/_matrix/client/v3/keys/changes",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The desired start point of the list.
|
||||
///
|
||||
/// Should be the next_batch field from a response to an earlier call to /sync.
|
||||
#[ruma_api(query)]
|
||||
pub from: &'a str,
|
||||
|
||||
/// The desired end point of the list.
|
||||
///
|
||||
/// Should be the next_batch field from a recent call to /sync - typically the most recent
|
||||
/// such call.
|
||||
#[ruma_api(query)]
|
||||
pub to: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The Matrix User IDs of all users who updated their device identity keys.
|
||||
pub changed: Vec<Box<UserId>>,
|
||||
|
||||
/// The Matrix User IDs of all users who may have left all the end-to-end
|
||||
/// encrypted rooms they previously shared with the user.
|
||||
pub left: Vec<Box<UserId>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given start and end points.
|
||||
pub fn new(from: &'a str, to: &'a str) -> Self {
|
||||
Self { from, to }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given changed and left user ID lists.
|
||||
pub fn new(changed: Vec<Box<UserId>>, left: Vec<Box<UserId>>) -> Self {
|
||||
Self { changed, left }
|
||||
}
|
||||
}
|
||||
}
|
95
crates/ruma-client-api/src/keys/get_keys.rs
Normal file
95
crates/ruma-client-api/src/keys/get_keys.rs
Normal file
@ -0,0 +1,95 @@
|
||||
//! `POST /_matrix/client/*/keys/query`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysquery
|
||||
|
||||
use std::{collections::BTreeMap, time::Duration};
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::encryption::{CrossSigningKey, DeviceKeys};
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
use ruma_serde::Raw;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Returns the current devices and identity keys for the given users.",
|
||||
method: POST,
|
||||
name: "get_keys",
|
||||
r0_path: "/_matrix/client/r0/keys/query",
|
||||
stable_path: "/_matrix/client/v3/keys/query",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// The time (in milliseconds) to wait when downloading keys from remote servers.
|
||||
///
|
||||
/// 10 seconds is the recommended default.
|
||||
#[serde(
|
||||
with = "ruma_serde::duration::opt_ms",
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
)]
|
||||
pub timeout: Option<Duration>,
|
||||
|
||||
/// The keys to be downloaded.
|
||||
///
|
||||
/// An empty list indicates all devices for the corresponding user.
|
||||
pub device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>,
|
||||
|
||||
/// If the client is fetching keys as a result of a device update received in a sync
|
||||
/// request, this should be the 'since' token of that sync request, or any later sync token.
|
||||
///
|
||||
/// This allows the server to ensure its response contains the keys advertised by the
|
||||
/// notification in that sync.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub token: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// If any remote homeservers could not be reached, they are recorded here.
|
||||
///
|
||||
/// The names of the properties are the names of the unreachable servers.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub failures: BTreeMap<String, JsonValue>,
|
||||
|
||||
/// Information on the queried devices.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, Raw<DeviceKeys>>>,
|
||||
|
||||
/// Information on the master cross-signing keys of the queried users.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub master_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
|
||||
|
||||
/// Information on the self-signing keys of the queried users.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub self_signing_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
|
||||
|
||||
/// Information on the user-signing keys of the queried users.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub user_signing_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request<'_> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
67
crates/ruma-client-api/src/keys/upload_keys.rs
Normal file
67
crates/ruma-client-api/src/keys/upload_keys.rs
Normal file
@ -0,0 +1,67 @@
|
||||
//! `POST /_matrix/client/*/keys/upload`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysupload
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::encryption::{DeviceKeys, OneTimeKey};
|
||||
use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId};
|
||||
use ruma_serde::Raw;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Publishes end-to-end encryption keys for the device.",
|
||||
method: POST,
|
||||
name: "upload_keys",
|
||||
r0_path: "/_matrix/client/r0/keys/upload",
|
||||
stable_path: "/_matrix/client/v3/keys/upload",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// Identity keys for the device.
|
||||
///
|
||||
/// May be absent if no new identity keys are required.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub device_keys: Option<Raw<DeviceKeys>>,
|
||||
|
||||
/// One-time public keys for "pre-key" messages.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub one_time_keys: BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>,
|
||||
|
||||
/// Fallback public keys for "pre-key" messages.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty", rename = "org.matrix.msc2732.fallback_keys")]
|
||||
pub fallback_keys: BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// For each key algorithm, the number of unclaimed one-time keys of that
|
||||
/// type currently held on the server for this device.
|
||||
pub one_time_key_counts: BTreeMap<DeviceKeyAlgorithm, UInt>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given one time key counts.
|
||||
pub fn new(one_time_key_counts: BTreeMap<DeviceKeyAlgorithm, UInt>) -> Self {
|
||||
Self { one_time_key_counts }
|
||||
}
|
||||
}
|
||||
}
|
107
crates/ruma-client-api/src/keys/upload_signatures.rs
Normal file
107
crates/ruma-client-api/src/keys/upload_signatures.rs
Normal file
@ -0,0 +1,107 @@
|
||||
//! `POST /_matrix/client/*/keys/signatures/upload`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keyssignaturesupload
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::encryption::{CrossSigningKey, DeviceKeys};
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
use ruma_serde::{Raw, StringEnum};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Publishes cross-signing signatures for the user.",
|
||||
method: POST,
|
||||
name: "upload_signatures",
|
||||
unstable_path: "/_matrix/client/unstable/keys/signatures/upload",
|
||||
stable_path: "/_matrix/client/v3/keys/signatures/upload",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// Signed keys.
|
||||
#[ruma_api(body)]
|
||||
pub signed_keys: BTreeMap<Box<UserId>, SignedKeys>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// Signature processing failures.
|
||||
pub failures: BTreeMap<Box<UserId>, BTreeMap<String, Failure>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given signed keys.
|
||||
pub fn new(signed_keys: BTreeMap<Box<UserId>, SignedKeys>) -> Self {
|
||||
Self { signed_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A map of key IDs to signed key objects.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct SignedKeys(BTreeMap<Box<str>, Box<RawJsonValue>>);
|
||||
|
||||
impl SignedKeys {
|
||||
/// Creates an empty `SignedKeys` map.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Add the given device keys.
|
||||
pub fn add_device_keys(&mut self, device_id: Box<DeviceId>, device_keys: Raw<DeviceKeys>) {
|
||||
self.0.insert(device_id.into(), device_keys.into_json());
|
||||
}
|
||||
|
||||
/// Add the given cross signing keys.
|
||||
pub fn add_cross_signing_keys(
|
||||
&mut self,
|
||||
cross_signing_key_id: Box<str>,
|
||||
cross_signing_keys: Raw<CrossSigningKey>,
|
||||
) {
|
||||
self.0.insert(cross_signing_key_id, cross_signing_keys.into_json());
|
||||
}
|
||||
}
|
||||
|
||||
/// A failure to process a signed key.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Failure {
|
||||
/// Machine-readable error code.
|
||||
errcode: FailureErrorCode,
|
||||
|
||||
/// Human-readable error message.
|
||||
error: String,
|
||||
}
|
||||
|
||||
/// Error code for signed key processing failures.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[non_exhaustive]
|
||||
#[ruma_enum(rename_all = "M_MATRIX_ERROR_CASE")]
|
||||
pub enum FailureErrorCode {
|
||||
/// The signature is invalid.
|
||||
InvalidSignature,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
}
|
70
crates/ruma-client-api/src/keys/upload_signing_keys.rs
Normal file
70
crates/ruma-client-api/src/keys/upload_signing_keys.rs
Normal file
@ -0,0 +1,70 @@
|
||||
//! `POST /_matrix/client/*/keys/device_signing/upload`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3keysdevice_signingupload
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::encryption::CrossSigningKey;
|
||||
use ruma_serde::Raw;
|
||||
|
||||
use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Publishes cross signing keys for the user.",
|
||||
method: POST,
|
||||
name: "upload_signing_keys",
|
||||
unstable_path: "/_matrix/client/unstable/keys/device_signing/upload",
|
||||
stable_path: "/_matrix/client/v3/keys/device_signing/upload",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth: Option<AuthData<'a>>,
|
||||
|
||||
/// The user's master key.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub master_key: Option<Raw<CrossSigningKey>>,
|
||||
|
||||
/// The user's self-signing key.
|
||||
///
|
||||
/// Must be signed with the accompanied master, or by the user's most recently uploaded
|
||||
/// master key if no master key is included in the request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub self_signing_key: Option<Raw<CrossSigningKey>>,
|
||||
|
||||
/// The user's user-signing key.
|
||||
///
|
||||
/// Must be signed with the accompanied master, or by the user's most recently uploaded
|
||||
/// master key if no master key is included in the request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub user_signing_key: Option<Raw<CrossSigningKey>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: UiaaResponse
|
||||
}
|
||||
|
||||
impl Request<'_> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
59
crates/ruma-client-api/src/knock/knock_room.rs
Normal file
59
crates/ruma-client-api/src/knock/knock_room.rs
Normal file
@ -0,0 +1,59 @@
|
||||
//! `POST /_matrix/client/*/knock/{roomIdOrAlias}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3knockroomidoralias
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, RoomOrAliasId, ServerName};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Knock on a room.",
|
||||
method: POST,
|
||||
name: "knock_room",
|
||||
unstable_path: "/_matrix/client/unstable/xyz.amorgan.knock/knock/:room_id_or_alias",
|
||||
stable_path: "/_matrix/client/v3/knock/:room_id_or_alias",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.1,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room the user should knock on.
|
||||
#[ruma_api(path)]
|
||||
pub room_id_or_alias: &'a RoomOrAliasId,
|
||||
|
||||
/// The reason for joining a room.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
|
||||
/// The servers to attempt to knock on the room through.
|
||||
///
|
||||
/// One of the servers must be participating in the room.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub server_name: &'a [Box<ServerName>],
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room that the user knocked on.
|
||||
pub room_id: Box<RoomId>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID or alias.
|
||||
pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self {
|
||||
Self { room_id_or_alias, reason: None, server_name: &[] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room ID.
|
||||
pub fn new(room_id: Box<RoomId>) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
}
|
@ -3,15 +3,47 @@
|
||||
//! (De)serializable types for the [Matrix Client-Server API][client-api].
|
||||
//! These types can be shared by client and server code.
|
||||
//!
|
||||
//! [client-api]: https://matrix.org/docs/spec/client_server/r0.6.1.html
|
||||
//! [client-api]: https://spec.matrix.org/v1.2/client-server-api/
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
|
||||
pub mod account;
|
||||
pub mod alias;
|
||||
pub mod appservice;
|
||||
pub mod backup;
|
||||
pub mod capabilities;
|
||||
pub mod config;
|
||||
pub mod context;
|
||||
pub mod device;
|
||||
pub mod directory;
|
||||
pub mod discover;
|
||||
pub mod error;
|
||||
pub mod r0;
|
||||
pub mod filter;
|
||||
pub mod keys;
|
||||
pub mod knock;
|
||||
pub mod media;
|
||||
pub mod membership;
|
||||
pub mod message;
|
||||
pub mod presence;
|
||||
pub mod profile;
|
||||
pub mod push;
|
||||
pub mod read_marker;
|
||||
pub mod receipt;
|
||||
pub mod redact;
|
||||
pub mod room;
|
||||
pub mod search;
|
||||
pub mod server;
|
||||
pub mod session;
|
||||
pub mod unversioned;
|
||||
pub mod state;
|
||||
pub mod sync;
|
||||
pub mod tag;
|
||||
pub mod thirdparty;
|
||||
pub mod to_device;
|
||||
pub mod typing;
|
||||
pub mod uiaa;
|
||||
pub mod user_directory;
|
||||
pub mod voip;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
86
crates/ruma-client-api/src/media/create_content.rs
Normal file
86
crates/ruma-client-api/src/media/create_content.rs
Normal file
@ -0,0 +1,86 @@
|
||||
//! `POST /_matrix/media/*/upload`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixmediav3upload
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::MxcUri;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Upload content to the media store.",
|
||||
method: POST,
|
||||
name: "create_media_content",
|
||||
r0_path: "/_matrix/media/r0/upload",
|
||||
stable_path: "/_matrix/media/v3/upload",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The file contents to upload.
|
||||
#[ruma_api(raw_body)]
|
||||
pub file: &'a [u8],
|
||||
|
||||
/// The name of the file being uploaded.
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub filename: Option<&'a str>,
|
||||
|
||||
/// The content type of the file being uploaded.
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub content_type: Option<&'a str>,
|
||||
|
||||
/// Should the server return a blurhash or not.
|
||||
///
|
||||
/// This uses the unstable prefix in
|
||||
/// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448).
|
||||
#[ruma_api(query)]
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default", rename = "xyz.amorgan.blurhash")]
|
||||
pub generate_blurhash: bool,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The MXC URI for the uploaded content.
|
||||
pub content_uri: Box<MxcUri>,
|
||||
|
||||
/// The [BlurHash](https://blurha.sh) for the uploaded content.
|
||||
///
|
||||
/// This uses the unstable prefix in
|
||||
/// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448).
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
#[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")]
|
||||
pub blurhash: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given file contents.
|
||||
pub fn new(file: &'a [u8]) -> Self {
|
||||
Self {
|
||||
file,
|
||||
filename: None,
|
||||
content_type: None,
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
generate_blurhash: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given MXC URI.
|
||||
pub fn new(content_uri: Box<MxcUri>) -> Self {
|
||||
Self {
|
||||
content_uri,
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
blurhash: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
crates/ruma-client-api/src/media/get_content.rs
Normal file
82
crates/ruma-client-api/src/media/get_content.rs
Normal file
@ -0,0 +1,82 @@
|
||||
//! `GET /_matrix/media/*/download/{serverName}/{mediaId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3downloadservernamemediaid
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{Error, MxcUri, ServerName};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve content from the media store.",
|
||||
method: GET,
|
||||
name: "get_media_content",
|
||||
r0_path: "/_matrix/media/r0/download/:server_name/:media_id",
|
||||
stable_path: "/_matrix/media/v3/download/:server_name/:media_id",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The media ID from the mxc:// URI (the path component).
|
||||
#[ruma_api(path)]
|
||||
pub media_id: &'a str,
|
||||
|
||||
/// The server name from the mxc:// URI (the authoritory component).
|
||||
#[ruma_api(path)]
|
||||
pub server_name: &'a ServerName,
|
||||
|
||||
/// Whether to fetch media deemed remote.
|
||||
///
|
||||
/// Used to prevent routing loops. Defaults to `true`.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default = "ruma_serde::default_true", skip_serializing_if = "ruma_serde::is_true")]
|
||||
pub allow_remote: bool,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The content that was previously uploaded.
|
||||
#[ruma_api(raw_body)]
|
||||
pub file: Vec<u8>,
|
||||
|
||||
/// The content type of the file that was previously uploaded.
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub content_type: Option<String>,
|
||||
|
||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||
/// file that was previously uploaded.
|
||||
///
|
||||
/// See [MDN] for the syntax.
|
||||
///
|
||||
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||
pub content_disposition: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given media ID and server name.
|
||||
pub fn new(media_id: &'a str, server_name: &'a ServerName) -> Self {
|
||||
Self { media_id, server_name, allow_remote: true }
|
||||
}
|
||||
|
||||
/// Creates a new `Request` with the given url.
|
||||
pub fn from_url(url: &'a MxcUri) -> Result<Self, Error> {
|
||||
let (server_name, media_id) = url.parts()?;
|
||||
|
||||
Ok(Self { media_id, server_name, allow_remote: true })
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given file contents.
|
||||
pub fn new(file: Vec<u8>) -> Self {
|
||||
Self { file, content_type: None, content_disposition: None }
|
||||
}
|
||||
}
|
||||
}
|
87
crates/ruma-client-api/src/media/get_content_as_filename.rs
Normal file
87
crates/ruma-client-api/src/media/get_content_as_filename.rs
Normal file
@ -0,0 +1,87 @@
|
||||
//! `GET /_matrix/media/*/download/{serverName}/{mediaId}/{fileName}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{Error, MxcUri, ServerName};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Retrieve content from the media store, specifying a filename to return.",
|
||||
method: GET,
|
||||
name: "get_media_content_as_filename",
|
||||
r0_path: "/_matrix/media/r0/download/:server_name/:media_id/:filename",
|
||||
stable_path: "/_matrix/media/v3/download/:server_name/:media_id/:filename",
|
||||
rate_limited: false,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The media ID from the mxc:// URI (the path component).
|
||||
#[ruma_api(path)]
|
||||
pub media_id: &'a str,
|
||||
|
||||
/// The server name from the mxc:// URI (the authoritory component).
|
||||
#[ruma_api(path)]
|
||||
pub server_name: &'a ServerName,
|
||||
|
||||
/// The filename to return in the `Content-Disposition` header.
|
||||
#[ruma_api(path)]
|
||||
pub filename: &'a str,
|
||||
|
||||
/// Whether to fetch media deemed remote.
|
||||
///
|
||||
/// Used to prevent routing loops. Defaults to `true`.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default = "ruma_serde::default_true", skip_serializing_if = "ruma_serde::is_true")]
|
||||
pub allow_remote: bool,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The content that was previously uploaded.
|
||||
#[ruma_api(raw_body)]
|
||||
pub file: Vec<u8>,
|
||||
|
||||
/// The content type of the file that was previously uploaded.
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
// Potentially not actually optional – https://github.com/matrix-org/matrix-doc/pull/2818
|
||||
pub content_type: Option<String>,
|
||||
|
||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||
/// file that was previously uploaded.
|
||||
///
|
||||
/// See [MDN] for the syntax.
|
||||
///
|
||||
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||
pub content_disposition: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given media ID, server name and filename.
|
||||
pub fn new(media_id: &'a str, server_name: &'a ServerName, filename: &'a str) -> Self {
|
||||
Self { media_id, server_name, filename, allow_remote: true }
|
||||
}
|
||||
|
||||
/// Creates a new `Request` with the given url and filename.
|
||||
pub fn from_url(url: &'a MxcUri, filename: &'a str) -> Result<Self, Error> {
|
||||
let (server_name, media_id) = url.parts()?;
|
||||
|
||||
Ok(Self { media_id, server_name, filename, allow_remote: true })
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given file.
|
||||
pub fn new(file: Vec<u8>) -> Self {
|
||||
Self { file, content_type: None, content_disposition: None }
|
||||
}
|
||||
}
|
||||
}
|
126
crates/ruma-client-api/src/media/get_content_thumbnail.rs
Normal file
126
crates/ruma-client-api/src/media/get_content_thumbnail.rs
Normal file
@ -0,0 +1,126 @@
|
||||
//! `GET /_matrix/media/*/thumbnail/{serverName}/{mediaId}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{Error, MxcUri, ServerName};
|
||||
use ruma_serde::StringEnum;
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a thumbnail of content from the media store.",
|
||||
method: GET,
|
||||
name: "get_content_thumbnail",
|
||||
r0_path: "/_matrix/media/r0/thumbnail/:server_name/:media_id",
|
||||
stable_path: "/_matrix/media/v3/thumbnail/:server_name/:media_id",
|
||||
rate_limited: true,
|
||||
authentication: None,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The media ID from the mxc:// URI (the path component).
|
||||
#[ruma_api(path)]
|
||||
pub media_id: &'a str,
|
||||
|
||||
/// The server name from the mxc:// URI (the authoritory component).
|
||||
#[ruma_api(path)]
|
||||
pub server_name: &'a ServerName,
|
||||
|
||||
/// The desired resizing method.
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub method: Option<Method>,
|
||||
|
||||
/// The *desired* width of the thumbnail.
|
||||
///
|
||||
/// The actual thumbnail may not match the size specified.
|
||||
#[ruma_api(query)]
|
||||
pub width: UInt,
|
||||
|
||||
/// The *desired* height of the thumbnail.
|
||||
///
|
||||
/// The actual thumbnail may not match the size specified.
|
||||
#[ruma_api(query)]
|
||||
pub height: UInt,
|
||||
|
||||
/// Whether to fetch media deemed remote.
|
||||
///
|
||||
/// Used to prevent routing loops. Defaults to `true`.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default = "ruma_serde::default_true", skip_serializing_if = "ruma_serde::is_true")]
|
||||
pub allow_remote: bool,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A thumbnail of the requested content.
|
||||
#[ruma_api(raw_body)]
|
||||
pub file: Vec<u8>,
|
||||
|
||||
/// The content type of the thumbnail.
|
||||
#[ruma_api(header = CONTENT_TYPE)]
|
||||
pub content_type: Option<String>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given media ID, server name, desired thumbnail width
|
||||
/// and desired thumbnail height.
|
||||
pub fn new(
|
||||
media_id: &'a str,
|
||||
server_name: &'a ServerName,
|
||||
width: UInt,
|
||||
height: UInt,
|
||||
) -> Self {
|
||||
Self { media_id, server_name, method: None, width, height, allow_remote: true }
|
||||
}
|
||||
|
||||
/// Creates a new `Request` with the given url, desired thumbnail width and
|
||||
/// desired thumbnail height.
|
||||
pub fn from_url(url: &'a MxcUri, width: UInt, height: UInt) -> Result<Self, Error> {
|
||||
let (server_name, media_id) = url.parts()?;
|
||||
|
||||
Ok(Self { media_id, server_name, method: None, width, height, allow_remote: true })
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given thumbnail.
|
||||
pub fn new(file: Vec<u8>) -> Self {
|
||||
Self { file, content_type: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The desired resizing method.
|
||||
///
|
||||
/// This type can hold an arbitrary string. To check for formats that are not available as a
|
||||
/// documented variant here, use its string representation, obtained through `.as_str()`.
|
||||
#[derive(Clone, Debug, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum Method {
|
||||
/// Crop the original to produce the requested image dimensions.
|
||||
Crop,
|
||||
|
||||
/// Maintain the original aspect ratio of the source image.
|
||||
Scale,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Method {
|
||||
/// Creates a string slice from this `Method`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/media/get_media_config.rs
Normal file
48
crates/ruma-client-api/src/media/get_media_config.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `GET /_matrix/media/*/config`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3config
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Gets the config for the media repository.",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/media/r0/config",
|
||||
stable_path: "/_matrix/media/v3/config",
|
||||
name: "get_media_config",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// Maximum size of upload in bytes.
|
||||
#[serde(rename = "m.upload.size")]
|
||||
pub upload_size: UInt,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given maximum upload size.
|
||||
pub fn new(upload_size: UInt) -> Self {
|
||||
Self { upload_size }
|
||||
}
|
||||
}
|
||||
}
|
101
crates/ruma-client-api/src/media/get_media_preview.rs
Normal file
101
crates/ruma-client-api/src/media/get_media_preview.rs
Normal file
@ -0,0 +1,101 @@
|
||||
//! `GET /_matrix/media/*/preview_url`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3preview_url
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||
use serde::Serialize;
|
||||
use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a preview for a URL.",
|
||||
name: "get_media_preview",
|
||||
method: GET,
|
||||
r0_path: "/_matrix/media/r0/preview_url",
|
||||
stable_path: "/_matrix/media/v3/preview_url",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// URL to get a preview of.
|
||||
#[ruma_api(query)]
|
||||
pub url: &'a str,
|
||||
|
||||
/// Preferred point in time (in milliseconds) to return a preview for.
|
||||
#[ruma_api(query)]
|
||||
pub ts: MilliSecondsSinceUnixEpoch,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {
|
||||
/// OpenGraph-like data for the URL.
|
||||
///
|
||||
/// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size`
|
||||
/// field, and `og:image` returns the MXC URI to the image, if any.
|
||||
#[ruma_api(body)]
|
||||
pub data: Option<Box<RawJsonValue>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given url and timestamp.
|
||||
pub fn new(url: &'a str, ts: MilliSecondsSinceUnixEpoch) -> Self {
|
||||
Self { url, ts }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self { data: None }
|
||||
}
|
||||
|
||||
/// Creates a new `Response` with the given OpenGraph data (in a
|
||||
/// `serde_json::value::RawValue`).
|
||||
pub fn from_raw_value(data: Box<RawJsonValue>) -> Self {
|
||||
Self { data: Some(data) }
|
||||
}
|
||||
|
||||
/// Creates a new `Response` with the given OpenGraph data (in any kind of serializable
|
||||
/// object).
|
||||
pub fn from_serialize<T: Serialize>(data: &T) -> serde_json::Result<Self> {
|
||||
Ok(Self { data: Some(to_raw_json_value(data)?) })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::{
|
||||
from_value as from_json_value, json,
|
||||
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},
|
||||
};
|
||||
|
||||
// Since BTreeMap<String, Box<RawJsonValue>> deserialization doesn't seem to
|
||||
// work, test that Option<RawJsonValue> works
|
||||
#[test]
|
||||
fn raw_json_deserialize() {
|
||||
type OptRawJson = Option<Box<RawJsonValue>>;
|
||||
|
||||
assert!(from_json_value::<OptRawJson>(json!(null)).unwrap().is_none());
|
||||
assert!(from_json_value::<OptRawJson>(json!("test")).unwrap().is_some());
|
||||
assert!(from_json_value::<OptRawJson>(json!({ "a": "b" })).unwrap().is_some());
|
||||
}
|
||||
|
||||
// For completeness sake, make sure serialization works too
|
||||
#[test]
|
||||
fn raw_json_serialize() {
|
||||
assert!(to_raw_json_value(&json!(null)).is_ok());
|
||||
assert!(to_raw_json_value(&json!("string")).is_ok());
|
||||
assert!(to_raw_json_value(&json!({})).is_ok());
|
||||
assert!(to_raw_json_value(&json!({ "a": "b" })).is_ok());
|
||||
}
|
||||
}
|
||||
}
|
55
crates/ruma-client-api/src/membership/ban_user.rs
Normal file
55
crates/ruma-client-api/src/membership/ban_user.rs
Normal file
@ -0,0 +1,55 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/ban`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidban
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Ban a user from a room.",
|
||||
method: POST,
|
||||
name: "ban_user",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/ban",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/ban",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to kick the user from.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user to ban.
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The reason for banning the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id and room id.
|
||||
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
||||
Self { room_id, user_id, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/membership/forget_room.rs
Normal file
48
crates/ruma-client-api/src/membership/forget_room.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/forget`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidforget
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Forget a room.",
|
||||
method: POST,
|
||||
name: "forget_room",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/forget",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/forget",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to forget.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
146
crates/ruma-client-api/src/membership/get_member_events.rs
Normal file
146
crates/ruma-client-api/src/membership/get_member_events.rs
Normal file
@ -0,0 +1,146 @@
|
||||
//! `GET /_matrix/client/*/rooms/{roomId}/members`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidmembers
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::room::member::RoomMemberEvent;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_serde::{Raw, StringEnum};
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get membership events for a room.",
|
||||
method: GET,
|
||||
name: "get_member_events",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/members",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/members",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to get the member events for.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The point in time (pagination token) to return members for in the room.
|
||||
///
|
||||
/// This token can be obtained from a prev_batch token returned for each room by the sync
|
||||
/// API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub at: Option<&'a str>,
|
||||
|
||||
/// The kind of memberships to filter for.
|
||||
///
|
||||
/// Defaults to no filtering if unspecified. When specified alongside not_membership, the
|
||||
/// two parameters create an 'or' condition: either the membership is the same as membership
|
||||
/// or is not the same as not_membership.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub membership: Option<MembershipEventFilter>,
|
||||
|
||||
/// The kind of memberships to *exclude* from the results.
|
||||
///
|
||||
/// Defaults to no filtering if unspecified.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub not_membership: Option<MembershipEventFilter>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A list of member events.
|
||||
pub chunk: Vec<Raw<RoomMemberEvent>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id, at: None, membership: None, not_membership: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given member event chunk.
|
||||
pub fn new(chunk: Vec<Raw<RoomMemberEvent>>) -> Self {
|
||||
Self { chunk }
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of membership events to filter for.
|
||||
///
|
||||
/// This type can hold an arbitrary string. To check for formats that are not available as a
|
||||
/// documented variant here, use its string representation, obtained through `.as_str()`.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum MembershipEventFilter {
|
||||
/// The user has joined.
|
||||
Join,
|
||||
|
||||
/// The user has been invited.
|
||||
Invite,
|
||||
|
||||
/// The user has left.
|
||||
Leave,
|
||||
|
||||
/// The user has been banned.
|
||||
Ban,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl MembershipEventFilter {
|
||||
/// Creates a string slice from this `MembershipEventFilter`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "server"))]
|
||||
mod tests {
|
||||
use matches::assert_matches;
|
||||
use ruma_api::IncomingRequest as _;
|
||||
|
||||
use super::{IncomingRequest, MembershipEventFilter};
|
||||
|
||||
#[test]
|
||||
fn deserialization() {
|
||||
let uri = http::Uri::builder()
|
||||
.scheme("https")
|
||||
.authority("example.org")
|
||||
.path_and_query(
|
||||
"/_matrix/client/r0/rooms/!dummy%3Aexample.org/members\
|
||||
?not_membership=leave\
|
||||
&at=1026",
|
||||
)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let req = IncomingRequest::try_from_http_request(
|
||||
http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(),
|
||||
&["!dummy:example.org"],
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
req,
|
||||
Ok(IncomingRequest {
|
||||
room_id,
|
||||
at: Some(at),
|
||||
membership: None,
|
||||
not_membership: Some(MembershipEventFilter::Leave),
|
||||
}) if room_id == "!dummy:example.org" && at == "1026"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
120
crates/ruma-client-api/src/membership/invite_user.rs
Normal file
120
crates/ruma-client-api/src/membership/invite_user.rs
Normal file
@ -0,0 +1,120 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/invite`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec (MXID)][spec-mxid], [spec (3PID)][spec-3pid])
|
||||
//!
|
||||
//! This endpoint has two forms: one to invite a user
|
||||
//! [by their Matrix identifier][spec-mxid], and one to invite a user
|
||||
//! [by their third party identifier][spec-3pid].
|
||||
//!
|
||||
//! [spec-mxid]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite
|
||||
//! [spec-3pid]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite-1
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use ruma_serde::Outgoing;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::membership::{IncomingInvite3pid, Invite3pid};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Invite a user to a room.",
|
||||
method: POST,
|
||||
name: "invite_user",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/invite",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/invite",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room where the user should be invited.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user to invite.
|
||||
#[serde(flatten)]
|
||||
pub recipient: InvitationRecipient<'a>,
|
||||
|
||||
/// Optional reason for inviting the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID and invitation recipient.
|
||||
pub fn new(room_id: &'a RoomId, recipient: InvitationRecipient<'a>) -> Self {
|
||||
Self { room_id, recipient, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Distinguishes between invititations by Matrix or third party identifiers.
|
||||
#[derive(Clone, Debug, PartialEq, Outgoing, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[incoming_derive(PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum InvitationRecipient<'a> {
|
||||
/// Used to invite user by their Matrix identifier.
|
||||
UserId {
|
||||
/// Matrix identifier of user.
|
||||
user_id: &'a UserId,
|
||||
},
|
||||
|
||||
/// Used to invite user by a third party identifier.
|
||||
ThirdPartyId(Invite3pid<'a>),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ruma_common::thirdparty::Medium;
|
||||
use ruma_identifiers::user_id;
|
||||
use serde_json::{from_value as from_json_value, json};
|
||||
|
||||
use super::IncomingInvitationRecipient;
|
||||
use crate::membership::IncomingInvite3pid;
|
||||
|
||||
#[test]
|
||||
fn deserialize_invite_by_user_id() {
|
||||
let incoming = from_json_value::<IncomingInvitationRecipient>(
|
||||
json!({ "user_id": "@carl:example.org" }),
|
||||
)
|
||||
.unwrap();
|
||||
let user_id = user_id!("@carl:example.org").to_owned();
|
||||
let recipient = IncomingInvitationRecipient::UserId { user_id };
|
||||
assert_eq!(incoming, recipient);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_invite_by_3pid() {
|
||||
let incoming = from_json_value::<IncomingInvitationRecipient>(json!({
|
||||
"id_server": "example.org",
|
||||
"id_access_token": "abcdefghijklmnop",
|
||||
"medium": "email",
|
||||
"address": "carl@example.org"
|
||||
}))
|
||||
.unwrap();
|
||||
let recipient = IncomingInvitationRecipient::ThirdPartyId(IncomingInvite3pid {
|
||||
id_server: "example.org".into(),
|
||||
id_access_token: "abcdefghijklmnop".into(),
|
||||
medium: Medium::Email,
|
||||
address: "carl@example.org".into(),
|
||||
});
|
||||
assert_eq!(incoming, recipient);
|
||||
}
|
||||
}
|
||||
}
|
61
crates/ruma-client-api/src/membership/join_room_by_id.rs
Normal file
61
crates/ruma-client-api/src/membership/join_room_by_id.rs
Normal file
@ -0,0 +1,61 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/join`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidjoin
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use crate::membership::{IncomingThirdPartySigned, ThirdPartySigned};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Join a room using its ID.",
|
||||
method: POST,
|
||||
name: "join_room_by_id",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/join",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/join",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room where the user should be invited.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a 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<ThirdPartySigned<'a>>,
|
||||
|
||||
/// Optional reason for joining the room.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room that the user joined.
|
||||
pub room_id: Box<RoomId>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id, third_party_signed: None, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room id.
|
||||
pub fn new(room_id: Box<RoomId>) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
//! `POST /_matrix/client/*/join/{roomIdOrAlias}`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3joinroomidoralias
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, RoomOrAliasId, ServerName};
|
||||
|
||||
use crate::membership::{IncomingThirdPartySigned, 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",
|
||||
r0_path: "/_matrix/client/r0/join/:room_id_or_alias",
|
||||
stable_path: "/_matrix/client/v3/join/:room_id_or_alias",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room where the user should be invited.
|
||||
#[ruma_api(path)]
|
||||
pub room_id_or_alias: &'a RoomOrAliasId,
|
||||
|
||||
/// The servers to attempt to join the room through.
|
||||
///
|
||||
/// One of the servers must be participating in the room.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub server_name: &'a [Box<ServerName>],
|
||||
|
||||
/// 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<ThirdPartySigned<'a>>,
|
||||
|
||||
/// Optional reason for joining the room.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room that the user joined.
|
||||
pub room_id: Box<RoomId>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID or alias ID.
|
||||
pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self {
|
||||
Self { room_id_or_alias, server_name: &[], third_party_signed: None, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room ID.
|
||||
pub fn new(room_id: Box<RoomId>) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
}
|
116
crates/ruma-client-api/src/membership/joined_members.rs
Normal file
116
crates/ruma-client-api/src/membership/joined_members.rs
Normal file
@ -0,0 +1,116 @@
|
||||
//! `GET /_matrix/client/*/rooms/{roomId}/joined_members`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidjoined_members
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{MxcUri, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a map of user ids to member info objects for members of the room. Primarily for use in Application Services.",
|
||||
method: GET,
|
||||
name: "joined_members",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/joined_members",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/joined_members",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to get the members of.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A list of the rooms the user is in, i.e.
|
||||
/// the ID of each room in which the user has joined membership.
|
||||
pub joined: BTreeMap<Box<UserId>, RoomMember>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given joined rooms.
|
||||
pub fn new(joined: BTreeMap<Box<UserId>, RoomMember>) -> Self {
|
||||
Self { joined }
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a room member.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct RoomMember {
|
||||
/// The display name of the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub display_name: Option<String>,
|
||||
|
||||
/// The mxc avatar url of the user.
|
||||
///
|
||||
/// If you activate the `compat` feature, this field being an empty string in JSON will
|
||||
/// result in `None` here during deserialization.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(
|
||||
feature = "compat",
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub avatar_url: Option<Box<MxcUri>>,
|
||||
}
|
||||
|
||||
impl RoomMember {
|
||||
/// Creates an empty `RoomMember`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use matches::assert_matches;
|
||||
use serde_json::{from_value as from_json_value, json};
|
||||
|
||||
use super::RoomMember;
|
||||
|
||||
#[test]
|
||||
fn deserialize_room_member() {
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMember>(json!({
|
||||
"display_name": "alice",
|
||||
"avatar_url": "mxc://localhost/wefuiwegh8742w",
|
||||
})).unwrap(),
|
||||
RoomMember {
|
||||
display_name: Some(display_name),
|
||||
avatar_url: Some(avatar_url),
|
||||
} if display_name == "alice"
|
||||
&& avatar_url == "mxc://localhost/wefuiwegh8742w"
|
||||
);
|
||||
|
||||
#[cfg(feature = "compat")]
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMember>(json!({
|
||||
"display_name": "alice",
|
||||
"avatar_url": "",
|
||||
})).unwrap(),
|
||||
RoomMember {
|
||||
display_name: Some(display_name),
|
||||
avatar_url: None,
|
||||
} if display_name == "alice"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
48
crates/ruma-client-api/src/membership/joined_rooms.rs
Normal file
48
crates/ruma-client-api/src/membership/joined_rooms.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! `GET /_matrix/client/*/joined_rooms`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3joined_rooms
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get a list of the user's current rooms.",
|
||||
method: GET,
|
||||
name: "joined_rooms",
|
||||
r0_path: "/_matrix/client/r0/joined_rooms",
|
||||
stable_path: "/_matrix/client/v3/joined_rooms",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
request: {}
|
||||
|
||||
response: {
|
||||
/// A list of the rooms the user is in, i.e. the ID of each room in
|
||||
/// which the user has joined membership.
|
||||
pub joined_rooms: Vec<Box<RoomId>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given joined rooms.
|
||||
pub fn new(joined_rooms: Vec<Box<RoomId>>) -> Self {
|
||||
Self { joined_rooms }
|
||||
}
|
||||
}
|
||||
}
|
55
crates/ruma-client-api/src/membership/kick_user.rs
Normal file
55
crates/ruma-client-api/src/membership/kick_user.rs
Normal file
@ -0,0 +1,55 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/kick`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidkick
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Kick a user from a room.",
|
||||
method: POST,
|
||||
name: "kick_user",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/kick",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/kick",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to kick the user from.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user to kick.
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The reason for kicking the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id and room id.
|
||||
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
||||
Self { room_id, user_id, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
52
crates/ruma-client-api/src/membership/leave_room.rs
Normal file
52
crates/ruma-client-api/src/membership/leave_room.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/leave`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidleave
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Leave a room.",
|
||||
method: POST,
|
||||
name: "leave_room",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/leave",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/leave",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to leave.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// Optional reason to be included as the `reason` on the subsequent membership event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id.
|
||||
pub fn new(room_id: &'a RoomId) -> Self {
|
||||
Self { room_id, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
55
crates/ruma-client-api/src/membership/unban_user.rs
Normal file
55
crates/ruma-client-api/src/membership/unban_user.rs
Normal file
@ -0,0 +1,55 @@
|
||||
//! `POST /_matrix/client/*/rooms/{roomId}/unban`
|
||||
|
||||
pub mod v3 {
|
||||
//! `/v3/` ([spec])
|
||||
//!
|
||||
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidunban
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Unban a user from a room.",
|
||||
method: POST,
|
||||
name: "unban_user",
|
||||
r0_path: "/_matrix/client/r0/rooms/:room_id/unban",
|
||||
stable_path: "/_matrix/client/v3/rooms/:room_id/unban",
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
added: 1.0,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room to unban the user from.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user to unban.
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// Optional reason for unbanning the user.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room id and room id.
|
||||
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
||||
Self { room_id, user_id, reason: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user