ruwuma/crates/ruma-federation-api/src/query/get_profile_information.rs
strawberry f621b318c5 support generic KV pairs of MSC4133
still GET/PUT/DELETE for now

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-09-09 22:40:32 -04:00

124 lines
4.1 KiB
Rust

//! `GET /_matrix/federation/*/query/profile`
//!
//! Get profile information, such as a display name or avatar, for a given user.
pub mod v1 {
//! `/v1/` ([spec])
//!
//! [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;
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: false,
authentication: ServerSignatures,
history: {
1.0 => "/_matrix/federation/v1/query/profile",
}
};
/// Request type for the `get_profile_information` endpoint.
#[request]
pub struct Request {
/// User ID to query.
#[ruma_api(query)]
pub user_id: OwnedUserId,
/// Profile field to query.
#[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(query)]
pub field: Option<ProfileField>,
}
/// Response type for the `get_profile_information` endpoint.
#[response]
#[derive(Default)]
pub struct Response {
/// Display name of the user.
#[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String>,
/// Avatar URL for the user's avatar.
///
/// If you activate the `compat-empty-string-null` 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-empty-string-null",
serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
)]
pub avatar_url: Option<OwnedMxcUri>,
/// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`.
///
/// This uses the unstable prefix in
/// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
#[cfg(feature = "unstable-msc2448")]
#[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")]
pub blurhash: Option<String>,
/// [MSC4175][msc]: `m.tz` field for specifying a timezone the user is in
///
/// [msc]: https://github.com/matrix-org/matrix-spec-proposals/blob/clokep/profile-tz/proposals/4175-profile-field-time-zone.md
///
/// 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 {
/// Creates a new `Request` with the given user id.
pub fn new(user_id: OwnedUserId) -> Self {
Self { user_id, field: None }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Default::default()
}
}
/// Profile fields to specify in query.
///
/// This type can hold an arbitrary string. To build this with a custom value, convert it from a
/// string with `::from()` / `.into()`. To check for values that are not available as a
/// documented variant here, use its string representation, obtained through
/// [`.as_str()`](Self::as_str()).
#[derive(Clone, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum ProfileField {
/// Display name of the user.
#[ruma_enum(rename = "displayname")]
DisplayName,
/// Avatar URL for the user's avatar.
#[ruma_enum(rename = "avatar_url")]
AvatarUrl,
/// Timezone
#[ruma_enum(rename = "us.cloke.msc4175.tz")]
Tz,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
}