Skip to main content

proto_blue_api/generated/app/bsky/feed/
sendInteractions.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: app.bsky.feed.sendInteractions
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7/// Send information about interactions with feed items back to the feed generator that served them.
8/// XRPC Procedure: app.bsky.feed.sendInteractions
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Input {
12    pub interactions: Vec<crate::app::bsky::feed::defs::Interaction>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Output {}
18
19/// Errors a `call()` on this method can return.
20#[derive(Debug, thiserror::Error)]
21pub enum CallError {
22    #[error("{0}")]
23    Xrpc(proto_blue_xrpc::XrpcError),
24    #[error(transparent)]
25    Transport(#[from] proto_blue_xrpc::Error),
26    #[error(transparent)]
27    Json(#[from] serde_json::Error),
28}
29
30fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
31    CallError::Xrpc(err)
32}
33
34/// Execute the procedure.
35pub async fn call(
36    client: &proto_blue_xrpc::XrpcClient,
37    input: &Input,
38    opts: Option<&proto_blue_xrpc::CallOptions>,
39) -> Result<Output, CallError> {
40    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
41    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
42    let response = match client
43        .procedure("app.bsky.feed.sendInteractions", qp_ref, Some(body), opts)
44        .await
45    {
46        Ok(r) => r,
47        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
48        Err(e) => return Err(CallError::Transport(e)),
49    };
50    Ok(serde_json::from_value(response.data)?)
51}
52
53/// Register a typed handler for this procedure on an [`proto_blue_xrpc::XrpcServer`].
54#[cfg(feature = "server")]
55pub fn register<F, Fut>(
56    server: proto_blue_xrpc::XrpcServer,
57    handler: F,
58) -> proto_blue_xrpc::XrpcServer
59where
60    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
61    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
62        + Send
63        + 'static,
64{
65    let handler = std::sync::Arc::new(handler);
66    server.procedure("app.bsky.feed.sendInteractions", move |ctx| {
67        let handler = handler.clone();
68        async move {
69            let input = match ctx.json_body()? {
70                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
71                    proto_blue_xrpc::XrpcServerError::new(
72                        proto_blue_xrpc::ResponseType::InvalidRequest,
73                        format!("input deserialize: {e}"),
74                    )
75                })?),
76                None => None,
77            };
78            let out = handler(ctx, input).await?;
79            let value = serde_json::to_value(&out).map_err(|e| {
80                proto_blue_xrpc::XrpcServerError::new(
81                    proto_blue_xrpc::ResponseType::InternalServerError,
82                    format!("output serialize: {e}"),
83                )
84            })?;
85            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
86        }
87    })
88}