ruma_client_api/context/
get_context.rs1pub mod v3 {
6 use js_int::{uint, UInt};
11 use ruma_common::{
12 api::{request, response, Metadata},
13 metadata,
14 serde::Raw,
15 OwnedEventId, OwnedRoomId,
16 };
17 use ruma_events::{AnyStateEvent, AnyTimelineEvent};
18
19 use crate::filter::RoomEventFilter;
20
21 const METADATA: Metadata = metadata! {
22 method: GET,
23 rate_limited: false,
24 authentication: AccessToken,
25 history: {
26 1.0 => "/_matrix/client/r0/rooms/:room_id/context/:event_id",
27 1.1 => "/_matrix/client/v3/rooms/:room_id/context/:event_id",
28 }
29 };
30
31 #[request(error = crate::Error)]
33 pub struct Request {
34 #[ruma_api(path)]
36 pub room_id: OwnedRoomId,
37
38 #[ruma_api(path)]
40 pub event_id: OwnedEventId,
41
42 #[ruma_api(query)]
49 #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")]
50 pub limit: UInt,
51
52 #[ruma_api(query)]
54 #[serde(
55 with = "ruma_common::serde::json_string",
56 default,
57 skip_serializing_if = "RoomEventFilter::is_empty"
58 )]
59 pub filter: RoomEventFilter,
60 }
61
62 #[response(error = crate::Error)]
64 #[derive(Default)]
65 pub struct Response {
66 #[serde(skip_serializing_if = "Option::is_none")]
68 pub start: Option<String>,
69
70 #[serde(skip_serializing_if = "Option::is_none")]
72 pub end: Option<String>,
73
74 #[serde(default, skip_serializing_if = "Vec::is_empty")]
77 pub events_before: Vec<Raw<AnyTimelineEvent>>,
78
79 #[serde(skip_serializing_if = "Option::is_none")]
81 pub event: Option<Raw<AnyTimelineEvent>>,
82
83 #[serde(default, skip_serializing_if = "Vec::is_empty")]
86 pub events_after: Vec<Raw<AnyTimelineEvent>>,
87
88 #[serde(default, skip_serializing_if = "Vec::is_empty")]
90 pub state: Vec<Raw<AnyStateEvent>>,
91 }
92
93 impl Request {
94 pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self {
96 Self { room_id, event_id, limit: default_limit(), filter: RoomEventFilter::default() }
97 }
98 }
99
100 impl Response {
101 pub fn new() -> Self {
103 Default::default()
104 }
105 }
106
107 fn default_limit() -> UInt {
108 uint!(10)
109 }
110
111 #[allow(clippy::trivially_copy_pass_by_ref)]
112 fn is_default_limit(val: &UInt) -> bool {
113 *val == default_limit()
114 }
115}