diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..45d4b6d5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# [unreleased] + +Breaking changes: + +* Move `r0::directory::get_public_rooms::PublicRoomsChunk` to `r0::directory::PublicRoomsChunk` + +Improvements: + +* Update `r0::directory::get_public_rooms` from r0.3.0 to r0.6.0 +* Add `r0::directory::get_public_rooms_filtered` (introduced upstream in r0.3.0) diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 7108a7ca..bd5ebff9 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1,3 +1,38 @@ //! Endpoints for the public room directory. pub mod get_public_rooms; +pub mod get_public_rooms_filtered; + +use js_int::UInt; +use ruma_identifiers::{RoomAliasId, RoomId}; +use serde::{Deserialize, Serialize}; + +/// A chunk of a room list response, describing one room +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct PublicRoomsChunk { + /// Aliases of the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub aliases: Option>, + /// The canonical alias of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub canonical_alias: Option, + /// The name of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// The number of members joined to the room. + pub num_joined_members: UInt, + /// The ID of the room. + pub room_id: RoomId, + /// The topic of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// Whether the room may be viewed by guest users without joining. + pub world_readable: bool, + /// Whether guest users may join the room and participate in it. + /// + /// If they can, they will be subject to ordinary power level rules like any other user. + pub guest_can_join: bool, + /// The URL for the room's avatar, if one is set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, +} diff --git a/src/r0/directory/get_public_rooms.rs b/src/r0/directory/get_public_rooms.rs index 301af00a..5586bf77 100644 --- a/src/r0/directory/get_public_rooms.rs +++ b/src/r0/directory/get_public_rooms.rs @@ -1,9 +1,9 @@ -//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) +//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-r0-publicrooms) use js_int::UInt; use ruma_api::ruma_api; -use ruma_identifiers::{RoomAliasId, RoomId}; -use serde::{Deserialize, Serialize}; + +use super::PublicRoomsChunk; ruma_api! { metadata { @@ -15,41 +15,28 @@ ruma_api! { requires_authentication: false, } - request {} + request { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + limit: Option, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + since: Option, + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + server: Option, + } response { - /// A pagination token for the response. - pub start: String, /// A paginated chunk of public rooms. pub chunk: Vec, /// A pagination token for the response. - pub end: String + pub next_batch: Option, + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, } } - -/// A chunk of the response, describing one room -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct PublicRoomsChunk { - /// Aliases of the room. - //#[serde(skip_serializing_if = "Option::is_none")] - pub aliases: Option>, - /// The URL for the room's avatar, if one is set. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - /// Whether guest users may join the room and participate in it. - /// - /// If they can, they will be subject to ordinary power level rules like any other user. - pub guest_can_join: bool, - /// The name of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - /// The number of members joined to the room. - pub num_joined_members: UInt, - /// The ID of the room. - pub room_id: RoomId, - /// The topic of the room, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - /// Whether the room may be viewed by guest users without joining. - pub world_readable: bool, -} diff --git a/src/r0/directory/get_public_rooms_filtered.rs b/src/r0/directory/get_public_rooms_filtered.rs new file mode 100644 index 00000000..b8bf71de --- /dev/null +++ b/src/r0/directory/get_public_rooms_filtered.rs @@ -0,0 +1,57 @@ +//! [POST /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-publicrooms) + +use js_int::UInt; +use ruma_api::ruma_api; +use serde::{Deserialize, Serialize}; + +use super::PublicRoomsChunk; + +ruma_api! { + metadata { + description: "Get the list of rooms in this homeserver's public directory.", + method: POST, + name: "get_public_rooms_filtered", + path: "/_matrix/client/r0/publicRooms", + rate_limited: false, + requires_authentication: true, + } + + request { + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + server: Option, + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + limit: Option, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + since: Option, + /// Filter to apply to the results. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(body)] + filter: Option, + } + + response { + /// A paginated chunk of public rooms. + pub chunk: Vec, + /// A pagination token for the response. + pub next_batch: Option, + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, + } +} + +/// A filter for public rooms lists +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Filter { + /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. + #[serde(skip_serializing_if = "Option::is_none")] + generic_search_term: Option, +}