From 05ce8bd3d8527bb7978fc4cacdb3ea199c7cc804 Mon Sep 17 00:00:00 2001 From: Daniel Kilimnik Date: Thu, 16 Jan 2025 14:58:18 +0100 Subject: [PATCH] feat: Add room details api --- CHANGELOG.md | 2 +- src/rooms.rs | 1 + src/rooms/room_details.rs | 3 + src/rooms/room_details/v1.rs | 122 +++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/rooms/room_details.rs create mode 100644 src/rooms/room_details/v1.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 48986c4..690670f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Breaking changes: Improvement: * The list_room response now includes the `room_type` field - +* Add room_details api # 0.7.0 diff --git a/src/rooms.rs b/src/rooms.rs index 79c126a..0e848f0 100644 --- a/src/rooms.rs +++ b/src/rooms.rs @@ -1,3 +1,4 @@ //! Endpoints in the `/_synapse/admin/v/rooms/` scope. pub mod list_rooms; +pub mod room_details; diff --git a/src/rooms/room_details.rs b/src/rooms/room_details.rs new file mode 100644 index 0000000..d82013f --- /dev/null +++ b/src/rooms/room_details.rs @@ -0,0 +1,3 @@ +//! Different versions of the room details endpoint. + +pub mod v1; diff --git a/src/rooms/room_details/v1.rs b/src/rooms/room_details/v1.rs new file mode 100644 index 0000000..0ff1e0f --- /dev/null +++ b/src/rooms/room_details/v1.rs @@ -0,0 +1,122 @@ +//! [GET /_synapse/admin/v1/rooms/:room_id](https://github.com/element-hq/synapse/blob/master/docs/admin_api/rooms.md#room-details-api) +use ruma::{ + api::{metadata, request, response, Metadata}, + events::room::{guest_access::GuestAccess, history_visibility::HistoryVisibility}, + room::RoomType, + space::SpaceRoomJoinRule, + OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UInt, +}; + +const METADATA: Metadata = metadata! { + method: GET, + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_synapse/admin/v1/rooms/:room_id", + } +}; + +#[request] +pub struct Request { + /// ID of the room to show the details of. + #[ruma_api(path)] + pub room_id: OwnedRoomId, +} + +#[response] +pub struct Response { + /// Room ID + pub room_id: OwnedRoomId, + + /// Room name + pub name: Option, + + /// Room topic + pub topic: Option, + + /// Room avatar + pub avatar: Option, + + /// Room alias ID + pub canonical_alias: Option, + + /// Amount of joined members. + pub joined_members: UInt, + + /// Amount of local members. + pub joined_local_members: UInt, + + /// Amount of local devices. + pub joined_local_devices: UInt, + + /// Room version + pub version: Option, + + /// User ID of the room creator. + #[serde(deserialize_with = "ruma::serde::empty_string_as_none")] + pub creator: Option, + + /// Room encryption. + pub encryption: Option, + + /// Whether the room is federatable + #[serde(deserialize_with = "crate::serde::bool_or_uint")] + pub federatable: bool, + + /// Whether the room is public. + #[serde(deserialize_with = "crate::serde::bool_or_uint")] + pub public: bool, + + /// Join rules of the room. + pub join_rules: Option, + + /// Guest access of the room + pub guest_access: Option, + + /// History visibility of the room + pub history_visibility: Option, + + /// State events of the room. + pub state_events: UInt, + + /// Room type of the room. + pub room_type: Option, + + /// Whether all local users have forgotten the room. + #[serde(deserialize_with = "crate::serde::bool_or_uint")] + pub forgotten: bool, +} + +impl Request { + /// Creates a `Request` with the given room ID. + pub fn new(room_id: OwnedRoomId) -> Self { + Self { room_id } + } +} + +impl Response { + /// Creates a `Response` with the given room ID and default values. + pub fn new(room_id: OwnedRoomId) -> Self { + Self { + room_id, + name: None, + topic: None, + avatar: None, + canonical_alias: None, + joined_members: 0u32.into(), + joined_local_members: 0u32.into(), + joined_local_devices: 0u32.into(), + version: None, + creator: None, + encryption: None, + federatable: false, + public: false, + join_rules: None, + guest_access: None, + history_visibility: None, + state_events: 0u32.into(), + room_type: None, + forgotten: false, + } + } +}