From bb9b2b4a061337a9a0ea76b2ee7e38e4b50c558a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 11 Sep 2020 20:39:52 +0200 Subject: [PATCH] client-api: Update state endpoints to the new API standards --- .../src/r0/state/get_state_events.rs | 18 ++++++++++++++++- .../state/get_state_events_for_empty_key.rs | 18 ++++++++++++++++- .../src/r0/state/get_state_events_for_key.rs | 20 +++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/ruma-client-api/src/r0/state/get_state_events.rs b/ruma-client-api/src/r0/state/get_state_events.rs index f7fcbf6e..c85eabc6 100644 --- a/ruma-client-api/src/r0/state/get_state_events.rs +++ b/ruma-client-api/src/r0/state/get_state_events.rs @@ -15,12 +15,14 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The room to look up the state for. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// If the user is a member of the room this will be the current state of the room as a /// list of events. If the user has left the room then this will be the state of the @@ -31,3 +33,17 @@ ruma_api! { 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 room state. + pub fn new(room_state: Vec>) -> Self { + Self { room_state } + } +} diff --git a/ruma-client-api/src/r0/state/get_state_events_for_empty_key.rs b/ruma-client-api/src/r0/state/get_state_events_for_empty_key.rs index b6f34ae8..01be6f3d 100644 --- a/ruma-client-api/src/r0/state/get_state_events_for_empty_key.rs +++ b/ruma-client-api/src/r0/state/get_state_events_for_empty_key.rs @@ -15,16 +15,18 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The room to look up the state for. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The type of state to look up. #[ruma_api(path)] pub event_type: EventType, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The content of the state event. /// @@ -35,3 +37,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID and event type. + pub fn new(room_id: &'a RoomId, event_type: EventType) -> Self { + Self { room_id, event_type } + } +} + +impl Response { + /// Creates a new `Response` with the given content. + pub fn new(content: Box) -> Self { + Self { content } + } +} diff --git a/ruma-client-api/src/r0/state/get_state_events_for_key.rs b/ruma-client-api/src/r0/state/get_state_events_for_key.rs index fe5feddd..cda33921 100644 --- a/ruma-client-api/src/r0/state/get_state_events_for_key.rs +++ b/ruma-client-api/src/r0/state/get_state_events_for_key.rs @@ -15,10 +15,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The room to look up the state for. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The type of state to look up. #[ruma_api(path)] @@ -26,9 +27,10 @@ ruma_api! { /// The key of the state to look up. #[ruma_api(path)] - pub state_key: String, + pub state_key: &'a str, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The content of the state event. #[ruma_api(body)] @@ -37,3 +39,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID, event type and state key. + pub fn new(room_id: &'a RoomId, event_type: EventType, state_key: &'a str) -> Self { + Self { room_id, event_type, state_key } + } +} + +impl Response { + /// Creates a new `Response` with the given content. + pub fn new(content: Box) -> Self { + Self { content } + } +}