ruma_client_api/delayed_events/
get_all_delayed_events.rs1pub mod msc4140 {
6 use ruma_common::{
11 api::{auth_scheme::AccessToken, request, response},
12 metadata,
13 };
14
15 use crate::delayed_events::DelayedEventData;
16
17 metadata! {
18 method: GET,
19 rate_limited: true,
20 authentication: AccessToken,
21 history: {
22 unstable("org.matrix.msc4140") => "/_matrix/client/unstable/org.matrix.msc4140/delayed_events",
23 }
24 }
25
26 #[request]
28 pub struct Request {}
29
30 #[response]
32 pub struct Response {
33 pub delayed_events: Vec<DelayedEventData>,
35 }
36
37 impl Request {
38 pub fn new() -> Self {
40 Self {}
41 }
42 }
43
44 impl Default for Request {
45 fn default() -> Self {
46 Self::new()
47 }
48 }
49
50 impl Response {
51 pub fn new(delayed_events: Vec<DelayedEventData>) -> Self {
53 Self { delayed_events }
54 }
55 }
56
57 #[cfg(all(test, feature = "server"))]
58 mod server_tests {
59
60 use std::time::Duration;
61
62 use js_int::UInt;
63 use ruma_common::{
64 MilliSecondsSinceUnixEpoch, api::OutgoingResponseExt as _, owned_event_id,
65 owned_room_id, serde::Raw,
66 };
67 use ruma_events::TimelineEventType;
68 use serde_json::{Value as JsonValue, json};
69
70 use super::Response;
71 use crate::delayed_events::DelayedEventData;
72
73 #[test]
74 fn serialize_get_all_delayed_events_response() {
75 let content = json!({
76 "topic": "test topic"
77 })
78 .to_string();
79
80 let mut event0 = DelayedEventData::new(
81 "a_delay_id".to_owned(),
82 owned_room_id!("!roomid:example.org"),
83 TimelineEventType::RoomTopic,
84 Some("a_state_key".to_owned()),
85 Raw::from_json_string(content).unwrap(),
86 Duration::from_millis(103),
87 MilliSecondsSinceUnixEpoch(UInt::new(70000).unwrap()),
88 );
89
90 event0.event_id = Some(owned_event_id!("$event:imaginary.hs"));
91 event0.finalized_ts = Some(MilliSecondsSinceUnixEpoch(UInt::new(70103).unwrap()));
92
93 let response = Response::new(vec![event0]);
94
95 let response: http::Response<Vec<u8>> = response.try_into_http_response().unwrap();
96
97 assert_eq!(
98 json!({
99 "delayed_events" : [{
100 "content": {
101 "topic": "test topic"
102 },
103 "delay": 103,
104 "delay_id": "a_delay_id",
105 "event_id": "$event:imaginary.hs",
106 "finalised_ts": 70103,
107 "room_id": "!roomid:example.org",
108 "running_since": 70000,
109 "state_key": "a_state_key",
110 "type": "m.room.topic"
111 }]
112 }),
113 serde_json::from_slice::<JsonValue>(response.body()).unwrap()
114 );
115 }
116 }
117}