proto_blue_api/generated/app/bsky/notification/
listNotifications.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 cursor: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub limit: Option<i64>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub priority: Option<bool>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub reasons: Option<Vec<String>>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub seen_at: Option<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct Output {
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub cursor: Option<String>,
28 pub notifications: Vec<Notification>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub priority: Option<bool>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub seen_at: Option<String>,
33}
34
35#[derive(Debug, thiserror::Error)]
37pub enum CallError {
38 #[error("{0}")]
39 Xrpc(proto_blue_xrpc::XrpcError),
40 #[error(transparent)]
41 Transport(#[from] proto_blue_xrpc::Error),
42 #[error(transparent)]
43 Json(#[from] serde_json::Error),
44}
45
46fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
47 CallError::Xrpc(err)
48}
49
50fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
51 let mut qp = proto_blue_xrpc::QueryParams::new();
52 if let Some(v) = &p.cursor { qp.insert("cursor".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
53 if let Some(v) = &p.limit { qp.insert("limit".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
54 if let Some(v) = &p.priority { qp.insert("priority".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
55 if let Some(v) = &p.reasons { qp.insert("reasons".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
56 if let Some(v) = &p.seen_at { qp.insert("seenAt".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
57 qp
58}
59
60pub async fn call(
62 client: &proto_blue_xrpc::XrpcClient,
63 params: Option<&Params>,
64 opts: Option<&proto_blue_xrpc::CallOptions>,
65) -> Result<Output, CallError> {
66 let qp = params.map(to_query_params);
67 let response = match client.query("app.bsky.notification.listNotifications", qp.as_ref(), opts).await {
68 Ok(r) => r,
69 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
70 Err(e) => return Err(CallError::Transport(e)),
71 };
72 Ok(serde_json::from_value(response.data)?)
73}
74
75#[cfg(feature = "server")]
77pub fn register<F, Fut>(
78server: proto_blue_xrpc::XrpcServer,
79handler: F,
80) -> proto_blue_xrpc::XrpcServer
81where
82 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
83 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
84{
85 let handler = std::sync::Arc::new(handler);
86 server.query("app.bsky.notification.listNotifications", move |ctx| {
87 let handler = handler.clone();
88 async move {
89 let params = params_from_ctx(&ctx);
90 let out = handler(ctx, params).await?;
91 let value = serde_json::to_value(&out)
92 .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
93 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
94 }
95 })
96}
97
98#[cfg(feature = "server")]
99fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
100 Some(Params {
104 cursor: ctx.params.get("cursor").cloned(),
105 limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
106 priority: ctx.params.get("priority").and_then(|v| v.parse::<bool>().ok()),
107 reasons: Some(ctx.params.get("reasons").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
108 seen_at: ctx.params.get("seenAt").cloned(),
109 })
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct Notification {
115 pub author: crate::app::bsky::actor::defs::ProfileView,
116 pub cid: String,
117 pub indexed_at: String,
118 pub is_read: bool,
119 #[serde(skip_serializing_if = "Option::is_none")]
120 pub labels: Option<Vec<crate::com::atproto::label::defs::Label>>,
121 pub reason: String,
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub reason_subject: Option<String>,
124 pub record: serde_json::Value,
125 pub uri: String,
126}
127