From ed5e175a806f45469a6e5504ba0d3f5246997fad Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Wed, 30 Jul 2025 23:08:40 -0400 Subject: Test receiving push events when backgrounded And thus also displaying notifications. --- src/push/handlers/echo.rs | 18 ++++++++++++++---- src/push/handlers/mod.rs | 1 + src/push/handlers/unregister.rs | 15 +++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/push/handlers') diff --git a/src/push/handlers/echo.rs b/src/push/handlers/echo.rs index 4b4de57..a6c7be2 100644 --- a/src/push/handlers/echo.rs +++ b/src/push/handlers/echo.rs @@ -1,10 +1,10 @@ use axum::extract::{Json, State}; -use crate::{app::App, push::Id, token::extract::Identity}; +use crate::{app::App, token::extract::Identity}; #[derive(serde::Deserialize)] pub struct Request { - subscription: Id, + endpoint: String, msg: String, } @@ -13,8 +13,18 @@ pub async fn handler( identity: Identity, Json(request): Json, ) -> Result<(), crate::error::Internal> { - let Request { subscription, msg } = request; - app.push().echo(&identity.user, &subscription, &msg).await?; + let Request { endpoint, msg } = request; + app.push().echo(&identity.user, &endpoint, &msg).await?; + + Ok(()) +} + +pub async fn broadcast( + State(app): State, + Json(request): Json, +) -> Result<(), crate::error::Internal> { + let Request { endpoint: _, msg } = request; + app.push().broadcast(&msg).await?; Ok(()) } diff --git a/src/push/handlers/mod.rs b/src/push/handlers/mod.rs index 90edaa7..4b27ff5 100644 --- a/src/push/handlers/mod.rs +++ b/src/push/handlers/mod.rs @@ -7,6 +7,7 @@ mod register; mod unregister; pub use echo::handler as echo; +pub use echo::broadcast as broadcast; pub use register::handler as register; pub use unregister::handler as unregister; diff --git a/src/push/handlers/unregister.rs b/src/push/handlers/unregister.rs index a00ee92..b35dbd5 100644 --- a/src/push/handlers/unregister.rs +++ b/src/push/handlers/unregister.rs @@ -1,16 +1,23 @@ use axum::{ - extract::{Path, State}, + extract::{Json, State}, http::StatusCode, }; -use crate::{app::App, error::Internal, push::Id, token::extract::Identity}; +use crate::{app::App, error::Internal, token::extract::Identity}; + + +#[derive(serde::Deserialize)] +pub struct Request { + endpoint: String, +} pub async fn handler( State(app): State, identity: Identity, - Path(subscription): Path, + Json(request): Json, ) -> Result { - app.push().unregister(&identity.user, &subscription).await?; + let Request { endpoint } = request; + app.push().unregister(&identity.user, &endpoint).await?; Ok(StatusCode::NO_CONTENT) } -- cgit v1.2.3