ruma_client_api/threads/
get_thread_updates.rs1pub mod msc4360 {
6 use std::collections::BTreeMap;
11
12 use js_int::UInt;
13 use ruma_common::{
14 OwnedEventId, OwnedRoomId,
15 api::{Direction, auth_scheme::AccessToken, request, response},
16 metadata,
17 serde::Raw,
18 };
19 use ruma_events::AnySyncTimelineEvent;
20 use serde::{Deserialize, Serialize};
21
22 metadata! {
23 method: GET,
24 rate_limited: true,
25 authentication: AccessToken,
26 history: {
27 unstable => "/_matrix/client/unstable/io.element.msc4360/thread_updates",
28 }
29 }
30
31 #[request]
33 pub struct Request {
34 #[ruma_api(query)]
39 #[allow(dead_code)]
41 dir: Direction,
42
43 #[ruma_api(query)]
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub from: Option<String>,
54
55 #[ruma_api(query)]
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub to: Option<String>,
62
63 #[ruma_api(query)]
67 #[serde(skip_serializing_if = "Option::is_none")]
68 pub limit: Option<UInt>,
69 }
70
71 #[response]
73 pub struct Response {
74 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
76 pub chunk: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, ThreadUpdate>>,
77
78 #[serde(skip_serializing_if = "Option::is_none")]
81 pub next_batch: Option<String>,
82 }
83
84 impl Request {
85 pub fn new() -> Self {
87 Self { dir: Direction::Backward, from: None, to: None, limit: None }
88 }
89 }
90
91 impl Response {
92 pub fn new() -> Self {
94 Self { chunk: BTreeMap::new(), next_batch: None }
95 }
96 }
97
98 #[derive(Clone, Debug, Serialize, Deserialize)]
100 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
101 pub struct ThreadUpdate {
102 pub thread_root: Raw<AnySyncTimelineEvent>,
104
105 #[serde(skip_serializing_if = "Option::is_none")]
107 pub prev_batch: Option<String>,
108 }
109
110 impl ThreadUpdate {
111 pub fn new(thread_root: Raw<AnySyncTimelineEvent>) -> Self {
113 Self { thread_root, prev_batch: None }
114 }
115 }
116}
117
118#[cfg(all(test, feature = "server"))]
119mod tests {
120 use ruma_common::api::IncomingRequestExt as _;
121
122 use super::msc4360::Request;
123
124 #[test]
125 fn deserialize_request() {
126 let http_req = http::Request::builder()
127 .method(http::Method::GET)
128 .uri("/_matrix/client/unstable/io.element.msc4360/thread_updates?dir=b&from=s1&to=s2&limit=10")
129 .body(&[] as &[u8])
130 .unwrap();
131
132 let req = Request::try_from_http_request(http_req, &[] as &[&str]).unwrap();
133
134 assert_eq!(req.from.as_deref(), Some("s1"));
135 assert_eq!(req.to.as_deref(), Some("s2"));
136 assert_eq!(req.limit, Some(js_int::uint!(10)));
137 }
138}