actor_serializer.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # frozen_string_literal: true
  2. class ActivityPub::ActorSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :type, :following, :followers,
  5. :inbox, :outbox,
  6. :preferred_username, :name, :summary,
  7. :url, :manually_approves_followers
  8. has_one :public_key, serializer: ActivityPub::PublicKeySerializer
  9. attribute :moved_to, if: :moved?
  10. class EndpointsSerializer < ActiveModel::Serializer
  11. include RoutingHelper
  12. attributes :shared_inbox
  13. def shared_inbox
  14. inbox_url
  15. end
  16. end
  17. has_one :endpoints, serializer: EndpointsSerializer
  18. has_one :icon, serializer: ActivityPub::ImageSerializer, if: :avatar_exists?
  19. has_one :image, serializer: ActivityPub::ImageSerializer, if: :header_exists?
  20. delegate :moved?, to: :object
  21. def id
  22. account_url(object)
  23. end
  24. def type
  25. 'Person'
  26. end
  27. def following
  28. account_following_index_url(object)
  29. end
  30. def followers
  31. account_followers_url(object)
  32. end
  33. def inbox
  34. account_inbox_url(object)
  35. end
  36. def outbox
  37. account_outbox_url(object)
  38. end
  39. def endpoints
  40. object
  41. end
  42. def preferred_username
  43. object.username
  44. end
  45. def name
  46. object.display_name
  47. end
  48. def summary
  49. Formatter.instance.simplified_format(object)
  50. end
  51. def icon
  52. object.avatar
  53. end
  54. def image
  55. object.header
  56. end
  57. def public_key
  58. object
  59. end
  60. def url
  61. short_account_url(object)
  62. end
  63. def avatar_exists?
  64. object.avatar.exists?
  65. end
  66. def header_exists?
  67. object.header.exists?
  68. end
  69. def manually_approves_followers
  70. object.locked
  71. end
  72. def moved_to
  73. ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
  74. end
  75. end