闭社主体 forked from https://github.com/tootsuite/mastodon
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.

43 lines
1.8 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. 'alsoKnownAs' => { '@id' => 'as:alsoKnownAs', '@type' => '@id' },
  12. 'Hashtag' => 'as:Hashtag',
  13. 'ostatus' => 'http://ostatus.org#',
  14. 'atomUri' => 'ostatus:atomUri',
  15. 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
  16. 'conversation' => 'ostatus:conversation',
  17. 'toot' => 'http://joinmastodon.org/ns#',
  18. 'Emoji' => 'toot:Emoji',
  19. 'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' },
  20. 'featured' => { '@id' => 'toot:featured', '@type' => '@id' },
  21. 'schema' => 'http://schema.org#',
  22. 'PropertyValue' => 'schema:PropertyValue',
  23. 'value' => 'schema:value',
  24. },
  25. ],
  26. }.freeze
  27. def self.default_key_transform
  28. :camel_lower
  29. end
  30. def self.transform_key_casing!(value, _options)
  31. ActivityPub::CaseTransform.camel_lower(value)
  32. end
  33. def serializable_hash(options = nil)
  34. options = serialization_options(options)
  35. serialized_hash = ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options)
  36. CONTEXT.merge(self.class.transform_key_casing!(serialized_hash, instance_options))
  37. end
  38. end