The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

192 строки
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. else
  38. 'Person'
  39. end
  40. end
  41. def following
  42. account_following_index_url(object)
  43. end
  44. def followers
  45. account_followers_url(object)
  46. end
  47. def inbox
  48. object.instance_actor? ? instance_actor_inbox_url : account_inbox_url(object)
  49. end
  50. def outbox
  51. account_outbox_url(object)
  52. end
  53. def featured
  54. account_collection_url(object, :featured)
  55. end
  56. def endpoints
  57. object
  58. end
  59. def preferred_username
  60. object.username
  61. end
  62. def name
  63. object.display_name
  64. end
  65. def summary
  66. Formatter.instance.simplified_format(object)
  67. end
  68. def icon
  69. object.avatar
  70. end
  71. def image
  72. object.header
  73. end
  74. def public_key
  75. object
  76. end
  77. def url
  78. object.instance_actor? ? about_more_url(instance_actor: true) : short_account_url(object)
  79. end
  80. def avatar_exists?
  81. object.avatar?
  82. end
  83. def header_exists?
  84. object.header?
  85. end
  86. def manually_approves_followers
  87. object.locked
  88. end
  89. def virtual_tags
  90. object.emojis + object.tags
  91. end
  92. def virtual_attachments
  93. object.fields + object.identity_proofs.active
  94. end
  95. def moved_to
  96. ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
  97. end
  98. def also_known_as?
  99. !object.also_known_as.empty?
  100. end
  101. class CustomEmojiSerializer < ActivityPub::EmojiSerializer
  102. end
  103. class TagSerializer < ActivityPub::Serializer
  104. context_extensions :hashtag
  105. include RoutingHelper
  106. attributes :type, :href, :name
  107. def type
  108. 'Hashtag'
  109. end
  110. def href
  111. explore_hashtag_url(object)
  112. end
  113. def name
  114. "##{object.name}"
  115. end
  116. end
  117. class Account::FieldSerializer < ActivityPub::Serializer
  118. attributes :type, :name, :value
  119. def type
  120. 'PropertyValue'
  121. end
  122. def value
  123. Formatter.instance.format_field(object.account, object.value)
  124. end
  125. end
  126. class AccountIdentityProofSerializer < ActivityPub::Serializer
  127. attributes :type, :name, :signature_algorithm, :signature_value
  128. def type
  129. 'IdentityProof'
  130. end
  131. def name
  132. object.provider_username
  133. end
  134. def signature_algorithm
  135. object.provider
  136. end
  137. def signature_value
  138. object.token
  139. end
  140. end
  141. end