about summary refs log tree commit diff
path: root/app/models/web
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/web')
-rw-r--r--app/models/web/push_subscription.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb
index 7da3428fe..867bc9519 100644
--- a/app/models/web/push_subscription.rb
+++ b/app/models/web/push_subscription.rb
@@ -50,6 +50,15 @@ class Web::PushSubscription < ApplicationRecord
                                end
   end
 
+  class << self
+    def unsubscribe_for(application_id, resource_owner)
+      access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil)
+                                                .pluck(:id)
+
+      where(access_token_id: access_token_ids).delete_all
+    end
+  end
+
   private
 
   def push_payload(message, ttl = 5.minutes.seconds)