Skip to main content

proto_blue_api/generated/chat/bsky/convo/
getLog.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: chat.bsky.convo.getLog
3
4use serde::{Deserialize, Serialize};
5
6/// XRPC Query: chat.bsky.convo.getLog
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Params {
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub cursor: Option<String>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub cursor: Option<String>,
19    pub logs: Vec<serde_json::Value>,
20}
21
22/// Errors a `call()` on this method can return.
23#[derive(Debug, thiserror::Error)]
24pub enum CallError {
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    CallError::Xrpc(err)
35}
36
37fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
38    let mut qp = proto_blue_xrpc::QueryParams::new();
39    if let Some(v) = &p.cursor { qp.insert("cursor".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
40    qp
41}
42
43/// Execute the query.
44pub async fn call(
45    client: &proto_blue_xrpc::XrpcClient,
46    params: Option<&Params>,
47    opts: Option<&proto_blue_xrpc::CallOptions>,
48) -> Result<Output, CallError> {
49    let qp = params.map(to_query_params);
50    let response = match client.query("chat.bsky.convo.getLog", qp.as_ref(), opts).await {
51        Ok(r) => r,
52        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
53        Err(e) => return Err(CallError::Transport(e)),
54    };
55    Ok(serde_json::from_value(response.data)?)
56}
57
58/// Register a typed handler for this method on an [`XrpcServer`].
59#[cfg(feature = "server")]
60pub fn register<F, Fut>(
61server: proto_blue_xrpc::XrpcServer,
62handler: F,
63) -> proto_blue_xrpc::XrpcServer
64where
65    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
66    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
67{
68    let handler = std::sync::Arc::new(handler);
69    server.query("chat.bsky.convo.getLog", move |ctx| {
70        let handler = handler.clone();
71        async move {
72            let params = params_from_ctx(&ctx);
73            let out = handler(ctx, params).await?;
74            let value = serde_json::to_value(&out)
75                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
76            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
77        }
78    })
79}
80
81#[cfg(feature = "server")]
82fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
83    // Always construct a `Params` — required fields are
84    // validated upstream by the lexicon validator when enabled;
85    // missing values surface as runtime errors from the handler.
86    Some(Params {
87        cursor: ctx.params.get("cursor").cloned(),
88    })
89}
90