From 9f814a2415a56743cbcbfc7b7e74dffaf1be0ba7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 6 Sep 2020 01:31:14 +0200 Subject: [PATCH] client-api: Update room endpoints to the new API standards --- ruma-client-api/src/r0/room/aliases.rs | 19 ++++++++++++++- ruma-client-api/src/r0/room/get_room_event.rs | 22 +++++++++++++++--- ruma-client-api/src/r0/room/report_content.rs | 23 ++++++++++++++++--- ruma-client-api/src/r0/room/upgrade_room.rs | 22 +++++++++++++++--- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/ruma-client-api/src/r0/room/aliases.rs b/ruma-client-api/src/r0/room/aliases.rs index d9f74e9a..0d729d17 100644 --- a/ruma-client-api/src/r0/room/aliases.rs +++ b/ruma-client-api/src/r0/room/aliases.rs @@ -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, + /// The server's local aliases on the room. + pub aliases: Vec, } 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) -> Self { + Self { aliases } + } +} diff --git a/ruma-client-api/src/r0/room/get_room_event.rs b/ruma-client-api/src/r0/room/get_room_event.rs index d74e6cf5..d01d7461 100644 --- a/ruma-client-api/src/r0/room/get_room_event.rs +++ b/ruma-client-api/src/r0/room/get_room_event.rs @@ -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, } 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) -> Self { + Self { event } + } +} diff --git a/ruma-client-api/src/r0/room/report_content.rs b/ruma-client-api/src/r0/room/report_content.rs index 146ffa4a..fb635916 100644 --- a/ruma-client-api/src/r0/room/report_content.rs +++ b/ruma-client-api/src/r0/room/report_content.rs @@ -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 + } +} diff --git a/ruma-client-api/src/r0/room/upgrade_room.rs b/ruma-client-api/src/r0/room/upgrade_room.rs index 17832349..e6a080a8 100644 --- a/ruma-client-api/src/r0/room/upgrade_room.rs +++ b/ruma-client-api/src/r0/room/upgrade_room.rs @@ -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 } + } +}