client-api: Update room endpoints to the new API standards

This commit is contained in:
Jonas Platte 2020-09-06 01:31:14 +02:00
parent a012ad3532
commit 9f814a2415
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
4 changed files with 76 additions and 10 deletions

View File

@ -13,15 +13,32 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The room ID to get aliases of.
#[ruma_api(path)]
pub room_id: &'a RoomId,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
aliases: Vec<RoomAliasId>,
/// The server's local aliases on the room.
pub aliases: Vec<RoomAliasId>,
}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room ID.
pub fn new(room_id: &'a RoomId) -> Self {
Self { room_id }
}
}
impl Response {
/// Creates a new `Response` with the given aliases.
pub fn new(aliases: Vec<RoomAliasId>) -> Self {
Self { aliases }
}
}

View File

@ -15,21 +15,37 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The ID of the room the event is in.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a RoomId,
/// The ID of the event.
#[ruma_api(path)]
pub event_id: EventId,
pub event_id: &'a EventId,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
/// Arbitrary JSON of the event body. Returns both room and state events.
/// Arbitrary JSON of the event body.
#[ruma_api(body)]
pub event: Raw<AnyRoomEvent>,
}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room ID and event ID.
pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self {
Self { room_id, event_id }
}
}
impl Response {
/// Creates a new `Response` with the given event.
pub fn new(event: Raw<AnyRoomEvent>) -> Self {
Self { event }
}
}

View File

@ -14,23 +14,40 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// Room in which the event to be reported is located.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a RoomId,
/// Event to report.
#[ruma_api(path)]
pub event_id: EventId,
pub event_id: &'a EventId,
/// Integer between -100 and 0 rating offensivness.
pub score: Int,
/// Reason to report content. May be blank.
pub reason: String,
pub reason: &'a str,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room ID, event ID, score and reason.
pub fn new(room_id: &'a RoomId, event_id: &'a EventId, score: Int, reason: &'a str) -> Self {
Self { room_id, event_id, score, reason }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -1,7 +1,7 @@
//! [POST /_matrix/client/r0/rooms/{roomId}/upgrade](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-upgrade)
use ruma_api::ruma_api;
use ruma_identifiers::RoomId;
use ruma_identifiers::{RoomId, RoomVersionId};
ruma_api! {
metadata: {
@ -13,15 +13,17 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// ID of the room to be upgraded.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a RoomId,
/// New version for the room.
pub new_version: String,
pub new_version: &'a RoomVersionId,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
/// ID of the new room.
pub replacement_room: RoomId,
@ -29,3 +31,17 @@ ruma_api! {
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room ID and new room version.
pub fn new(room_id: &'a RoomId, new_version: &'a RoomVersionId) -> Self {
Self { room_id, new_version }
}
}
impl Response {
/// Creates a new `Response` with the given room ID.
pub fn new(replacement_room: RoomId) -> Self {
Self { replacement_room }
}
}