logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

web_push_notification_worker.rb (789B)


  1. # frozen_string_literal: true
  2. class WebPushNotificationWorker
  3. include Sidekiq::Worker
  4. sidekiq_options backtrace: true
  5. def perform(session_activation_id, notification_id)
  6. session_activation = SessionActivation.find(session_activation_id)
  7. notification = Notification.find(notification_id)
  8. return if session_activation.web_push_subscription.nil? || notification.activity.nil?
  9. session_activation.web_push_subscription.push(notification)
  10. rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
  11. # Subscription expiration is not currently implemented in any browser
  12. session_activation.web_push_subscription.destroy!
  13. session_activation.update!(web_push_subscription: nil)
  14. true
  15. rescue ActiveRecord::RecordNotFound
  16. true
  17. end
  18. end