proto_blue_api/generated/app/bsky/notification/
getUnreadCount.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub priority: Option<bool>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub seen_at: Option<String>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct Output {
20 pub count: i64,
21}
22
23#[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
38fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
39 let mut qp = proto_blue_xrpc::QueryParams::new();
40 if let Some(v) = &p.priority { qp.insert("priority".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
41 if let Some(v) = &p.seen_at { qp.insert("seenAt".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
42 qp
43}
44
45pub async fn call(
47 client: &proto_blue_xrpc::XrpcClient,
48 params: Option<&Params>,
49 opts: Option<&proto_blue_xrpc::CallOptions>,
50) -> Result<Output, CallError> {
51 let qp = params.map(to_query_params);
52 let response = match client.query("app.bsky.notification.getUnreadCount", qp.as_ref(), opts).await {
53 Ok(r) => r,
54 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
55 Err(e) => return Err(CallError::Transport(e)),
56 };
57 Ok(serde_json::from_value(response.data)?)
58}
59
60#[cfg(feature = "server")]
62pub fn register<F, Fut>(
63server: proto_blue_xrpc::XrpcServer,
64handler: F,
65) -> proto_blue_xrpc::XrpcServer
66where
67 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
68 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
69{
70 let handler = std::sync::Arc::new(handler);
71 server.query("app.bsky.notification.getUnreadCount", move |ctx| {
72 let handler = handler.clone();
73 async move {
74 let params = params_from_ctx(&ctx);
75 let out = handler(ctx, params).await?;
76 let value = serde_json::to_value(&out)
77 .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
78 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
79 }
80 })
81}
82
83#[cfg(feature = "server")]
84fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
85 Some(Params {
89 priority: ctx.params.get("priority").and_then(|v| v.parse::<bool>().ok()),
90 seen_at: ctx.params.get("seenAt").cloned(),
91 })
92}
93