Add REST API for Web Push Notifications subscriptions (#7445)
- POST /api/v1/push/subscription - PUT /api/v1/push/subscription - DELETE /api/v1/push/subscription - New OAuth scope: "push" (required for the above methods)
This commit is contained in:
parent
9a794067f7
commit
b4fb766b23
20 changed files with 258 additions and 81 deletions
18
app/workers/web/push_notification_worker.rb
Normal file
18
app/workers/web/push_notification_worker.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Web::PushNotificationWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options backtrace: true
|
||||
|
||||
def perform(subscription_id, notification_id)
|
||||
subscription = ::Web::PushSubscription.find(subscription_id)
|
||||
notification = Notification.find(notification_id)
|
||||
|
||||
subscription.push(notification) unless notification.activity.nil?
|
||||
rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
|
||||
subscription.destroy!
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class WebPushNotificationWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options backtrace: true
|
||||
|
||||
def perform(session_activation_id, notification_id)
|
||||
session_activation = SessionActivation.find(session_activation_id)
|
||||
notification = Notification.find(notification_id)
|
||||
|
||||
return if session_activation.web_push_subscription.nil? || notification.activity.nil?
|
||||
|
||||
session_activation.web_push_subscription.push(notification)
|
||||
rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
|
||||
# Subscription expiration is not currently implemented in any browser
|
||||
|
||||
session_activation.web_push_subscription.destroy!
|
||||
session_activation.update!(web_push_subscription: nil)
|
||||
|
||||
true
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue