Skip to main content

proto_blue_api/generated/com/atproto/admin/
enableAccountInvites.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.admin.enableAccountInvites
3
4use serde::{Deserialize, Serialize};
5
6/// Re-enable an account's ability to receive invite codes.
7/// XRPC Procedure: com.atproto.admin.enableAccountInvites
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    pub account: String,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub note: Option<String>,
14}
15
16/// Errors a `call()` on this method can return.
17#[derive(Debug, thiserror::Error)]
18pub enum CallError {
19    #[error("{0}")]
20    Xrpc(proto_blue_xrpc::XrpcError),
21    #[error(transparent)]
22    Transport(#[from] proto_blue_xrpc::Error),
23    #[error(transparent)]
24    Json(#[from] serde_json::Error),
25}
26
27fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
28    CallError::Xrpc(err)
29}
30
31/// Execute the procedure.
32pub async fn call(
33    client: &proto_blue_xrpc::XrpcClient,
34    input: &Input,
35    opts: Option<&proto_blue_xrpc::CallOptions>,
36) -> Result<serde_json::Value, CallError> {
37    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
38    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
39    let response = match client.procedure("com.atproto.admin.enableAccountInvites", qp_ref, Some(body), opts).await {
40        Ok(r) => r,
41        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
42        Err(e) => return Err(CallError::Transport(e)),
43    };
44    Ok(response.data)
45}
46
47/// Register a typed handler for this procedure on an [`XrpcServer`].
48#[cfg(feature = "server")]
49pub fn register<F, Fut>(
50server: proto_blue_xrpc::XrpcServer,
51handler: F,
52) -> proto_blue_xrpc::XrpcServer
53where
54    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
55    Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
56{
57    let handler = std::sync::Arc::new(handler);
58    server.procedure("com.atproto.admin.enableAccountInvites", move |ctx| {
59        let handler = handler.clone();
60        async move {
61            let input = match ctx.json_body()? {
62                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
63                None => None,
64            };
65            let out = handler(ctx, input).await?;
66            Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
67        }
68    })
69}
70