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