Skip to main content

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

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: tools.ozone.moderation.getAccountTimeline
3
4use serde::{Deserialize, Serialize};
5
6/// Get timeline of all available events of an account. This includes moderation events, account history and did history.
7/// XRPC Query: tools.ozone.moderation.getAccountTimeline
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11    pub did: String,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17    pub timeline: Vec<TimelineItem>,
18}
19
20/// Errors a `call()` on this method can return.
21#[derive(Debug, thiserror::Error)]
22pub enum CallError {
23    #[error("RepoNotFound")]
24    RepoNotFound,
25    #[error("{0}")]
26    Xrpc(proto_blue_xrpc::XrpcError),
27    #[error(transparent)]
28    Transport(#[from] proto_blue_xrpc::Error),
29    #[error(transparent)]
30    Json(#[from] serde_json::Error),
31}
32
33fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
34    match err.error.as_deref() {
35        Some("RepoNotFound") => CallError::RepoNotFound,
36        _ => CallError::Xrpc(err),
37    }
38}
39
40fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
41    let mut qp = proto_blue_xrpc::QueryParams::new();
42    { let v = &p.did; qp.insert("did".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
43    qp
44}
45
46/// Execute the query.
47pub async fn call(
48    client: &proto_blue_xrpc::XrpcClient,
49    params: Option<&Params>,
50    opts: Option<&proto_blue_xrpc::CallOptions>,
51) -> Result<Output, CallError> {
52    let qp = params.map(to_query_params);
53    let response = match client.query("tools.ozone.moderation.getAccountTimeline", qp.as_ref(), opts).await {
54        Ok(r) => r,
55        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
56        Err(e) => return Err(CallError::Transport(e)),
57    };
58    Ok(serde_json::from_value(response.data)?)
59}
60
61/// Register a typed handler for this method on an [`XrpcServer`].
62#[cfg(feature = "server")]
63pub fn register<F, Fut>(
64server: proto_blue_xrpc::XrpcServer,
65handler: F,
66) -> proto_blue_xrpc::XrpcServer
67where
68    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
69    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
70{
71    let handler = std::sync::Arc::new(handler);
72    server.query("tools.ozone.moderation.getAccountTimeline", move |ctx| {
73        let handler = handler.clone();
74        async move {
75            let params = params_from_ctx(&ctx);
76            let out = handler(ctx, params).await?;
77            let value = serde_json::to_value(&out)
78                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
79            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
80        }
81    })
82}
83
84#[cfg(feature = "server")]
85fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
86    // Always construct a `Params` — required fields are
87    // validated upstream by the lexicon validator when enabled;
88    // missing values surface as runtime errors from the handler.
89    Some(Params {
90        did: (ctx.params.get("did").cloned())?,
91    })
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(rename_all = "camelCase")]
96pub struct TimelineItem {
97    pub day: String,
98    pub summary: Vec<TimelineItemSummary>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct TimelineItemSummary {
104    pub count: i64,
105    pub event_subject_type: String,
106    pub event_type: String,
107}
108