support generic KV pairs of MSC4133
still GET/PUT/DELETE for now Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
11155e576a
commit
f621b318c5
@ -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;
|
||||
|
59
crates/ruma-client-api/src/profile/delete_profile_key.rs
Normal file
59
crates/ruma-client-api/src/profile/delete_profile_key.rs
Normal file
@ -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<String, JsonValue>,
|
||||
}
|
||||
|
||||
#[response(error = crate::Error)]
|
||||
#[derive(Default)]
|
||||
pub struct Response {}
|
||||
|
||||
impl Request {
|
||||
pub fn new(
|
||||
user_id: OwnedUserId,
|
||||
key: String,
|
||||
kv_pair: BTreeMap<String, JsonValue>,
|
||||
) -> Self {
|
||||
Self { user_id, key, kv_pair }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String>,
|
||||
|
||||
/// 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<String, JsonValue>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
@ -89,6 +95,7 @@ pub mod v3 {
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
blurhash: None,
|
||||
tz: None,
|
||||
custom_profile_fields: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
55
crates/ruma-client-api/src/profile/get_profile_key.rs
Normal file
55
crates/ruma-client-api/src/profile/get_profile_key.rs
Normal file
@ -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<String, JsonValue>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn new(user_id: OwnedUserId, key: String) -> Self {
|
||||
Self { user_id, key }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
pub fn new(value: BTreeMap<String, JsonValue>) -> Self {
|
||||
Self { value }
|
||||
}
|
||||
}
|
||||
}
|
59
crates/ruma-client-api/src/profile/set_profile_key.rs
Normal file
59
crates/ruma-client-api/src/profile/set_profile_key.rs
Normal file
@ -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<String, JsonValue>,
|
||||
}
|
||||
|
||||
#[response(error = crate::Error)]
|
||||
#[derive(Default)]
|
||||
pub struct Response {}
|
||||
|
||||
impl Request {
|
||||
pub fn new(
|
||||
user_id: OwnedUserId,
|
||||
key: String,
|
||||
kv_pair: BTreeMap<String, JsonValue>,
|
||||
) -> Self {
|
||||
Self { user_id, key, kv_pair }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String>,
|
||||
|
||||
/// 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<String, JsonValue>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
|
Loading…
x
Reference in New Issue
Block a user