diff --git a/crates/ruma-client-api/src/profile.rs b/crates/ruma-client-api/src/profile.rs index 2c5293c6..ebf71129 100644 --- a/crates/ruma-client-api/src/profile.rs +++ b/crates/ruma-client-api/src/profile.rs @@ -1,10 +1,13 @@ //! Endpoints for user profiles. +pub mod delete_profile_key; +pub mod delete_timezone_key; pub mod get_avatar_url; pub mod get_display_name; pub mod get_profile; +pub mod get_profile_key; pub mod get_timezone_key; pub mod set_avatar_url; pub mod set_display_name; +pub mod set_profile_key; pub mod set_timezone_key; -pub mod delete_timezone_key; diff --git a/crates/ruma-client-api/src/profile/delete_profile_key.rs b/crates/ruma-client-api/src/profile/delete_profile_key.rs new file mode 100644 index 00000000..d6bc4dc8 --- /dev/null +++ b/crates/ruma-client-api/src/profile/delete_profile_key.rs @@ -0,0 +1,59 @@ +//! `DELETE /_matrix/client/*/profile/{user_id}/{key_name}` +//! +//! Deletes a custom profile key from the user + +pub mod unstable { + //! `msc4133` ([MSC]) + //! + //! [MSC]: https://github.com/tcpipuk/matrix-spec-proposals/blob/main/proposals/4133-extended-profiles.md + + use std::collections::BTreeMap; + + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + use serde_json::Value as JsonValue; + + const METADATA: Metadata = metadata! { + method: DELETE, + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/:key_name", + // 1.12 => "/_matrix/client/v3/profile/:user_id/:key_name", + } + }; + + #[request(error = crate::Error)] + pub struct Request { + #[ruma_api(path)] + pub user_id: OwnedUserId, + + #[ruma_api(path)] + pub key: String, + + #[serde(flatten)] + pub kv_pair: BTreeMap, + } + + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + + impl Request { + pub fn new( + user_id: OwnedUserId, + key: String, + kv_pair: BTreeMap, + ) -> Self { + Self { user_id, key, kv_pair } + } + } + + impl Response { + pub fn new() -> Self { + Self {} + } + } +} diff --git a/crates/ruma-client-api/src/profile/get_profile.rs b/crates/ruma-client-api/src/profile/get_profile.rs index 80715170..d069820d 100644 --- a/crates/ruma-client-api/src/profile/get_profile.rs +++ b/crates/ruma-client-api/src/profile/get_profile.rs @@ -1,8 +1,6 @@ //! `GET /_matrix/client/*/profile/{userId}` //! //! Get all profile information of an user. -//! -//! TODO: implement the "generic-ness" of MSC4133 pub mod v3 { //! `/v3/` ([spec]) @@ -13,10 +11,13 @@ pub mod v3 { //! //! [MSC]: https://github.com/tcpipuk/matrix-spec-proposals/blob/main/proposals/4133-extended-profiles.md + use std::collections::BTreeMap; + use ruma_common::{ api::{request, response, Metadata}, metadata, OwnedMxcUri, OwnedUserId, }; + use serde_json::Value as JsonValue; const METADATA: Metadata = metadata! { method: GET, @@ -71,6 +72,11 @@ pub mod v3 { /// TODO: strong type this to be a valid IANA timezone? #[serde(rename = "us.cloke.msc4175.tz", skip_serializing_if = "Option::is_none")] pub tz: Option, + + /// Custom arbitrary profile fields as part of MSC4133 that are not reserved such as + /// MSC4175 + #[serde(flatten, skip_serializing_if = "BTreeMap::is_empty")] + pub custom_profile_fields: BTreeMap, } impl Request { @@ -89,6 +95,7 @@ pub mod v3 { #[cfg(feature = "unstable-msc2448")] blurhash: None, tz: None, + custom_profile_fields: BTreeMap::new(), } } } diff --git a/crates/ruma-client-api/src/profile/get_profile_key.rs b/crates/ruma-client-api/src/profile/get_profile_key.rs new file mode 100644 index 00000000..24cf921e --- /dev/null +++ b/crates/ruma-client-api/src/profile/get_profile_key.rs @@ -0,0 +1,55 @@ +//! `GET /_matrix/client/*/profile/{user_id}/{key_name}` +//! +//! Gets a custom profile key from the user + +pub mod unstable { + //! `msc4133` ([MSC]) + //! + //! [MSC]: https://github.com/tcpipuk/matrix-spec-proposals/blob/main/proposals/4133-extended-profiles.md + + use std::collections::BTreeMap; + + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + use serde_json::Value as JsonValue; + + const METADATA: Metadata = metadata! { + method: GET, + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/:key_name", + // 1.12 => "/_matrix/client/v3/profile/:user_id/:key_name", + } + }; + + #[request(error = crate::Error)] + pub struct Request { + #[ruma_api(path)] + pub user_id: OwnedUserId, + + #[ruma_api(path)] + pub key: String, + } + + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + #[serde(flatten)] + pub value: BTreeMap, + } + + impl Request { + pub fn new(user_id: OwnedUserId, key: String) -> Self { + Self { user_id, key } + } + } + + impl Response { + pub fn new(value: BTreeMap) -> Self { + Self { value } + } + } +} diff --git a/crates/ruma-client-api/src/profile/set_profile_key.rs b/crates/ruma-client-api/src/profile/set_profile_key.rs new file mode 100644 index 00000000..f0bf07d9 --- /dev/null +++ b/crates/ruma-client-api/src/profile/set_profile_key.rs @@ -0,0 +1,59 @@ +//! `PUT /_matrix/client/*/profile/{user_id}/{key_name}` +//! +//! Sets a custom profile key from the user + +pub mod unstable { + //! `msc4133` ([MSC]) + //! + //! [MSC]: https://github.com/tcpipuk/matrix-spec-proposals/blob/main/proposals/4133-extended-profiles.md + + use std::collections::BTreeMap; + + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + use serde_json::Value as JsonValue; + + const METADATA: Metadata = metadata! { + method: PUT, + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/:key_name", + // 1.12 => "/_matrix/client/v3/profile/:user_id/:key_name", + } + }; + + #[request(error = crate::Error)] + pub struct Request { + #[ruma_api(path)] + pub user_id: OwnedUserId, + + #[ruma_api(path)] + pub key: String, + + #[serde(flatten)] + pub kv_pair: BTreeMap, + } + + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + + impl Request { + pub fn new( + user_id: OwnedUserId, + key: String, + kv_pair: BTreeMap, + ) -> Self { + Self { user_id, key, kv_pair } + } + } + + impl Response { + pub fn new() -> Self { + Self {} + } + } +} diff --git a/crates/ruma-federation-api/src/query/get_profile_information.rs b/crates/ruma-federation-api/src/query/get_profile_information.rs index 2dc37b79..db6ced3f 100644 --- a/crates/ruma-federation-api/src/query/get_profile_information.rs +++ b/crates/ruma-federation-api/src/query/get_profile_information.rs @@ -7,12 +7,15 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1queryprofile + use std::collections::BTreeMap; + use ruma_common::{ api::{request, response, Metadata}, metadata, serde::StringEnum, OwnedMxcUri, OwnedUserId, }; + use serde_json::Value as JsonValue; use crate::PrivOwnedStr; @@ -72,6 +75,11 @@ pub mod v1 { /// TODO: strong type this to be a valid IANA timezone? #[serde(rename = "us.cloke.msc4175.tz", skip_serializing_if = "Option::is_none")] pub tz: Option, + + /// Custom arbitrary profile fields as part of MSC4133 that are not reserved such as + /// MSC4175 + #[serde(flatten, skip_serializing_if = "BTreeMap::is_empty")] + pub custom_profile_fields: BTreeMap, } impl Request {