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/repo.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/push/repo.rs') diff --git a/src/push/repo.rs b/src/push/repo.rs index ddef706..56bbc3d 100644 --- a/src/push/repo.rs +++ b/src/push/repo.rs @@ -41,7 +41,30 @@ impl Subscriptions<'_> { Ok(id) } - pub async fn by_id(&mut self, id: &Id) -> Result { + pub async fn all(&mut self) -> Result, sqlx::Error> { + let subscriptions = sqlx::query!( + r#" + select + id as "id: Id", + user as "user: user::Id", + endpoint, + key_p256dh, + key_auth + from subscription + "# + ) + .map(|row| Subscription { + id: row.id, + user: row.user, + info: SubscriptionInfo::new(row.endpoint, row.key_p256dh, row.key_auth), + }) + .fetch_all(&mut *self.0) + .await?; + + Ok(subscriptions) + } + + pub async fn by_endpoint(&mut self, endpoint: &String) -> Result { let subscription = sqlx::query!( r#" select @@ -51,9 +74,9 @@ impl Subscriptions<'_> { key_p256dh, key_auth from subscription - where id = $1 + where endpoint = $1 "#, - id, + endpoint, ) .map(|row| Subscription { id: row.id, @@ -70,9 +93,9 @@ impl Subscriptions<'_> { sqlx::query!( r#" delete from subscription - where id = $1 + where endpoint = $1 "#, - subscription.id, + subscription.info.endpoint, ) .execute(&mut *self.0) .await?; -- cgit v1.2.3