Skip to main content

proto_blue_api/generated/tools/ozone/moderation/
queryStatuses.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: tools.ozone.moderation.queryStatuses
3
4use serde::{Deserialize, Serialize};
5
6/// View moderation statuses of subjects (record or repo).
7/// XRPC Query: tools.ozone.moderation.queryStatuses
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub age_assurance_state: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub appealed: Option<bool>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub collections: Option<Vec<String>>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub comment: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub cursor: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub exclude_tags: Option<Vec<String>>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub hosting_deleted_after: Option<String>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub hosting_deleted_before: Option<String>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub hosting_statuses: Option<Vec<String>>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub hosting_updated_after: Option<String>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub hosting_updated_before: Option<String>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub ignore_subjects: Option<Vec<String>>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub include_all_user_records: Option<bool>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub include_muted: Option<bool>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub last_reviewed_by: Option<String>,
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub limit: Option<i64>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub min_account_suspend_count: Option<i64>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub min_priority_score: Option<i64>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub min_reported_records_count: Option<i64>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub min_strike_count: Option<i64>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub min_takendown_records_count: Option<i64>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub only_muted: Option<bool>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub queue_count: Option<i64>,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub queue_index: Option<i64>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub queue_seed: Option<String>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub reported_after: Option<String>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub reported_before: Option<String>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub review_state: Option<String>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub reviewed_after: Option<String>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub reviewed_before: Option<String>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub sort_direction: Option<String>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub sort_field: Option<String>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub subject: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub subject_type: Option<String>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub tags: Option<Vec<String>>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub takendown: Option<bool>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(rename_all = "camelCase")]
87pub struct Output {
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub cursor: Option<String>,
90    pub subject_statuses: Vec<crate::tools::ozone::moderation::defs::SubjectStatusView>,
91}
92
93/// Errors a `call()` on this method can return.
94#[derive(Debug, thiserror::Error)]
95pub enum CallError {
96    #[error("{0}")]
97    Xrpc(proto_blue_xrpc::XrpcError),
98    #[error(transparent)]
99    Transport(#[from] proto_blue_xrpc::Error),
100    #[error(transparent)]
101    Json(#[from] serde_json::Error),
102}
103
104fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
105    CallError::Xrpc(err)
106}
107
108fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
109    let mut qp = proto_blue_xrpc::QueryParams::new();
110    if let Some(v) = &p.age_assurance_state { qp.insert("ageAssuranceState".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
111    if let Some(v) = &p.appealed { qp.insert("appealed".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
112    if let Some(v) = &p.collections { qp.insert("collections".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
113    if let Some(v) = &p.comment { qp.insert("comment".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
114    if let Some(v) = &p.cursor { qp.insert("cursor".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
115    if let Some(v) = &p.exclude_tags { qp.insert("excludeTags".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
116    if let Some(v) = &p.hosting_deleted_after { qp.insert("hostingDeletedAfter".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
117    if let Some(v) = &p.hosting_deleted_before { qp.insert("hostingDeletedBefore".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
118    if let Some(v) = &p.hosting_statuses { qp.insert("hostingStatuses".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
119    if let Some(v) = &p.hosting_updated_after { qp.insert("hostingUpdatedAfter".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
120    if let Some(v) = &p.hosting_updated_before { qp.insert("hostingUpdatedBefore".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
121    if let Some(v) = &p.ignore_subjects { qp.insert("ignoreSubjects".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
122    if let Some(v) = &p.include_all_user_records { qp.insert("includeAllUserRecords".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
123    if let Some(v) = &p.include_muted { qp.insert("includeMuted".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
124    if let Some(v) = &p.last_reviewed_by { qp.insert("lastReviewedBy".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
125    if let Some(v) = &p.limit { qp.insert("limit".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
126    if let Some(v) = &p.min_account_suspend_count { qp.insert("minAccountSuspendCount".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
127    if let Some(v) = &p.min_priority_score { qp.insert("minPriorityScore".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
128    if let Some(v) = &p.min_reported_records_count { qp.insert("minReportedRecordsCount".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
129    if let Some(v) = &p.min_strike_count { qp.insert("minStrikeCount".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
130    if let Some(v) = &p.min_takendown_records_count { qp.insert("minTakendownRecordsCount".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
131    if let Some(v) = &p.only_muted { qp.insert("onlyMuted".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
132    if let Some(v) = &p.queue_count { qp.insert("queueCount".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
133    if let Some(v) = &p.queue_index { qp.insert("queueIndex".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
134    if let Some(v) = &p.queue_seed { qp.insert("queueSeed".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
135    if let Some(v) = &p.reported_after { qp.insert("reportedAfter".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
136    if let Some(v) = &p.reported_before { qp.insert("reportedBefore".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
137    if let Some(v) = &p.review_state { qp.insert("reviewState".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
138    if let Some(v) = &p.reviewed_after { qp.insert("reviewedAfter".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
139    if let Some(v) = &p.reviewed_before { qp.insert("reviewedBefore".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
140    if let Some(v) = &p.sort_direction { qp.insert("sortDirection".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
141    if let Some(v) = &p.sort_field { qp.insert("sortField".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
142    if let Some(v) = &p.subject { qp.insert("subject".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
143    if let Some(v) = &p.subject_type { qp.insert("subjectType".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
144    if let Some(v) = &p.tags { qp.insert("tags".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
145    if let Some(v) = &p.takendown { qp.insert("takendown".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
146    qp
147}
148
149/// Execute the query.
150pub async fn call(
151    client: &proto_blue_xrpc::XrpcClient,
152    params: Option<&Params>,
153    opts: Option<&proto_blue_xrpc::CallOptions>,
154) -> Result<Output, CallError> {
155    let qp = params.map(to_query_params);
156    let response = match client.query("tools.ozone.moderation.queryStatuses", qp.as_ref(), opts).await {
157        Ok(r) => r,
158        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
159        Err(e) => return Err(CallError::Transport(e)),
160    };
161    Ok(serde_json::from_value(response.data)?)
162}
163
164/// Register a typed handler for this method on an [`XrpcServer`].
165#[cfg(feature = "server")]
166pub fn register<F, Fut>(
167server: proto_blue_xrpc::XrpcServer,
168handler: F,
169) -> proto_blue_xrpc::XrpcServer
170where
171    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
172    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
173{
174    let handler = std::sync::Arc::new(handler);
175    server.query("tools.ozone.moderation.queryStatuses", move |ctx| {
176        let handler = handler.clone();
177        async move {
178            let params = params_from_ctx(&ctx);
179            let out = handler(ctx, params).await?;
180            let value = serde_json::to_value(&out)
181                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
182            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
183        }
184    })
185}
186
187#[cfg(feature = "server")]
188fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
189    // Always construct a `Params` — required fields are
190    // validated upstream by the lexicon validator when enabled;
191    // missing values surface as runtime errors from the handler.
192    Some(Params {
193        age_assurance_state: ctx.params.get("ageAssuranceState").cloned(),
194        appealed: ctx.params.get("appealed").and_then(|v| v.parse::<bool>().ok()),
195        collections: Some(ctx.params.get("collections").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
196        comment: ctx.params.get("comment").cloned(),
197        cursor: ctx.params.get("cursor").cloned(),
198        exclude_tags: Some(ctx.params.get("excludeTags").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
199        hosting_deleted_after: ctx.params.get("hostingDeletedAfter").cloned(),
200        hosting_deleted_before: ctx.params.get("hostingDeletedBefore").cloned(),
201        hosting_statuses: Some(ctx.params.get("hostingStatuses").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
202        hosting_updated_after: ctx.params.get("hostingUpdatedAfter").cloned(),
203        hosting_updated_before: ctx.params.get("hostingUpdatedBefore").cloned(),
204        ignore_subjects: Some(ctx.params.get("ignoreSubjects").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
205        include_all_user_records: ctx.params.get("includeAllUserRecords").and_then(|v| v.parse::<bool>().ok()),
206        include_muted: ctx.params.get("includeMuted").and_then(|v| v.parse::<bool>().ok()),
207        last_reviewed_by: ctx.params.get("lastReviewedBy").cloned(),
208        limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
209        min_account_suspend_count: ctx.params.get("minAccountSuspendCount").and_then(|v| v.parse::<i64>().ok()),
210        min_priority_score: ctx.params.get("minPriorityScore").and_then(|v| v.parse::<i64>().ok()),
211        min_reported_records_count: ctx.params.get("minReportedRecordsCount").and_then(|v| v.parse::<i64>().ok()),
212        min_strike_count: ctx.params.get("minStrikeCount").and_then(|v| v.parse::<i64>().ok()),
213        min_takendown_records_count: ctx.params.get("minTakendownRecordsCount").and_then(|v| v.parse::<i64>().ok()),
214        only_muted: ctx.params.get("onlyMuted").and_then(|v| v.parse::<bool>().ok()),
215        queue_count: ctx.params.get("queueCount").and_then(|v| v.parse::<i64>().ok()),
216        queue_index: ctx.params.get("queueIndex").and_then(|v| v.parse::<i64>().ok()),
217        queue_seed: ctx.params.get("queueSeed").cloned(),
218        reported_after: ctx.params.get("reportedAfter").cloned(),
219        reported_before: ctx.params.get("reportedBefore").cloned(),
220        review_state: ctx.params.get("reviewState").cloned(),
221        reviewed_after: ctx.params.get("reviewedAfter").cloned(),
222        reviewed_before: ctx.params.get("reviewedBefore").cloned(),
223        sort_direction: ctx.params.get("sortDirection").cloned(),
224        sort_field: ctx.params.get("sortField").cloned(),
225        subject: ctx.params.get("subject").cloned(),
226        subject_type: ctx.params.get("subjectType").cloned(),
227        tags: Some(ctx.params.get("tags").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
228        takendown: ctx.params.get("takendown").and_then(|v| v.parse::<bool>().ok()),
229    })
230}
231