summaryrefslogtreecommitdiff
path: root/src/push/repo.rs
diff options
context:
space:
mode:
authorKit La Touche <kit@transneptune.net>2025-07-30 23:08:40 -0400
committerKit La Touche <kit@transneptune.net>2025-07-30 23:08:40 -0400
commited5e175a806f45469a6e5504ba0d3f5246997fad (patch)
tree0d4233c57596186b86d165640ca4721e7495567d /src/push/repo.rs
parentb63380b251d04dd92f06aa5bbc22a72ca3e4bf8e (diff)
Test receiving push events when backgrounded
And thus also displaying notifications.
Diffstat (limited to 'src/push/repo.rs')
-rw-r--r--src/push/repo.rs33
1 files changed, 28 insertions, 5 deletions
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<Subscription, sqlx::Error> {
+ pub async fn all(&mut self) -> Result<Vec<Subscription>, 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<Subscription, sqlx::Error> {
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?;