ruma_client_api/threads/
get_threads.rs1pub mod v1 {
6 use js_int::UInt;
11 use ruma_common::{
12 OwnedRoomId,
13 api::{auth_scheme::AccessToken, request, response},
14 metadata,
15 serde::{Raw, StringEnum},
16 };
17 use ruma_events::AnyTimelineEvent;
18
19 use crate::PrivOwnedStr;
20
21 metadata! {
22 method: GET,
23 rate_limited: true,
24 authentication: AccessToken,
25 history: {
26 unstable => "/_matrix/client/unstable/org.matrix.msc3856/rooms/{room_id}/threads",
27 1.4 => "/_matrix/client/v1/rooms/{room_id}/threads",
28 }
29 }
30
31 #[request]
33 pub struct Request {
34 #[ruma_api(path)]
36 pub room_id: OwnedRoomId,
37
38 #[serde(skip_serializing_if = "Option::is_none")]
42 #[ruma_api(query)]
43 pub from: Option<String>,
44
45 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
47 #[ruma_api(query)]
48 pub include: IncludeThreads,
49
50 #[serde(skip_serializing_if = "Option::is_none")]
55 #[ruma_api(query)]
56 pub limit: Option<UInt>,
57 }
58
59 #[response]
61 pub struct Response {
62 pub chunk: Vec<Raw<AnyTimelineEvent>>,
66
67 #[serde(skip_serializing_if = "Option::is_none")]
72 pub next_batch: Option<String>,
73 }
74
75 impl Request {
76 pub fn new(room_id: OwnedRoomId) -> Self {
78 Self { room_id, from: None, include: IncludeThreads::default(), limit: None }
79 }
80 }
81
82 impl Response {
83 pub fn new(chunk: Vec<Raw<AnyTimelineEvent>>) -> Self {
85 Self { chunk, next_batch: None }
86 }
87 }
88
89 #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
91 #[derive(Clone, Default, StringEnum)]
92 #[ruma_enum(rename_all = "lowercase")]
93 #[non_exhaustive]
94 pub enum IncludeThreads {
95 #[default]
101 All,
102
103 Participated,
109
110 #[doc(hidden)]
111 _Custom(PrivOwnedStr),
112 }
113}
114
115#[cfg(all(test, feature = "server"))]
116mod tests {
117 use ruma_common::{api::IncomingRequest, room_id};
118
119 use super::v1::{IncludeThreads, Request};
120
121 #[test]
122 fn deserialize_request_without_include() {
125 let http_req = http::Request::builder()
126 .method(http::Method::GET)
127 .uri("/_matrix/client/v1/rooms/!room:example.com/threads")
128 .body(Vec::<u8>::new())
129 .unwrap();
130
131 let req = Request::try_from_http_request(http_req, &["!room:example.com"]).unwrap();
132
133 assert_eq!(req.room_id, room_id!("!room:example.com"));
134 assert_eq!(req.from, None);
135 assert_eq!(req.limit, None);
136 assert_eq!(req.include, IncludeThreads::All);
137 }
138
139 #[test]
140 fn deserialize_request_explicit_include() {
142 let http_req = http::Request::builder()
143 .method(http::Method::GET)
144 .uri("/_matrix/client/v1/rooms/!room:example.com/threads?include=participated")
145 .body(Vec::<u8>::new())
146 .unwrap();
147
148 let req = Request::try_from_http_request(http_req, &["!room:example.com"]).unwrap();
149
150 assert_eq!(req.room_id, room_id!("!room:example.com"));
151 assert_eq!(req.include, IncludeThreads::Participated);
152 }
153}