diff --git a/ruma-client-api/src/r0/membership/get_member_events.rs b/ruma-client-api/src/r0/membership/get_member_events.rs index 5d888e20..3daa9e69 100644 --- a/ruma-client-api/src/r0/membership/get_member_events.rs +++ b/ruma-client-api/src/r0/membership/get_member_events.rs @@ -16,16 +16,17 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The room to get the member events for. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The point in time (pagination token) to return members for in the room. This token can /// be obtained from a prev_batch token returned for each room by the sync API. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub at: Option, + pub at: Option<&'a str>, /// The kind of memberships to filter for. Defaults to no filtering if unspecified. When /// specified alongside not_membership, the two parameters create an 'or' condition: either @@ -41,6 +42,7 @@ ruma_api! { pub not_membership: Option, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// A list of member events. pub chunk: Vec> @@ -49,8 +51,23 @@ 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, at: None, membership: None, not_membership: None } + } +} + +impl Response { + /// Creates a new `Response` with the given member event chunk. + pub fn new(chunk: Vec>) -> Self { + Self { chunk } + } +} + /// The kind of membership events to filter for. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(rename_all = "lowercase")] pub enum MembershipEventFilter { /// The user has joined. @@ -72,7 +89,7 @@ mod tests { use matches::assert_matches; - use super::{MembershipEventFilter, Request}; + use super::{IncomingRequest, MembershipEventFilter}; #[test] fn deserialization() { @@ -87,12 +104,12 @@ mod tests { .build() .unwrap(); - let req: Result = + let req: Result = http::Request::builder().uri(uri).body(Vec::::new()).unwrap().try_into(); assert_matches!( req, - Ok(Request { + Ok(IncomingRequest { room_id, at: Some(at), membership: None, diff --git a/ruma-client-api/src/r0/membership/joined_members.rs b/ruma-client-api/src/r0/membership/joined_members.rs index adc7dc77..e682b5b4 100644 --- a/ruma-client-api/src/r0/membership/joined_members.rs +++ b/ruma-client-api/src/r0/membership/joined_members.rs @@ -16,12 +16,14 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The room to get the members of. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// A list of the rooms the user is in, i.e. /// the ID of each room in which the user has joined membership. @@ -31,8 +33,23 @@ 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 joined rooms. + pub fn new(joined: BTreeMap) -> Self { + Self { joined } + } +} + /// Information about a room member. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomMember { /// The display name of the user. #[serde(skip_serializing_if = "Option::is_none")] @@ -42,3 +59,10 @@ pub struct RoomMember { #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, } + +impl RoomMember { + /// Creates an empty `RoomMember`. + pub fn new() -> Self { + Default::default() + } +} diff --git a/ruma-client-api/src/r0/membership/joined_rooms.rs b/ruma-client-api/src/r0/membership/joined_rooms.rs index 3bf0a6ad..23519c01 100644 --- a/ruma-client-api/src/r0/membership/joined_rooms.rs +++ b/ruma-client-api/src/r0/membership/joined_rooms.rs @@ -13,8 +13,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: {} + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// A list of the rooms the user is in, i.e. the ID of each room in /// which the user has joined membership. @@ -23,3 +26,17 @@ ruma_api! { error: crate::Error } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given joined rooms. + pub fn new(joined_rooms: Vec) -> Self { + Self { joined_rooms } + } +}