Convert alias mod and get_public_rooms to use Outgoing trait
This commit is contained in:
parent
30e73186e7
commit
7f0f5be1fe
@ -20,10 +20,10 @@ ruma_api! {
|
||||
pub auth: Option<AuthData>,
|
||||
|
||||
/// Client-generated secret string used to protect this session.
|
||||
pub client_secret: String,
|
||||
pub client_secret: &'a str,
|
||||
|
||||
/// The session identifier given by the identity server.
|
||||
pub sid: String,
|
||||
pub sid: &'a str,
|
||||
}
|
||||
|
||||
response: {}
|
||||
|
@ -16,10 +16,10 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room alias to set.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
|
||||
/// The room ID to set.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
response: {}
|
||||
|
@ -16,7 +16,7 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room alias to remove.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
}
|
||||
|
||||
response: {}
|
||||
|
@ -16,15 +16,15 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room alias.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room ID for this room alias.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// A list of servers that are aware of this room ID.
|
||||
pub servers: Vec<String>,
|
||||
pub servers: &'a [String],
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
|
@ -6,33 +6,34 @@ pub mod get_room_visibility;
|
||||
pub mod set_room_visibility;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::Outgoing;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
/// A chunk of a room list response, describing one room
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct PublicRoomsChunk {
|
||||
#[derive(Clone, Debug, Outgoing, Serialize)]
|
||||
pub struct PublicRoomsChunk<'a> {
|
||||
/// Aliases of the room.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub aliases: Vec<RoomAliasId>,
|
||||
pub aliases: Vec<&'a RoomAliasId>,
|
||||
|
||||
/// The canonical alias of the room, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub canonical_alias: Option<RoomAliasId>,
|
||||
pub canonical_alias: Option<&'a RoomAliasId>,
|
||||
|
||||
/// The name of the room, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
pub name: Option<&'a str>,
|
||||
|
||||
/// The number of members joined to the room.
|
||||
pub num_joined_members: UInt,
|
||||
|
||||
/// The ID of the room.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The topic of the room, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub topic: Option<String>,
|
||||
pub topic: Option<&'a str>,
|
||||
|
||||
/// Whether the room may be viewed by guest users without joining.
|
||||
pub world_readable: bool,
|
||||
@ -44,5 +45,5 @@ pub struct PublicRoomsChunk {
|
||||
|
||||
/// The URL for the room's avatar, if one is set.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub avatar_url: Option<String>,
|
||||
pub avatar_url: Option<&'a str>,
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::PublicRoomsChunk;
|
||||
use super::{IncomingPublicRoomsChunk, PublicRoomsChunk};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -24,25 +24,25 @@ ruma_api! {
|
||||
/// Pagination token from a previous request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub since: Option<String>,
|
||||
pub since: Option<&'a str>,
|
||||
|
||||
/// 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")]
|
||||
#[ruma_api(query)]
|
||||
pub server: Option<String>,
|
||||
pub server: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
pub chunk: Vec<PublicRoomsChunk<'a>>,
|
||||
|
||||
/// A pagination token for the response.
|
||||
pub next_batch: Option<String>,
|
||||
pub next_batch: Option<&'a str>,
|
||||
|
||||
/// A pagination token that allows fetching previous results.
|
||||
pub prev_batch: Option<String>,
|
||||
pub prev_batch: Option<&'a str>,
|
||||
|
||||
/// An estimate on the total number of public rooms, if the server has an estimate.
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
@ -50,3 +50,38 @@ ruma_api! {
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_request_from_refs() {
|
||||
let req: http::Request<Vec<u8>> =
|
||||
Request { limit: Some(js_int::uint!(10)), since: Some("hello"), server: Some("address") }
|
||||
.try_into_http_request("https://homeserver.tld", Some("auth_tok"))
|
||||
.unwrap();
|
||||
|
||||
let uri = req.uri();
|
||||
let query = uri.query().unwrap();
|
||||
|
||||
assert_eq!(uri.path(), "/_matrix/client/r0/publicRooms");
|
||||
assert!(query.contains("since=hello"));
|
||||
assert!(query.contains("limit=10"));
|
||||
assert!(query.contains("server=address"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_response_from_refs() {
|
||||
use std::convert::TryInto;
|
||||
|
||||
let res: http::Response<Vec<u8>> = Response {
|
||||
chunk: vec![],
|
||||
next_batch: Some("next_batch_token"),
|
||||
prev_batch: Some("prev_batch_token"),
|
||||
total_room_count_estimate: Some(js_int::uint!(10)),
|
||||
}
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
String::from_utf8_lossy(res.body()),
|
||||
r#"{"chunk":[],"next_batch":"next_batch_token","prev_batch":"prev_batch_token","total_room_count_estimate":10}"#
|
||||
);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use serde::{
|
||||
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use super::PublicRoomsChunk;
|
||||
use super::{IncomingPublicRoomsChunk, PublicRoomsChunk};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -30,7 +30,7 @@ ruma_api! {
|
||||
/// `None` means the server this request is sent to.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ruma_api(query)]
|
||||
pub server: Option<String>,
|
||||
pub server: Option<&'a str>,
|
||||
|
||||
/// Limit for the number of results to return.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -38,7 +38,7 @@ ruma_api! {
|
||||
|
||||
/// Pagination token from a previous request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub since: Option<String>,
|
||||
pub since: Option<&'a str>,
|
||||
|
||||
/// Filter to apply to the results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -51,13 +51,13 @@ ruma_api! {
|
||||
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
pub chunk: Vec<PublicRoomsChunk<'a>>,
|
||||
|
||||
/// A pagination token for the response.
|
||||
pub next_batch: Option<String>,
|
||||
pub next_batch: Option<&'a str>,
|
||||
|
||||
/// A pagination token that allows fetching previous results.
|
||||
pub prev_batch: Option<String>,
|
||||
pub prev_batch: Option<&'a str>,
|
||||
|
||||
/// An estimate on the total number of public rooms, if the server has an estimate.
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user