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