From 56bddc9cb6226a46f8e1909044877559c476d0a8 Mon Sep 17 00:00:00 2001 From: Daniel Kilimnik Date: Fri, 17 Jan 2025 10:40:40 +0100 Subject: [PATCH] feat: Add room members api --- CHANGELOG.md | 1 + src/rooms.rs | 1 + src/rooms/room_members.rs | 3 +++ src/rooms/room_members/v1.rs | 44 ++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 src/rooms/room_members.rs create mode 100644 src/rooms/room_members/v1.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 690670f..5219a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Improvement: * The list_room response now includes the `room_type` field * Add room_details api +* Add room_members api # 0.7.0 diff --git a/src/rooms.rs b/src/rooms.rs index 0e848f0..91d9d87 100644 --- a/src/rooms.rs +++ b/src/rooms.rs @@ -2,3 +2,4 @@ pub mod list_rooms; pub mod room_details; +pub mod room_members; diff --git a/src/rooms/room_members.rs b/src/rooms/room_members.rs new file mode 100644 index 0000000..5db1b64 --- /dev/null +++ b/src/rooms/room_members.rs @@ -0,0 +1,3 @@ +//! Different versions of the endpoint to list room members. + +pub mod v1; diff --git a/src/rooms/room_members/v1.rs b/src/rooms/room_members/v1.rs new file mode 100644 index 0000000..364a986 --- /dev/null +++ b/src/rooms/room_members/v1.rs @@ -0,0 +1,44 @@ +//! [GET /_synapse/admin/v1/rooms/:room_id/members](https://github.com/element-hq/synapse/blob/master/docs/admin_api/rooms.md#room-members-api) +use ruma::{ + api::{metadata, request, response, Metadata}, + OwnedRoomId, OwnedUserId, UInt, +}; + +const METADATA: Metadata = metadata! { + method: GET, + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_synapse/admin/v1/rooms/:room_id/members", + } +}; + +#[request] +pub struct Request { + /// ID of the room to list the members of. + #[ruma_api(path)] + pub room_id: OwnedRoomId, +} + +#[response] +pub struct Response { + /// List of members that are present in the room + pub members: Vec, + + /// Amount of members in the room. + pub total: UInt, +} + +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 members and total count, + pub fn new(members: Vec, total: UInt) -> Self { + Self { members, total } + } +}