autoendpoint/routes/
webpush.rs1use std::str::FromStr;
2
3use crate::error::{ApiErrorKind, ApiResult};
4use crate::extractors::message_id::MessageId;
5use crate::extractors::notification::Notification;
6use crate::extractors::routers::{RouterType, Routers};
7use crate::server::AppState;
8use actix_web::web::Data;
9use actix_web::HttpResponse;
10
11pub async fn webpush_route(
14 notification: Notification,
15 routers: Routers,
16 _app_state: Data<AppState>,
17) -> ApiResult<HttpResponse> {
18 sentry::configure_scope(|scope| {
19 scope.set_extra(
20 "uaid",
21 notification.subscription.user.uaid.to_string().into(),
22 );
23 });
24 let router = routers.get(
25 RouterType::from_str(¬ification.subscription.user.router_type)
26 .map_err(|_| ApiErrorKind::InvalidRouterType)?,
27 );
28 Ok(router.route_notification(notification).await?.into())
29}
30
31pub async fn delete_notification_route(
33 message_id: MessageId,
34 app_state: Data<AppState>,
35) -> ApiResult<HttpResponse> {
36 let sort_key = message_id.sort_key();
37 debug!("Deleting notification with sort-key {}", sort_key);
38 trace!("message_id = {:?}", message_id);
39 app_state
40 .db
41 .remove_message(&message_id.uaid(), &sort_key)
42 .await?;
43
44 Ok(HttpResponse::NoContent().finish())
45}