Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add room details api
Browse files Browse the repository at this point in the history
kilimnik committed Jan 16, 2025
1 parent 07c7a1c commit d3726a3
Showing 3 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rooms.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Endpoints in the `/_synapse/admin/v<x>/rooms/` scope.
pub mod list_rooms;
pub mod room_details;
3 changes: 3 additions & 0 deletions src/rooms/room_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Different versions of the room details endpoint.
pub mod v1;
142 changes: 142 additions & 0 deletions src/rooms/room_details/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//! [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,
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 {
/// Alias or ID of the room to join.
#[ruma_api(path)]
pub room_id: OwnedRoomId,
}

#[response]
pub struct Response {
/// Room ID
pub room_id: OwnedRoomId,

/// Room name
pub name: Option<String>,

/// Room topic
pub topic: Option<String>,

/// Room avatar
pub avatar: Option<String>,

/// Room alias ID
pub canonical_alias: Option<OwnedRoomAliasId>,

/// Amount of joined members.
pub joined_members: UInt,

/// Amount of local members.
pub joined_local_members: UInt,

///A mount of local devices.
pub joined_local_devices: UInt,

/// Room version
pub version: String,

/// User ID of the room creator.
#[serde(deserialize_with = "ruma::serde::empty_string_as_none")]
pub creator: Option<OwnedUserId>,

/// Room encryption.
pub encryption: Option<String>,

/// 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<SpaceRoomJoinRule>,

/// Guest access of the room
pub guest_access: Option<GuestAccess>,

/// History visibility of the room
pub history_visibility: Option<HistoryVisibility>,

/// State events of the room.
pub state_events: UInt,

/// Room type of the room.
pub room_type: Option<RoomType>,

/// Whether all local users have forgotten the room.
#[serde(deserialize_with = "crate::serde::bool_or_uint")]
pub forgotten: bool,
}

impl Request {
/// Creates an empty `Request`.
pub fn new(room_id: OwnedRoomId) -> Self {
Self { room_id }
}
}

impl Response {
/// Creates an empty `Response`.
pub fn new(
room_id: OwnedRoomId,
name: Option<String>,
topic: Option<String>,
avatar: Option<String>,
canonical_alias: Option<OwnedRoomAliasId>,
joined_members: UInt,
joined_local_members: UInt,
joined_local_devices: UInt,
version: String,
creator: Option<OwnedUserId>,
encryption: Option<String>,
federatable: bool,
public: bool,
join_rules: Option<SpaceRoomJoinRule>,
guest_access: Option<GuestAccess>,
history_visibility: Option<HistoryVisibility>,
state_events: UInt,
room_type: Option<RoomType>,
forgotten: bool,
) -> Self {
Self {
room_id,
name,
topic,
avatar,
canonical_alias,
joined_members,
joined_local_members,
joined_local_devices,
version,
creator,
encryption,
federatable,
public,
join_rules,
guest_access,
history_visibility,
state_events,
room_type,
forgotten,
}
}
}

0 comments on commit d3726a3

Please sign in to comment.