闭社主体 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.

109 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::ActorSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :type, :following, :followers,
  5. :inbox, :outbox,
  6. :preferred_username, :name, :summary,
  7. :url, :manually_approves_followers
  8. has_one :public_key, serializer: ActivityPub::PublicKeySerializer
  9. class ImageSerializer < ActiveModel::Serializer
  10. include RoutingHelper
  11. attributes :type, :url
  12. def type
  13. 'Image'
  14. end
  15. def url
  16. full_asset_url(object.url(:original))
  17. end
  18. end
  19. class EndpointsSerializer < ActiveModel::Serializer
  20. include RoutingHelper
  21. attributes :shared_inbox
  22. def shared_inbox
  23. inbox_url
  24. end
  25. end
  26. has_one :endpoints, serializer: EndpointsSerializer
  27. has_one :icon, serializer: ImageSerializer, if: :avatar_exists?
  28. has_one :image, serializer: ImageSerializer, if: :header_exists?
  29. def id
  30. account_url(object)
  31. end
  32. def type
  33. 'Person'
  34. end
  35. def following
  36. account_following_index_url(object)
  37. end
  38. def followers
  39. account_followers_url(object)
  40. end
  41. def inbox
  42. account_inbox_url(object)
  43. end
  44. def outbox
  45. account_outbox_url(object)
  46. end
  47. def endpoints
  48. object
  49. end
  50. def preferred_username
  51. object.username
  52. end
  53. def name
  54. object.display_name
  55. end
  56. def summary
  57. Formatter.instance.simplified_format(object)
  58. end
  59. def icon
  60. object.avatar
  61. end
  62. def image
  63. object.header
  64. end
  65. def public_key
  66. object
  67. end
  68. def url
  69. short_account_url(object)
  70. end
  71. def avatar_exists?
  72. object.avatar.exists?
  73. end
  74. def header_exists?
  75. object.header.exists?
  76. end
  77. def manually_approves_followers
  78. object.locked
  79. end
  80. end