闭社主体 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.

34 lines
1.1 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. 'Hashtag' => 'as:Hashtag',
  11. 'ostatus' => 'http://ostatus.org#',
  12. 'atomUri' => 'ostatus:atomUri',
  13. 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
  14. 'conversation' => 'ostatus:conversation',
  15. },
  16. ],
  17. }.freeze
  18. def self.default_key_transform
  19. :camel_lower
  20. end
  21. def self.transform_key_casing!(value, _options)
  22. ActivityPub::CaseTransform.camel_lower(value)
  23. end
  24. def serializable_hash(options = nil)
  25. options = serialization_options(options)
  26. serialized_hash = CONTEXT.merge(ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options))
  27. self.class.transform_key_casing!(serialized_hash, instance_options)
  28. end
  29. end