diff --git a/src/r0/account.rs b/src/r0/account.rs index 66460b05..b16ab28f 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -1,7 +1,9 @@ //! Endpoints for account registration and management. +pub mod bind_3pid; pub mod change_password; pub mod deactivate; +pub mod delete_3pid; pub mod get_username_availability; pub mod register; pub mod request_3pid_management_token_via_email; @@ -10,6 +12,7 @@ pub mod request_password_change_token_via_email; pub mod request_password_change_token_via_msisdn; pub mod request_registration_token_via_email; pub mod request_registration_token_via_msisdn; +pub mod unbind_3pid; pub mod whoami; @@ -30,8 +33,15 @@ pub struct AuthenticationData { pub struct IdentityServerInfo { /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. - /// Deprecated since r0.6.0. pub id_server: String, /// Access token previously registered with identity server. pub id_access_token: String, } + +/// Possible values for deleting or unbinding 3PIDs +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +enum ThirdPartyIdRemovalStatus { + NoSupport, + Success, +} diff --git a/src/r0/account/bind_3pid.rs b/src/r0/account/bind_3pid.rs new file mode 100644 index 00000000..e8603f6e --- /dev/null +++ b/src/r0/account/bind_3pid.rs @@ -0,0 +1,29 @@ +//! [POST /_matrix/client/r0/account/3pid/bind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind) + +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Bind a 3PID to a user's account on an identity server", + method: POST, + name: "bind_3pid", + path: "/_matrix/client/r0/account/3pid/bind", + rate_limited: true, + requires_authentication: true, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The ID server to send the onward request to as a hostname with an + /// appended colon and port number if the port is not the default. + #[serde(flatten)] + pub identity_server_info: IdentityServerInfo, + /// The session identifier given by the identity server. + pub sid: String, + } + + response {} +} diff --git a/src/r0/account/delete_3pid.rs b/src/r0/account/delete_3pid.rs new file mode 100644 index 00000000..b9109efe --- /dev/null +++ b/src/r0/account/delete_3pid.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/account/3pid/delete](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-delete) + +use ruma_api::ruma_api; + +use super::ThirdPartyIdRemovalStatus; +use crate::r0::thirdparty::Medium; + +ruma_api! { + metadata { + description: "Delete a 3PID from a user's account on an identity server.", + method: POST, + name: "delete_3pid", + path: "/_matrix/client/r0/account/3pid/delete", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Identity server to delete from. + #[serde(skip_serializing_if = "Option::is_none")] + id_server: Option, + /// Medium of the 3PID to be removed. + medium: Medium, + /// Third-party address being removed. + address: String, + } + + response { + /// Result of unbind operation. + id_server_unbind_result: ThirdPartyIdRemovalStatus, + } + +} diff --git a/src/r0/account/unbind_3pid.rs b/src/r0/account/unbind_3pid.rs new file mode 100644 index 00000000..69f68f8e --- /dev/null +++ b/src/r0/account/unbind_3pid.rs @@ -0,0 +1,33 @@ +//! [POST /_matrix/client/r0/account/3pid/unbind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-unbind) + +use ruma_api::ruma_api; + +use super::ThirdPartyIdRemovalStatus; +use crate::r0::thirdparty::Medium; + +ruma_api! { + metadata { + description: "Unbind a 3PID from a user's account on an identity server.", + method: POST, + name: "unbind_3pid", + path: "/_matrix/client/r0/account/3pid/unbind", + rate_limited: false, + requires_authentication: true, + } + + request { + /// Identity server to unbind from. + #[serde(skip_serializing_if = "Option::is_none")] + id_server: Option, + /// Medium of the 3PID to be removed. + medium: Medium, + /// Third-party address being removed. + address: String, + } + + response { + /// Result of unbind operation. + id_server_unbind_result: ThirdPartyIdRemovalStatus, + } + +} diff --git a/src/r0/contact/get_contacts.rs b/src/r0/contact/get_contacts.rs index c7ba4814..5c7837c6 100644 --- a/src/r0/contact/get_contacts.rs +++ b/src/r0/contact/get_contacts.rs @@ -1,5 +1,6 @@ //! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid) +use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use serde::{Deserialize, Serialize}; @@ -22,14 +23,6 @@ ruma_api! { } } -/// The medium of third party identifier. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, -} - /// An identifier external to Matrix. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ThirdPartyIdentifier { diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 01dea6ed..6e4a4b17 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,5 +1,6 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) +use crate::r0::thirdparty::Medium; use ruma_api::ruma_api; use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; @@ -52,14 +53,6 @@ ruma_api! { } } -/// The medium of a third party identifier. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum Medium { - /// An email address. - #[serde(rename = "email")] - Email, -} - /// The authentication mechanism. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum LoginType { diff --git a/src/r0/thirdparty.rs b/src/r0/thirdparty.rs index 185ad65e..82b1012d 100644 --- a/src/r0/thirdparty.rs +++ b/src/r0/thirdparty.rs @@ -72,3 +72,13 @@ pub struct User { /// Information used to identify this third party user. pub fields: HashMap, } + +/// The medium of a third party identifier. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Medium { + /// Email address identifier + Email, + /// Phone number identifier + MSISDN, +}