jacquard_api/chat_bsky/group/
request_join.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::value::Data;
16use jacquard_derive::{IntoStatic, open_union};
17use serde::{Serialize, Deserialize};
18use crate::chat_bsky::convo::ConvoView;
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct RequestJoin<S: BosStr = DefaultStr> {
23 pub code: S,
24 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
25 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
26}
27
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
30#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
31pub struct RequestJoinOutput<S: BosStr = DefaultStr> {
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub convo: Option<ConvoView<S>>,
35 pub status: RequestJoinOutputStatus<S>,
36 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
37 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
38}
39
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub enum RequestJoinOutputStatus<S: BosStr = DefaultStr> {
43 Joined,
44 Pending,
45 Other(S),
46}
47
48impl<S: BosStr> RequestJoinOutputStatus<S> {
49 pub fn as_str(&self) -> &str {
50 match self {
51 Self::Joined => "joined",
52 Self::Pending => "pending",
53 Self::Other(s) => s.as_ref(),
54 }
55 }
56 pub fn from_value(s: S) -> Self {
58 match s.as_ref() {
59 "joined" => Self::Joined,
60 "pending" => Self::Pending,
61 _ => Self::Other(s),
62 }
63 }
64}
65
66impl<S: BosStr> core::fmt::Display for RequestJoinOutputStatus<S> {
67 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
68 write!(f, "{}", self.as_str())
69 }
70}
71
72impl<S: BosStr> AsRef<str> for RequestJoinOutputStatus<S> {
73 fn as_ref(&self) -> &str {
74 self.as_str()
75 }
76}
77
78impl<S: BosStr> Serialize for RequestJoinOutputStatus<S> {
79 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
80 where
81 Ser: serde::Serializer,
82 {
83 serializer.serialize_str(self.as_str())
84 }
85}
86
87impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RequestJoinOutputStatus<S> {
88 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
89 where
90 D: serde::Deserializer<'de>,
91 {
92 let s = S::deserialize(deserializer)?;
93 Ok(Self::from_value(s))
94 }
95}
96
97impl<S: BosStr + Default> Default for RequestJoinOutputStatus<S> {
98 fn default() -> Self {
99 Self::Other(Default::default())
100 }
101}
102
103impl<S: BosStr> jacquard_common::IntoStatic for RequestJoinOutputStatus<S>
104where
105 S: BosStr + jacquard_common::IntoStatic,
106 S::Output: BosStr,
107{
108 type Output = RequestJoinOutputStatus<S::Output>;
109 fn into_static(self) -> Self::Output {
110 match self {
111 RequestJoinOutputStatus::Joined => RequestJoinOutputStatus::Joined,
112 RequestJoinOutputStatus::Pending => RequestJoinOutputStatus::Pending,
113 RequestJoinOutputStatus::Other(v) => {
114 RequestJoinOutputStatus::Other(v.into_static())
115 }
116 }
117 }
118}
119
120
121#[derive(
122 Serialize,
123 Deserialize,
124 Debug,
125 Clone,
126 PartialEq,
127 Eq,
128 thiserror::Error,
129 miette::Diagnostic
130)]
131
132#[serde(tag = "error", content = "message")]
133pub enum RequestJoinError {
134 #[serde(rename = "ConvoLocked")]
135 ConvoLocked(Option<SmolStr>),
136 #[serde(rename = "FollowRequired")]
137 FollowRequired(Option<SmolStr>),
138 #[serde(rename = "InvalidCode")]
139 InvalidCode(Option<SmolStr>),
140 #[serde(rename = "LinkDisabled")]
141 LinkDisabled(Option<SmolStr>),
142 #[serde(rename = "MemberLimitReached")]
143 MemberLimitReached(Option<SmolStr>),
144 #[serde(rename = "UserKicked")]
145 UserKicked(Option<SmolStr>),
146 #[serde(untagged)]
148 Other { error: SmolStr, message: Option<SmolStr> },
149}
150
151impl core::fmt::Display for RequestJoinError {
152 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
153 match self {
154 Self::ConvoLocked(msg) => {
155 write!(f, "ConvoLocked")?;
156 if let Some(msg) = msg {
157 write!(f, ": {}", msg)?;
158 }
159 Ok(())
160 }
161 Self::FollowRequired(msg) => {
162 write!(f, "FollowRequired")?;
163 if let Some(msg) = msg {
164 write!(f, ": {}", msg)?;
165 }
166 Ok(())
167 }
168 Self::InvalidCode(msg) => {
169 write!(f, "InvalidCode")?;
170 if let Some(msg) = msg {
171 write!(f, ": {}", msg)?;
172 }
173 Ok(())
174 }
175 Self::LinkDisabled(msg) => {
176 write!(f, "LinkDisabled")?;
177 if let Some(msg) = msg {
178 write!(f, ": {}", msg)?;
179 }
180 Ok(())
181 }
182 Self::MemberLimitReached(msg) => {
183 write!(f, "MemberLimitReached")?;
184 if let Some(msg) = msg {
185 write!(f, ": {}", msg)?;
186 }
187 Ok(())
188 }
189 Self::UserKicked(msg) => {
190 write!(f, "UserKicked")?;
191 if let Some(msg) = msg {
192 write!(f, ": {}", msg)?;
193 }
194 Ok(())
195 }
196 Self::Other { error, message } => {
197 write!(f, "{}", error)?;
198 if let Some(msg) = message {
199 write!(f, ": {}", msg)?;
200 }
201 Ok(())
202 }
203 }
204 }
205}
206
207pub struct RequestJoinResponse;
211impl jacquard_common::xrpc::XrpcResp for RequestJoinResponse {
212 const NSID: &'static str = "chat.bsky.group.requestJoin";
213 const ENCODING: &'static str = "application/json";
214 type Output<S: BosStr> = RequestJoinOutput<S>;
215 type Err = RequestJoinError;
216}
217
218impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for RequestJoin<S> {
219 const NSID: &'static str = "chat.bsky.group.requestJoin";
220 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
221 "application/json",
222 );
223 type Response = RequestJoinResponse;
224}
225
226pub struct RequestJoinRequest;
230impl jacquard_common::xrpc::XrpcEndpoint for RequestJoinRequest {
231 const PATH: &'static str = "/xrpc/chat.bsky.group.requestJoin";
232 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
233 "application/json",
234 );
235 type Request<S: BosStr> = RequestJoin<S>;
236 type Response = RequestJoinResponse;
237}