diff --git a/ruma-client-api/src/r0/config/get_global_account_data.rs b/ruma-client-api/src/r0/config/get_global_account_data.rs index 73285420..a97dbb59 100644 --- a/ruma-client-api/src/r0/config/get_global_account_data.rs +++ b/ruma-client-api/src/r0/config/get_global_account_data.rs @@ -15,16 +15,18 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// Type of data to retrieve. #[ruma_api(path)] - pub event_type: String, + pub event_type: &'a str, } + #[non_exhaustive] response: { /// Account data content for the given type. #[ruma_api(body)] @@ -33,3 +35,17 @@ ruma_api! { 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) -> Self { + Self { account_data } + } +} diff --git a/ruma-client-api/src/r0/config/get_room_account_data.rs b/ruma-client-api/src/r0/config/get_room_account_data.rs index d3aa5dc2..82a780ed 100644 --- a/ruma-client-api/src/r0/config/get_room_account_data.rs +++ b/ruma-client-api/src/r0/config/get_room_account_data.rs @@ -15,20 +15,22 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// Room ID for which to retrieve data. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// Type of data to retrieve. #[ruma_api(path)] - pub event_type: String, + pub event_type: &'a str, } + #[non_exhaustive] response: { /// Account data content for the given type. #[ruma_api(body)] @@ -37,3 +39,17 @@ ruma_api! { 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) -> Self { + Self { account_data } + } +} diff --git a/ruma-client-api/src/r0/config/set_global_account_data.rs b/ruma-client-api/src/r0/config/set_global_account_data.rs index eeabef26..c357c06a 100644 --- a/ruma-client-api/src/r0/config/set_global_account_data.rs +++ b/ruma-client-api/src/r0/config/set_global_account_data.rs @@ -14,6 +14,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// Arbitrary JSON to store as config data. /// @@ -25,16 +26,32 @@ ruma_api! { /// /// Custom types should be namespaced to avoid clashes. #[ruma_api(path)] - pub event_type: String, + pub event_type: &'a str, /// The ID of the user to set account_data for. /// /// The access token must be authorized to make requests for this user ID. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, } + #[derive(Default)] + #[non_exhaustive] 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: Box, event_type: &'a str, user_id: &'a UserId) -> Self { + Self { data, event_type, user_id } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/config/set_room_account_data.rs b/ruma-client-api/src/r0/config/set_room_account_data.rs index 63029553..c1a82f10 100644 --- a/ruma-client-api/src/r0/config/set_room_account_data.rs +++ b/ruma-client-api/src/r0/config/set_room_account_data.rs @@ -14,10 +14,11 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// Arbitrary JSON to store as config data. /// - /// To create a `Box`, use `serde_json::value::to_raw_value`. + /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. #[ruma_api(body)] pub data: Box, @@ -25,20 +26,41 @@ ruma_api! { /// /// Custom types should be namespaced to avoid clashes. #[ruma_api(path)] - pub event_type: String, + pub event_type: &'a str, /// The ID of the room to set account_data on. #[ruma_api(path)] - pub room_id: RoomId, + 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: UserId, + pub user_id: &'a UserId, } + #[derive(Default)] + #[non_exhaustive] 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: Box, + 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 + } +} diff --git a/ruma-client-api/src/r0/contact/get_contacts.rs b/ruma-client-api/src/r0/contact/get_contacts.rs index 792f69d7..cef4ef37 100644 --- a/ruma-client-api/src/r0/contact/get_contacts.rs +++ b/ruma-client-api/src/r0/contact/get_contacts.rs @@ -16,8 +16,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[non_exhaustive] request: {} + #[non_exhaustive] response: { /// A list of third party identifiers the homeserver has associated with the user's /// account. @@ -28,8 +31,26 @@ ruma_api! { 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) -> Self { + Self { threepids } + } +} + /// An identifier external to Matrix. +/// +/// To create an instance of this type, first create a `ThirdPartyIdentifierInit` and convert it to +/// this type using `ThirdPartyIdentifier::Init` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] +#[non_exhaustive] #[cfg_attr(test, derive(PartialEq))] pub struct ThirdPartyIdentifier { /// The third party identifier address. @@ -47,6 +68,32 @@ pub struct ThirdPartyIdentifier { pub added_at: SystemTime, } +/// Initial set of fields of `ThirdPartyIdentifier`. +/// +/// This struct will not be updated even if additional fields are added to `ThirdPartyIdentifier` +/// in a new (non-breaking) release of the Matrix specification. +#[derive(Debug)] +pub struct ThirdPartyIdentifierInit { + /// The third party identifier address. + pub address: String, + + /// The medium of third party identifier. + pub medium: Medium, + + /// The time when the identifier was validated by the identity server. + pub validated_at: SystemTime, + + /// The time when the homeserver associated the third party identifier with the user. + pub added_at: SystemTime, +} + +impl From for ThirdPartyIdentifier { + fn from(init: ThirdPartyIdentifierInit) -> Self { + let ThirdPartyIdentifierInit { address, medium, validated_at, added_at } = init; + ThirdPartyIdentifier { address, medium, validated_at, added_at } + } +} + #[cfg(test)] mod tests { use std::time::{Duration, UNIX_EPOCH}; diff --git a/ruma-client-api/src/r0/contact/request_contact_verification_token.rs b/ruma-client-api/src/r0/contact/request_contact_verification_token.rs index 721106f2..470acb5b 100644 --- a/ruma-client-api/src/r0/contact/request_contact_verification_token.rs +++ b/ruma-client-api/src/r0/contact/request_contact_verification_token.rs @@ -13,35 +13,59 @@ ruma_api! { requires_authentication: false, } + #[non_exhaustive] request: { /// Client-generated secret string used to protect this session. - pub client_secret: String, + pub client_secret: &'a str, /// The email address. - pub email: String, - - /// A URL for the identity server to redirect the user to after - /// validation is completed. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option, + pub email: &'a str, /// Used to distinguish protocol level retries from requests to re-send /// the email. pub send_attempt: UInt, + /// A URL for the identity server to redirect the user to after + /// validation is completed. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, + /// The identity server to send the onward request to as a hostname with /// an appended colon and port number if the port is not the default. #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, + pub id_server: Option<&'a str>, /// An access token previously registered with the identity server. /// /// Required if an `id_server` is supplied. #[serde(skip_serializing_if = "Option::is_none")] - pub id_access_token: Option, + pub id_access_token: Option<&'a str>, } + #[derive(Default)] + #[non_exhaustive] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given client secret, email and send-attempt counter. + pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self { + Self { + client_secret, + email, + send_attempt, + next_link: None, + id_server: None, + id_access_token: None, + } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}