You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
  3. CONTEXT = {
  4. '@context': [
  5. 'https://www.w3.org/ns/activitystreams',
  6. 'https://w3id.org/security/v1',
  7. {
  8. 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
  9. 'sensitive' => 'as:sensitive',
  10. 'movedTo' => { '@id' => 'as:movedTo', '@type' => '@id' },
  11. 'Hashtag' => 'as:Hashtag',
  12. 'ostatus' => 'http://ostatus.org#',
  13. 'atomUri' => 'ostatus:atomUri',
  14. 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
  15. 'conversation' => 'ostatus:conversation',
  16. 'toot' => 'http://joinmastodon.org/ns#',
  17. 'Emoji' => 'toot:Emoji',
  18. 'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' },
  19. 'featured' => { '@id' => 'toot:featured', '@type' => '@id' },
  20. 'schema' => 'http://schema.org#',
  21. 'PropertyValue' => 'schema:PropertyValue',
  22. 'value' => 'schema:value',
  23. },
  24. ],
  25. }.freeze
  26. def self.default_key_transform
  27. :camel_lower
  28. end
  29. def self.transform_key_casing!(value, _options)
  30. ActivityPub::CaseTransform.camel_lower(value)
  31. end
  32. def serializable_hash(options = nil)
  33. options = serialization_options(options)
  34. serialized_hash = ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options)
  35. CONTEXT.merge(self.class.transform_key_casing!(serialized_hash, instance_options))
  36. end
  37. end