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.

40 lines
822 B

  1. # frozen_string_literal: true
  2. class ActivityPub::ActivitySerializer < ActiveModel::Serializer
  3. attributes :id, :type, :actor, :published, :to, :cc
  4. has_one :proper, key: :object, serializer: ActivityPub::NoteSerializer, unless: :announce?
  5. attribute :proper_uri, key: :object, if: :announce?
  6. def id
  7. ActivityPub::TagManager.instance.activity_uri_for(object)
  8. end
  9. def type
  10. announce? ? 'Announce' : 'Create'
  11. end
  12. def actor
  13. ActivityPub::TagManager.instance.uri_for(object.account)
  14. end
  15. def published
  16. object.created_at.iso8601
  17. end
  18. def to
  19. ActivityPub::TagManager.instance.to(object)
  20. end
  21. def cc
  22. ActivityPub::TagManager.instance.cc(object)
  23. end
  24. def proper_uri
  25. ActivityPub::TagManager.instance.uri_for(object.proper)
  26. end
  27. def announce?
  28. object.reblog?
  29. end
  30. end