summaryrefslogtreecommitdiff
path: root/src/push/repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/push/repo.rs')
-rw-r--r--src/push/repo.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/push/repo.rs b/src/push/repo.rs
index 6c18c6e..4183489 100644
--- a/src/push/repo.rs
+++ b/src/push/repo.rs
@@ -37,6 +37,24 @@ impl Push<'_> {
Ok(())
}
+ pub async fn by_login(&mut self, login: &Login) -> Result<Vec<SubscriptionInfo>, sqlx::Error> {
+ sqlx::query!(
+ r#"
+ select
+ subscription.endpoint,
+ subscription.p256dh,
+ subscription.auth
+ from push_subscription as subscription
+ join token on subscription.token = token.id
+ where token.login = $1
+ "#,
+ login.id,
+ )
+ .map(|row| SubscriptionInfo::new(row.endpoint, row.p256dh, row.auth))
+ .fetch_all(&mut *self.0)
+ .await
+ }
+
pub async fn by_endpoint(
&mut self,
subscriber: &Login,
@@ -65,6 +83,23 @@ impl Push<'_> {
Ok(info)
}
+ pub async fn unsubscribe(
+ &mut self,
+ subscription: &SubscriptionInfo,
+ ) -> Result<(), sqlx::Error> {
+ sqlx::query!(
+ r#"
+ delete from push_subscription
+ where endpoint = $1
+ "#,
+ subscription.endpoint,
+ )
+ .execute(&mut *self.0)
+ .await?;
+
+ Ok(())
+ }
+
pub async fn unsubscribe_token(&mut self, token: &Token) -> Result<(), sqlx::Error> {
sqlx::query!(
r#"