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.

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