From 01344edc8db3586d4ce5d2c1e7cf1d4e41f06eb2 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Sat, 20 May 2023 22:24:22 +0200 Subject: [PATCH] Update Mutual Rooms (MSC2666) implementation (#1547) --- .../src/membership/mutual_rooms.rs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/ruma-client-api/src/membership/mutual_rooms.rs b/crates/ruma-client-api/src/membership/mutual_rooms.rs index f13737c2..5b3a94d4 100644 --- a/crates/ruma-client-api/src/membership/mutual_rooms.rs +++ b/crates/ruma-client-api/src/membership/mutual_rooms.rs @@ -17,7 +17,7 @@ pub mod unstable { rate_limited: true, authentication: AccessToken, history: { - unstable => "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/:user_id", + unstable => "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms", } }; @@ -25,8 +25,14 @@ pub mod unstable { #[request(error = crate::Error)] pub struct Request { /// The user to search mutual rooms for. - #[ruma_api(path)] + #[ruma_api(query)] pub user_id: OwnedUserId, + + /// The `next_batch_token` returned from a previous response, to get the next batch of + /// rooms. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub batch_token: Option, } /// Response type for the `mutual_rooms` endpoint. @@ -34,19 +40,33 @@ pub mod unstable { pub struct Response { /// A list of rooms the user is in together with the authenticated user. pub joined: Vec, + + /// An opaque string, returned when the server paginates this response. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch_token: Option, } impl Request { /// Creates a new `Request` with the given user id. pub fn new(user_id: OwnedUserId) -> Self { - Self { user_id } + Self { user_id, batch_token: None } + } + + /// Creates a new `Request` with the given user id, together with a batch token. + pub fn with_token(user_id: OwnedUserId, token: String) -> Self { + Self { user_id, batch_token: Some(token) } } } impl Response { /// Creates a `Response` with the given room ids. pub fn new(joined: Vec) -> Self { - Self { joined } + Self { joined, next_batch_token: None } + } + + /// Creates a `Response` with the given room ids, together with a batch token. + pub fn with_token(joined: Vec, token: String) -> Self { + Self { joined, next_batch_token: Some(token) } } } }