闭社主体 forked from https://github.com/tootsuite/mastodon
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.

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