From 3a515124ec3ce7f42d02ebea91b90fd89f2ead66 Mon Sep 17 00:00:00 2001 From: skim Date: Tue, 30 Jun 2020 14:13:43 -0700 Subject: [PATCH] Add profile information query endpoint --- ruma-federation-api/CHANGELOG.md | 7 ++- ruma-federation-api/src/query.rs | 1 + .../src/query/get_profile_information/mod.rs | 2 + .../src/query/get_profile_information/v1.rs | 49 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 ruma-federation-api/src/query/get_profile_information/mod.rs create mode 100644 ruma-federation-api/src/query/get_profile_information/v1.rs diff --git a/ruma-federation-api/CHANGELOG.md b/ruma-federation-api/CHANGELOG.md index 581a742a..c958c824 100644 --- a/ruma-federation-api/CHANGELOG.md +++ b/ruma-federation-api/CHANGELOG.md @@ -18,7 +18,10 @@ Improvements: create_join_event::v1, create_join_event_template::v1 }, - query::get_room_information::v1, + query::{ + get_profile_information::v1, + get_room_information::v1, + }, transactions::send_transaction_message::v1, version::get_server_version::v1 ``` @@ -27,4 +30,4 @@ Improvements: Improvements: -* Provide `RoomV3Pdu` type for room versions 3 and above \ No newline at end of file +* Provide `RoomV3Pdu` type for room versions 3 and above diff --git a/ruma-federation-api/src/query.rs b/ruma-federation-api/src/query.rs index 7dc27cdb..1987c091 100644 --- a/ruma-federation-api/src/query.rs +++ b/ruma-federation-api/src/query.rs @@ -1,3 +1,4 @@ //! Endpoints to retrieve information from a homeserver about a resource. +pub mod get_profile_information; pub mod get_room_information; diff --git a/ruma-federation-api/src/query/get_profile_information/mod.rs b/ruma-federation-api/src/query/get_profile_information/mod.rs new file mode 100644 index 00000000..81e4aaf3 --- /dev/null +++ b/ruma-federation-api/src/query/get_profile_information/mod.rs @@ -0,0 +1,2 @@ +//! Endpoint to query profile information with a user id and optional field. +pub mod v1; diff --git a/ruma-federation-api/src/query/get_profile_information/v1.rs b/ruma-federation-api/src/query/get_profile_information/v1.rs new file mode 100644 index 00000000..37cf0803 --- /dev/null +++ b/ruma-federation-api/src/query/get_profile_information/v1.rs @@ -0,0 +1,49 @@ +//! [GET /_matrix/federation/v1/query/profile](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-profile) + +use ruma_api::ruma_api; +use ruma_identifiers::UserId; +use serde::{Deserialize, Serialize}; + +ruma_api! { + metadata: { + description: "Get profile information, such as a display name or avatar, for a given user.", + name: "get_profile_information", + method: GET, + path: "/_matrix/federation/v1/query/profile", + rate_limited: false, + requires_authentication: true, + } + + request: { + /// User ID to query. + #[ruma_api(query)] + pub user_id: UserId, + + /// Profile field to query. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub field: Option, + } + + response: { + /// Display name of the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + + /// Avatar URL for the user's avatar. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + } +} + +/// Profile fields to specify in query. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum ProfileField { + /// Display name of the user. + #[serde(rename = "displayname")] + DisplayName, + + /// Avatar URL for the user's avatar. + #[serde(rename = "avatar_url")] + AvatarUrl, +}