Skip to content

Commit

Permalink
feat: reuse User type across all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
avdb13 committed Feb 24, 2024
1 parent 71b2d7c commit b76417a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 58 deletions.
45 changes: 45 additions & 0 deletions crates/matrix/src/admin/user.rs
Original file line number Diff line number Diff line change
@@ -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<String>,

pub avatar_url: Option<OwnedMxcUri>,

pub threepids: Vec<ThirdPartyIdentifier>,

pub external_ids: Vec<ExternalId>,

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<u64>,

#[serde(skip_serializing)]
pub consent_ts: Option<u64>,

pub locked: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ExternalId {
pub auth_provider: String,

pub external_id: String,
}
44 changes: 7 additions & 37 deletions crates/matrix/src/admin/user/get_user.rs
Original file line number Diff line number Diff line change
@@ -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<String>,

pub threepids: Vec<ThirdPartyIdentifier>,

pub avatar_url: Option<OwnedMxcUri>,

pub admin: bool,

pub deactivated: bool,

pub erased: bool,

pub shadow_banned: bool,

pub creation_ts: u64,

pub consent_server_notice_sent: Option<u64>,

pub consent_ts: Option<u64>,

pub external_ids: Vec<ExternalId>,

pub locked: bool,
}

#[derive(Clone, Debug)]
pub struct ExternalId {
pub auth_provider: String,

pub external_id: String,
#[ruma_api(body)]
pub user: User,
}
29 changes: 8 additions & 21 deletions crates/matrix/src/admin/user/get_users.rs
Original file line number Diff line number Diff line change
@@ -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! {
Expand Down Expand Up @@ -52,25 +52,12 @@ pub struct Request {

#[response(error = crate::Error)]
pub struct Response {
pub name: OwnedUserId,

pub displayname: Option<String>,

pub threepids: Vec<ThirdPartyIdentifier>,

pub avatar_url: Option<OwnedMxcUri>,

pub admin: bool,

pub deactivated: bool,

pub erased: bool,

pub shadow_banned: bool,
#[serde(flatten)]
users: Vec<User>,

pub creation_ts: u64,
next_token: String,

pub locked: bool,
total: u64,
}

#[derive(Clone, Debug, Default)]
Expand Down
28 changes: 28 additions & 0 deletions crates/matrix/src/admin/user/set_user.rs
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit b76417a

Please sign in to comment.