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