Skip to main content

synapse_admin_api/rooms/list_rooms/
v1.rs

1//! [GET /_synapse/admin/v1/rooms](https://github.com/element-hq/synapse/blob/master/docs/admin_api/rooms.md#list-room-api)
2use ruma::{
3    OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UInt,
4    api::{auth_scheme::AccessToken, metadata, request, response},
5    events::room::{guest_access::GuestAccess, history_visibility::HistoryVisibility},
6    room::{JoinRuleKind, RoomType},
7    serde::StringEnum,
8    uint,
9};
10use serde::{Deserialize, Serialize};
11
12metadata! {
13    method: GET,
14    rate_limited: false,
15    authentication: AccessToken,
16    path: "/_synapse/admin/v1/rooms",
17}
18
19#[request]
20#[derive(Default)]
21pub struct Request {
22    /// Offset in the returned list. Defaults to 0.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    #[ruma_api(query)]
25    pub from: Option<UInt>,
26
27    /// Maximum amount of rooms to return. Defaults to 100.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    #[ruma_api(query)]
30    pub limit: Option<UInt>,
31
32    /// Sort order of the response.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    #[ruma_api(query)]
35    pub order_by: Option<RoomSortOrder>,
36
37    /// Sort direction of the response.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    #[ruma_api(query)]
40    pub dir: Option<SortDirection>,
41
42    /// Filter rooms by their room name. Search term can be contained in any part of the room name.
43    /// Defaults to no filtering.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[ruma_api(query)]
46    pub search_term: Option<String>,
47}
48
49#[derive(Default)]
50#[response]
51pub struct Response {
52    /// List all RoomDetails.
53    pub rooms: Vec<RoomDetails>,
54
55    /// Offset.
56    pub offset: UInt,
57
58    /// Total amount of rooms.
59    pub total_rooms: UInt,
60
61    /// Token to receive the next RoomDetails batch.
62    pub next_batch: Option<UInt>,
63
64    /// Token to receive the previous RoomDetails batch.
65    pub prev_batch: Option<UInt>,
66}
67
68impl Request {
69    /// Creates an empty `Request`.
70    pub fn new() -> Self {
71        Default::default()
72    }
73}
74
75impl Response {
76    /// Creates an empty `Response`.
77    pub fn new() -> Self {
78        Default::default()
79    }
80}
81
82/// Enum to define the sorting method of rooms.
83#[derive(Clone, StringEnum)]
84#[ruma_enum(rename_all = "snake_case")]
85#[non_exhaustive]
86pub enum RoomSortOrder {
87    /// Sort by name alphabetical
88    Name,
89
90    /// Sort by canonical alias
91    CanonicalAlias,
92
93    /// Sort by joined members
94    JoinedMembers,
95
96    /// Sort by joined local members
97    JoinedLocalMembers,
98
99    /// Sort by version
100    Version,
101
102    /// Sort by creator
103    Creator,
104
105    /// Sort by encryption
106    Encryption,
107
108    /// Sort by feaeratable
109    Federatable,
110
111    /// Sort by public
112    Public,
113
114    /// Sort by join rules
115    JoinRules,
116
117    /// Sort by guest access
118    GuestAccess,
119
120    /// Sort by history visibility
121    HistoryVisibility,
122
123    /// Sort by state events
124    StateEvents,
125
126    #[doc(hidden)]
127    _Custom(crate::PrivOwnedStr),
128}
129
130/// Enum to define the sort order direction.
131#[derive(Clone, StringEnum)]
132#[non_exhaustive]
133pub enum SortDirection {
134    /// Sort direction backward.
135    #[ruma_enum(rename = "b")]
136    Backward,
137
138    /// Sort direction forward.
139    #[ruma_enum(rename = "f")]
140    Forward,
141
142    #[doc(hidden)]
143    _Custom(crate::PrivOwnedStr),
144}
145
146/// Structure for all the room details.
147#[derive(Serialize, Deserialize, Clone, Debug)]
148#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
149pub struct RoomDetails {
150    /// Room ID
151    pub room_id: OwnedRoomId,
152
153    /// Room name
154    pub name: Option<String>,
155
156    /// Room alias ID
157    pub canonical_alias: Option<OwnedRoomAliasId>,
158
159    /// Amount of joined members.
160    pub joined_members: UInt,
161
162    /// Amount of local members.
163    pub joined_local_members: UInt,
164
165    /// Room version
166    pub version: Option<String>,
167
168    /// User ID of the room creator.
169    #[serde(deserialize_with = "ruma::serde::empty_string_as_none")]
170    pub creator: Option<OwnedUserId>,
171
172    /// Room encryption.
173    pub encryption: Option<String>,
174
175    /// Whether the room is federatable
176    #[serde(deserialize_with = "crate::serde::bool_or_uint")]
177    pub federatable: bool,
178
179    /// Whether the room is public.
180    #[serde(deserialize_with = "crate::serde::bool_or_uint")]
181    pub public: bool,
182
183    /// Join rules of the room.
184    pub join_rules: Option<JoinRuleKind>,
185
186    /// Guest access of the room
187    pub guest_access: Option<GuestAccess>,
188
189    /// History visibility of the room
190    pub history_visibility: Option<HistoryVisibility>,
191
192    /// State events of the room.
193    pub state_events: UInt,
194
195    /// Room type of the room.
196    pub room_type: Option<RoomType>,
197}
198
199impl RoomDetails {
200    /// Construct `RoomDetails` with the given room ID and all the other fields at their default
201    /// value.
202    pub fn new(room_id: OwnedRoomId) -> Self {
203        Self {
204            room_id,
205            name: None,
206            canonical_alias: None,
207            joined_members: uint!(0),
208            joined_local_members: uint!(0),
209            version: None,
210            creator: None,
211            encryption: None,
212            federatable: false,
213            public: false,
214            join_rules: None,
215            guest_access: None,
216            history_visibility: None,
217            state_events: uint!(0),
218            room_type: None,
219        }
220    }
221}