From b76417a31b91b250def3117b12c040fadd2b0adf Mon Sep 17 00:00:00 2001 From: mikoto Date: Sat, 24 Feb 2024 17:03:35 +0000 Subject: [PATCH] feat: reuse `User` type across all requests --- crates/matrix/src/admin/user.rs | 45 +++++++++++++++++++++++ crates/matrix/src/admin/user/get_user.rs | 44 ++++------------------ crates/matrix/src/admin/user/get_users.rs | 29 ++++----------- crates/matrix/src/admin/user/set_user.rs | 28 ++++++++++++++ 4 files changed, 88 insertions(+), 58 deletions(-) diff --git a/crates/matrix/src/admin/user.rs b/crates/matrix/src/admin/user.rs index eb59f60..20275af 100644 --- a/crates/matrix/src/admin/user.rs +++ b/crates/matrix/src/admin/user.rs @@ -1,3 +1,48 @@ +use ruma_common::{thirdparty::ThirdPartyIdentifier, OwnedMxcUri, OwnedUserId}; +use serde::{Deserialize, Serialize}; + pub mod get_user; pub mod get_users; pub mod set_user; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct User { + #[serde(rename = "name")] + pub user_id: OwnedUserId, + + pub displayname: Option, + + pub avatar_url: Option, + + pub threepids: Vec, + + pub external_ids: Vec, + + pub admin: bool, + + pub deactivated: bool, + + #[serde(skip_serializing)] + pub erased: bool, + + #[serde(skip_serializing)] + pub shadow_banned: bool, + + #[serde(skip_serializing)] + pub creation_ts: u64, + + #[serde(skip_serializing)] + pub consent_server_notice_sent: Option, + + #[serde(skip_serializing)] + pub consent_ts: Option, + + pub locked: bool, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ExternalId { + pub auth_provider: String, + + pub external_id: String, +} diff --git a/crates/matrix/src/admin/user/get_user.rs b/crates/matrix/src/admin/user/get_user.rs index f19b5b1..da302be 100644 --- a/crates/matrix/src/admin/user/get_user.rs +++ b/crates/matrix/src/admin/user/get_user.rs @@ -1,58 +1,28 @@ use ruma_common::{ api::{request, response, Metadata}, - metadata, - thirdparty::ThirdPartyIdentifier, - OwnedMxcUri, OwnedUserId, + metadata, OwnedUserId, }; +use super::User; + #[allow(dead_code)] const METADATA: Metadata = metadata! { method: GET, rate_limited: false, authentication: AccessToken, history: { - unstable => "/_synapse/admin/v2/users/:name", + unstable => "/_synapse/admin/v2/users/:user_id", } }; #[request(error = crate::Error)] pub struct Request { #[ruma_api(path)] - pub name: OwnedUserId, + pub user_id: OwnedUserId, } #[response(error = crate::Error)] pub struct Response { - pub name: OwnedUserId, - - pub displayname: Option, - - pub threepids: Vec, - - pub avatar_url: Option, - - pub admin: bool, - - pub deactivated: bool, - - pub erased: bool, - - pub shadow_banned: bool, - - pub creation_ts: u64, - - pub consent_server_notice_sent: Option, - - pub consent_ts: Option, - - pub external_ids: Vec, - - pub locked: bool, -} - -#[derive(Clone, Debug)] -pub struct ExternalId { - pub auth_provider: String, - - pub external_id: String, + #[ruma_api(body)] + pub user: User, } diff --git a/crates/matrix/src/admin/user/get_users.rs b/crates/matrix/src/admin/user/get_users.rs index eeab703..263fc66 100644 --- a/crates/matrix/src/admin/user/get_users.rs +++ b/crates/matrix/src/admin/user/get_users.rs @@ -1,9 +1,9 @@ use ruma_common::{ - api::{request, response, Metadata, Direction}, - thirdparty::ThirdPartyIdentifier, - OwnedMxcUri, OwnedUserId, metadata, + api::{request, response, Direction, Metadata}, + metadata, OwnedUserId, }; -use ruma_macros::{request, response}; + +use super::User; #[allow(dead_code)] const METADATA: Metadata = metadata! { @@ -52,25 +52,12 @@ pub struct Request { #[response(error = crate::Error)] pub struct Response { - pub name: OwnedUserId, - - pub displayname: Option, - - pub threepids: Vec, - - pub avatar_url: Option, - - pub admin: bool, - - pub deactivated: bool, - - pub erased: bool, - - pub shadow_banned: bool, + #[serde(flatten)] + users: Vec, - pub creation_ts: u64, + next_token: String, - pub locked: bool, + total: u64, } #[derive(Clone, Debug, Default)] diff --git a/crates/matrix/src/admin/user/set_user.rs b/crates/matrix/src/admin/user/set_user.rs index e69de29..83868f1 100644 --- a/crates/matrix/src/admin/user/set_user.rs +++ b/crates/matrix/src/admin/user/set_user.rs @@ -0,0 +1,28 @@ +use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, +}; + +use super::User; + +#[allow(dead_code)] +const METADATA: Metadata = metadata! { + method: PUT, + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_synapse/admin/v2/users/:user_id", + } +}; + +#[request(error = crate::Error)] +pub struct Request { + #[ruma_api(path)] + pub user_id: OwnedUserId, + + #[ruma_api(body)] + pub user: User, +} + +#[response(error = crate::Error)] +pub struct Response {}