Update public room list endpoints to r0.6.0

This commit is contained in:
Jonas Platte 2019-11-11 19:54:24 +01:00
parent 6ae72856d7
commit c56469eba5
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
4 changed files with 123 additions and 34 deletions

10
CHANGELOG.md Normal file
View File

@ -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)

View File

@ -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<Vec<RoomAliasId>>,
/// The canonical alias of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub canonical_alias: Option<String>,
/// The name of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// 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<String>,
/// 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<String>,
}

View File

@ -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<UInt>,
/// Pagination token from a previous request.
#[serde(skip_serializing_if = "Option::is_none")]
since: Option<String>,
/// 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<String>,
}
response {
/// A pagination token for the response.
pub start: String,
/// A paginated chunk of public rooms.
pub chunk: Vec<PublicRoomsChunk>,
/// A pagination token for the response.
pub end: String
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
/// 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<Vec<RoomAliasId>>,
/// The URL for the room's avatar, if one is set.
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>,
/// 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<String>,
/// 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<String>,
/// Whether the room may be viewed by guest users without joining.
pub world_readable: bool,
}

View File

@ -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<String>,
/// Limit for the number of results to return.
#[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(body)]
limit: Option<UInt>,
/// Pagination token from a previous request.
#[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(body)]
since: Option<String>,
/// Filter to apply to the results.
#[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(body)]
filter: Option<Filter>,
}
response {
/// A paginated chunk of public rooms.
pub chunk: Vec<PublicRoomsChunk>,
/// A pagination token for the response.
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
/// 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<String>,
}