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.

181 lines
3.2 KiB

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