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

This commit is contained in:
Jonas Platte 2020-09-11 20:39:52 +02:00
parent de22a06976
commit bb9b2b4a06
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 52 additions and 4 deletions

View File

@ -15,12 +15,14 @@ ruma_api! {
requires_authentication: true, requires_authentication: true,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: { request: {
/// The room to look up the state for. /// The room to look up the state for.
#[ruma_api(path)] #[ruma_api(path)]
pub room_id: RoomId, pub room_id: &'a RoomId,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: { response: {
/// If the user is a member of the room this will be the current state of the room as a /// 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 /// 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 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<Raw<AnyStateEvent>>) -> Self {
Self { room_state }
}
}

View File

@ -15,16 +15,18 @@ ruma_api! {
requires_authentication: true, requires_authentication: true,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: { request: {
/// The room to look up the state for. /// The room to look up the state for.
#[ruma_api(path)] #[ruma_api(path)]
pub room_id: RoomId, pub room_id: &'a RoomId,
/// The type of state to look up. /// The type of state to look up.
#[ruma_api(path)] #[ruma_api(path)]
pub event_type: EventType, pub event_type: EventType,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: { response: {
/// The content of the state event. /// The content of the state event.
/// ///
@ -35,3 +37,17 @@ ruma_api! {
error: crate::Error 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<RawJsonValue>) -> Self {
Self { content }
}
}

View File

@ -15,10 +15,11 @@ ruma_api! {
requires_authentication: true, requires_authentication: true,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: { request: {
/// The room to look up the state for. /// The room to look up the state for.
#[ruma_api(path)] #[ruma_api(path)]
pub room_id: RoomId, pub room_id: &'a RoomId,
/// The type of state to look up. /// The type of state to look up.
#[ruma_api(path)] #[ruma_api(path)]
@ -26,9 +27,10 @@ ruma_api! {
/// The key of the state to look up. /// The key of the state to look up.
#[ruma_api(path)] #[ruma_api(path)]
pub state_key: String, pub state_key: &'a str,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: { response: {
/// The content of the state event. /// The content of the state event.
#[ruma_api(body)] #[ruma_api(body)]
@ -37,3 +39,17 @@ ruma_api! {
error: crate::Error 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<RawJsonValue>) -> Self {
Self { content }
}
}