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.

156 lines
2.6 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::ActorSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :type, :following, :followers,
  5. :inbox, :outbox, :featured,
  6. :preferred_username, :name, :summary,
  7. :url, :manually_approves_followers
  8. has_one :public_key, serializer: ActivityPub::PublicKeySerializer
  9. has_many :virtual_tags, key: :tag
  10. has_many :virtual_attachments, key: :attachment
  11. attribute :moved_to, if: :moved?
  12. attribute :also_known_as, if: :also_known_as?
  13. class EndpointsSerializer < ActiveModel::Serializer
  14. include RoutingHelper
  15. attributes :shared_inbox
  16. def shared_inbox
  17. inbox_url
  18. end
  19. end
  20. has_one :endpoints, serializer: EndpointsSerializer
  21. has_one :icon, serializer: ActivityPub::ImageSerializer, if: :avatar_exists?
  22. has_one :image, serializer: ActivityPub::ImageSerializer, if: :header_exists?
  23. delegate :moved?, to: :object
  24. def id
  25. account_url(object)
  26. end
  27. def type
  28. object.bot? ? 'Service' : 'Person'
  29. end
  30. def following
  31. account_following_index_url(object)
  32. end
  33. def followers
  34. account_followers_url(object)
  35. end
  36. def inbox
  37. account_inbox_url(object)
  38. end
  39. def outbox
  40. account_outbox_url(object)
  41. end
  42. def featured
  43. account_collection_url(object, :featured)
  44. end
  45. def endpoints
  46. object
  47. end
  48. def preferred_username
  49. object.username
  50. end
  51. def name
  52. object.display_name
  53. end
  54. def summary
  55. Formatter.instance.simplified_format(object)
  56. end
  57. def icon
  58. object.avatar
  59. end
  60. def image
  61. object.header
  62. end
  63. def public_key
  64. object
  65. end
  66. def url
  67. short_account_url(object)
  68. end
  69. def avatar_exists?
  70. object.avatar?
  71. end
  72. def header_exists?
  73. object.header?
  74. end
  75. def manually_approves_followers
  76. object.locked
  77. end
  78. def virtual_tags
  79. object.emojis + object.tags
  80. end
  81. def virtual_attachments
  82. object.fields
  83. end
  84. def moved_to
  85. ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
  86. end
  87. def also_known_as?
  88. !object.also_known_as.empty?
  89. end
  90. class CustomEmojiSerializer < ActivityPub::EmojiSerializer
  91. end
  92. class TagSerializer < ActiveModel::Serializer
  93. include RoutingHelper
  94. attributes :type, :href, :name
  95. def type
  96. 'Hashtag'
  97. end
  98. def href
  99. explore_hashtag_url(object)
  100. end
  101. def name
  102. "##{object.name}"
  103. end
  104. end
  105. class Account::FieldSerializer < ActiveModel::Serializer
  106. attributes :type, :name, :value
  107. def type
  108. 'PropertyValue'
  109. end
  110. def value
  111. Formatter.instance.format_field(object.account, object.value)
  112. end
  113. end
  114. end