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

52 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::ActivitySerializer < ActivityPub::Serializer
  3. attributes :id, :type, :actor, :published, :to, :cc
  4. has_one :proper, key: :object, serializer: ActivityPub::NoteSerializer, if: :serialize_object?
  5. attribute :proper_uri, key: :object, unless: :serialize_object?
  6. attribute :atom_uri, if: :announce?
  7. def id
  8. ActivityPub::TagManager.instance.activity_uri_for(object)
  9. end
  10. def type
  11. announce? ? 'Announce' : 'Create'
  12. end
  13. def actor
  14. ActivityPub::TagManager.instance.uri_for(object.account)
  15. end
  16. def published
  17. object.created_at.iso8601
  18. end
  19. def to
  20. ActivityPub::TagManager.instance.to(object)
  21. end
  22. def cc
  23. ActivityPub::TagManager.instance.cc(object)
  24. end
  25. def proper_uri
  26. ActivityPub::TagManager.instance.uri_for(object.proper)
  27. end
  28. def atom_uri
  29. OStatus::TagManager.instance.uri_for(object)
  30. end
  31. def announce?
  32. object.reblog?
  33. end
  34. def serialize_object?
  35. return true unless announce?
  36. # Serialize private self-boosts of local toots
  37. object.account == object.proper.account && object.proper.private_visibility? && object.local?
  38. end
  39. end