jacquard_api/app_bsky/feed/
get_post_thread.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::string::AtUri;
16use jacquard_common::types::value::Data;
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Serialize, Deserialize};
19use crate::app_bsky::feed::BlockedPost;
20use crate::app_bsky::feed::NotFoundPost;
21use crate::app_bsky::feed::ThreadViewPost;
22use crate::app_bsky::feed::ThreadgateView;
23
24#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
25#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
26pub struct GetPostThread<S: BosStr = DefaultStr> {
27 #[serde(default = "_default_depth")]
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub depth: Option<i64>,
31 #[serde(default = "_default_parent_height")]
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub parent_height: Option<i64>,
35 pub uri: AtUri<S>,
36}
37
38
39#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
40#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
41pub struct GetPostThreadOutput<S: BosStr = DefaultStr> {
42 pub thread: GetPostThreadOutputThread<S>,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub threadgate: Option<ThreadgateView<S>>,
45 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
46 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
47}
48
49
50#[open_union]
51#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
52#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
53pub enum GetPostThreadOutputThread<S: BosStr = DefaultStr> {
54 #[serde(rename = "app.bsky.feed.defs#threadViewPost")]
55 ThreadViewPost(Box<ThreadViewPost<S>>),
56 #[serde(rename = "app.bsky.feed.defs#notFoundPost")]
57 NotFoundPost(Box<NotFoundPost<S>>),
58 #[serde(rename = "app.bsky.feed.defs#blockedPost")]
59 BlockedPost(Box<BlockedPost<S>>),
60}
61
62
63#[derive(
64 Serialize,
65 Deserialize,
66 Debug,
67 Clone,
68 PartialEq,
69 Eq,
70 thiserror::Error,
71 miette::Diagnostic
72)]
73
74#[serde(tag = "error", content = "message")]
75pub enum GetPostThreadError {
76 #[serde(rename = "NotFound")]
77 NotFound(Option<SmolStr>),
78 #[serde(untagged)]
80 Other { error: SmolStr, message: Option<SmolStr> },
81}
82
83impl core::fmt::Display for GetPostThreadError {
84 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 match self {
86 Self::NotFound(msg) => {
87 write!(f, "NotFound")?;
88 if let Some(msg) = msg {
89 write!(f, ": {}", msg)?;
90 }
91 Ok(())
92 }
93 Self::Other { error, message } => {
94 write!(f, "{}", error)?;
95 if let Some(msg) = message {
96 write!(f, ": {}", msg)?;
97 }
98 Ok(())
99 }
100 }
101 }
102}
103
104pub struct GetPostThreadResponse;
108impl jacquard_common::xrpc::XrpcResp for GetPostThreadResponse {
109 const NSID: &'static str = "app.bsky.feed.getPostThread";
110 const ENCODING: &'static str = "application/json";
111 type Output<S: BosStr> = GetPostThreadOutput<S>;
112 type Err = GetPostThreadError;
113}
114
115impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetPostThread<S> {
116 const NSID: &'static str = "app.bsky.feed.getPostThread";
117 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
118 type Response = GetPostThreadResponse;
119}
120
121pub struct GetPostThreadRequest;
125impl jacquard_common::xrpc::XrpcEndpoint for GetPostThreadRequest {
126 const PATH: &'static str = "/xrpc/app.bsky.feed.getPostThread";
127 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
128 type Request<S: BosStr> = GetPostThread<S>;
129 type Response = GetPostThreadResponse;
130}
131
132fn _default_depth() -> Option<i64> {
133 Some(6i64)
134}
135
136fn _default_parent_height() -> Option<i64> {
137 Some(80i64)
138}
139
140pub mod get_post_thread_state {
141
142 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
143 #[allow(unused)]
144 use ::core::marker::PhantomData;
145 mod sealed {
146 pub trait Sealed {}
147 }
148 pub trait State: sealed::Sealed {
150 type Uri;
151 }
152 pub struct Empty(());
154 impl sealed::Sealed for Empty {}
155 impl State for Empty {
156 type Uri = Unset;
157 }
158 pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
160 impl<St: State> sealed::Sealed for SetUri<St> {}
161 impl<St: State> State for SetUri<St> {
162 type Uri = Set<members::uri>;
163 }
164 #[allow(non_camel_case_types)]
166 pub mod members {
167 pub struct uri(());
169 }
170}
171
172pub struct GetPostThreadBuilder<
174 St: get_post_thread_state::State,
175 S: BosStr = DefaultStr,
176> {
177 _state: PhantomData<fn() -> St>,
178 _fields: (Option<i64>, Option<i64>, Option<AtUri<S>>),
179 _type: PhantomData<fn() -> S>,
180}
181
182impl GetPostThread<DefaultStr> {
183 pub fn new() -> GetPostThreadBuilder<get_post_thread_state::Empty, DefaultStr> {
185 GetPostThreadBuilder::new()
186 }
187}
188
189impl<S: BosStr> GetPostThread<S> {
190 pub fn builder() -> GetPostThreadBuilder<get_post_thread_state::Empty, S> {
192 GetPostThreadBuilder::builder()
193 }
194}
195
196impl GetPostThreadBuilder<get_post_thread_state::Empty, DefaultStr> {
197 pub fn new() -> Self {
199 GetPostThreadBuilder {
200 _state: PhantomData,
201 _fields: (None, None, None),
202 _type: PhantomData,
203 }
204 }
205}
206
207impl<S: BosStr> GetPostThreadBuilder<get_post_thread_state::Empty, S> {
208 pub fn builder() -> Self {
210 GetPostThreadBuilder {
211 _state: PhantomData,
212 _fields: (None, None, None),
213 _type: PhantomData,
214 }
215 }
216}
217
218impl<St: get_post_thread_state::State, S: BosStr> GetPostThreadBuilder<St, S> {
219 pub fn depth(mut self, value: impl Into<Option<i64>>) -> Self {
221 self._fields.0 = value.into();
222 self
223 }
224 pub fn maybe_depth(mut self, value: Option<i64>) -> Self {
226 self._fields.0 = value;
227 self
228 }
229}
230
231impl<St: get_post_thread_state::State, S: BosStr> GetPostThreadBuilder<St, S> {
232 pub fn parent_height(mut self, value: impl Into<Option<i64>>) -> Self {
234 self._fields.1 = value.into();
235 self
236 }
237 pub fn maybe_parent_height(mut self, value: Option<i64>) -> Self {
239 self._fields.1 = value;
240 self
241 }
242}
243
244impl<St, S: BosStr> GetPostThreadBuilder<St, S>
245where
246 St: get_post_thread_state::State,
247 St::Uri: get_post_thread_state::IsUnset,
248{
249 pub fn uri(
251 mut self,
252 value: impl Into<AtUri<S>>,
253 ) -> GetPostThreadBuilder<get_post_thread_state::SetUri<St>, S> {
254 self._fields.2 = Option::Some(value.into());
255 GetPostThreadBuilder {
256 _state: PhantomData,
257 _fields: self._fields,
258 _type: PhantomData,
259 }
260 }
261}
262
263impl<St, S: BosStr> GetPostThreadBuilder<St, S>
264where
265 St: get_post_thread_state::State,
266 St::Uri: get_post_thread_state::IsSet,
267{
268 pub fn build(self) -> GetPostThread<S> {
270 GetPostThread {
271 depth: self._fields.0,
272 parent_height: self._fields.1,
273 uri: self._fields.2.unwrap(),
274 }
275 }
276}