add_serializer.rb 795 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class ActivityPub::AddSerializer < ActivityPub::Serializer
  3. class UriSerializer < ActiveModel::Serializer
  4. include RoutingHelper
  5. def serializable_hash(*_args)
  6. ActivityPub::TagManager.instance.uri_for(object)
  7. end
  8. end
  9. def self.serializer_for(model, options)
  10. case model.class.name
  11. when 'Status'
  12. UriSerializer
  13. when 'FeaturedTag'
  14. ActivityPub::HashtagSerializer
  15. else
  16. super
  17. end
  18. end
  19. include RoutingHelper
  20. attributes :type, :actor, :target
  21. has_one :proper_object, key: :object
  22. def type
  23. 'Add'
  24. end
  25. def actor
  26. ActivityPub::TagManager.instance.uri_for(object.account)
  27. end
  28. def proper_object
  29. object
  30. end
  31. def target
  32. account_collection_url(object.account, :featured)
  33. end
  34. end