mastodon/app/serializers/rest/web_push_subscription_v1_serializer.rb
Nik Clayton 320ebcebc7 feat: Implement /api/v2/push/subscription
`/api/v1/push/subscription` incorrectly returns the ID as an int instead
of a string.

That can't be fixed in the existing API without a breaking change, so
fix it in V2.

Mark the V1 API as deprecated with an arbitrary date of 2026-12-31.
2025-10-28 11:15:09 +00:00

20 lines
460 B
Ruby

# frozen_string_literal: true
class REST::WebPushSubscriptionV1Serializer < ActiveModel::Serializer
attributes :id, :endpoint, :standard, :alerts, :server_key, :policy
delegate :standard, to: :object
def alerts
(object.data&.dig('alerts') || {}).transform_values { |v| ActiveModel::Type::Boolean.new.cast(v) }
end
def server_key
Rails.configuration.x.vapid.public_key
end
def policy
object.data&.dig('policy') || 'all'
end
end