web_push_subscription_serializer.rb 362 B

12345678910111213
  1. # frozen_string_literal: true
  2. class REST::WebPushSubscriptionSerializer < ActiveModel::Serializer
  3. attributes :id, :endpoint, :alerts, :server_key
  4. def alerts
  5. (object.data&.dig('alerts') || {}).each_with_object({}) { |(k, v), h| h[k] = ActiveModel::Type::Boolean.new.cast(v) }
  6. end
  7. def server_key
  8. Rails.configuration.x.vapid_public_key
  9. end
  10. end