Skip to main content

proto_blue_api/generated/app/bsky/notification/
putActivitySubscription.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: app.bsky.notification.putActivitySubscription
3
4use serde::{Deserialize, Serialize};
5
6/// Puts an activity subscription entry. The key should be omitted for creation and provided for updates. Requires auth.
7/// XRPC Procedure: app.bsky.notification.putActivitySubscription
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    pub activity_subscription: crate::app::bsky::notification::defs::ActivitySubscription,
12    pub subject: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Output {
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub activity_subscription: Option<crate::app::bsky::notification::defs::ActivitySubscription>,
20    pub subject: String,
21}
22
23/// Errors a `call()` on this method can return.
24#[derive(Debug, thiserror::Error)]
25pub enum CallError {
26    #[error("{0}")]
27    Xrpc(proto_blue_xrpc::XrpcError),
28    #[error(transparent)]
29    Transport(#[from] proto_blue_xrpc::Error),
30    #[error(transparent)]
31    Json(#[from] serde_json::Error),
32}
33
34fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
35    CallError::Xrpc(err)
36}
37
38/// Execute the procedure.
39pub async fn call(
40    client: &proto_blue_xrpc::XrpcClient,
41    input: &Input,
42    opts: Option<&proto_blue_xrpc::CallOptions>,
43) -> Result<Output, CallError> {
44    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
45    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
46    let response = match client.procedure("app.bsky.notification.putActivitySubscription", qp_ref, Some(body), opts).await {
47        Ok(r) => r,
48        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
49        Err(e) => return Err(CallError::Transport(e)),
50    };
51    Ok(serde_json::from_value(response.data)?)
52}
53
54/// Register a typed handler for this procedure on an [`XrpcServer`].
55#[cfg(feature = "server")]
56pub fn register<F, Fut>(
57server: proto_blue_xrpc::XrpcServer,
58handler: F,
59) -> proto_blue_xrpc::XrpcServer
60where
61    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
62    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
63{
64    let handler = std::sync::Arc::new(handler);
65    server.procedure("app.bsky.notification.putActivitySubscription", move |ctx| {
66        let handler = handler.clone();
67        async move {
68            let input = match ctx.json_body()? {
69                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}")))?),
70                None => None,
71            };
72            let out = handler(ctx, input).await?;
73            let value = serde_json::to_value(&out)
74                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
75            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
76        }
77    })
78}
79