1//! `GET /_matrix/client/*/rooms/{roomId}/members`
2//!
3//! Get membership events for a room.
45pub mod v3 {
6//! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3roomsroomidmembers
910use ruma_common::{
11 api::{request, response, Metadata},
12 metadata,
13 serde::{Raw, StringEnum},
14 OwnedRoomId,
15 };
16use ruma_events::room::member::RoomMemberEvent;
1718use crate::PrivOwnedStr;
1920const METADATA: Metadata = metadata! {
21 method: GET,
22 rate_limited: false,
23 authentication: AccessToken,
24 history: {
251.0 => "/_matrix/client/r0/rooms/:room_id/members",
261.1 => "/_matrix/client/v3/rooms/:room_id/members",
27 }
28 };
2930/// Request type for the `get_member_events` endpoint.
31#[request(error = crate::Error)]
32pub struct Request {
33/// The room to get the member events for.
34#[ruma_api(path)]
35pub room_id: OwnedRoomId,
3637/// The point in time (pagination token) to return members for in the room.
38 ///
39 /// This token can be obtained from a prev_batch token returned for each room by the sync
40 /// API.
41#[serde(skip_serializing_if = "Option::is_none")]
42 #[ruma_api(query)]
43pub at: Option<String>,
4445/// The kind of memberships to filter for.
46 ///
47 /// Defaults to no filtering if unspecified. When specified alongside not_membership, the
48 /// two parameters create an 'or' condition: either the membership is the same as
49 /// membership or is not the same as not_membership.
50#[serde(skip_serializing_if = "Option::is_none")]
51 #[ruma_api(query)]
52pub membership: Option<MembershipEventFilter>,
5354/// The kind of memberships to *exclude* from the results.
55 ///
56 /// Defaults to no filtering if unspecified.
57#[serde(skip_serializing_if = "Option::is_none")]
58 #[ruma_api(query)]
59pub not_membership: Option<MembershipEventFilter>,
60 }
6162/// Response type for the `get_member_events` endpoint.
63#[response(error = crate::Error)]
64pub struct Response {
65/// A list of member events.
66pub chunk: Vec<Raw<RoomMemberEvent>>,
67 }
6869impl Request {
70/// Creates a new `Request` with the given room ID.
71pub fn new(room_id: OwnedRoomId) -> Self {
72Self { room_id, at: None, membership: None, not_membership: None }
73 }
74 }
7576impl Response {
77/// Creates a new `Response` with the given member event chunk.
78pub fn new(chunk: Vec<Raw<RoomMemberEvent>>) -> Self {
79Self { chunk }
80 }
81 }
8283/// The kind of membership events to filter for.
84#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
85 #[derive(Clone, PartialEq, Eq, StringEnum)]
86 #[ruma_enum(rename_all = "lowercase")]
87 #[non_exhaustive]
88pub enum MembershipEventFilter {
89/// The user has joined.
90Join,
9192/// The user has been invited.
93Invite,
9495/// The user has left.
96Leave,
9798/// The user has been banned.
99Ban,
100101#[doc(hidden)]
102_Custom(PrivOwnedStr),
103 }
104105#[cfg(all(test, feature = "server"))]
106mod tests {
107use ruma_common::api::IncomingRequest as _;
108109use super::{MembershipEventFilter, Request};
110111#[test]
112fn deserialization() {
113let uri = http::Uri::builder()
114 .scheme("https")
115 .authority("example.org")
116 .path_and_query(
117"/_matrix/client/r0/rooms/!dummy%3Aexample.org/members\
118 ?not_membership=leave\
119 &at=1026",
120 )
121 .build()
122 .unwrap();
123124let req = Request::try_from_http_request(
125 http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(),
126&["!dummy:example.org"],
127 )
128 .unwrap();
129130assert_eq!(req.room_id, "!dummy:example.org");
131assert_eq!(req.at.as_deref(), Some("1026"));
132assert_eq!(req.membership, None);
133assert_eq!(req.not_membership, Some(MembershipEventFilter::Leave));
134 }
135 }
136}