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.

116 lines
1.9 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. attribute :moved_to, if: :moved?
  11. class EndpointsSerializer < ActiveModel::Serializer
  12. include RoutingHelper
  13. attributes :shared_inbox
  14. def shared_inbox
  15. inbox_url
  16. end
  17. end
  18. has_one :endpoints, serializer: EndpointsSerializer
  19. has_one :icon, serializer: ActivityPub::ImageSerializer, if: :avatar_exists?
  20. has_one :image, serializer: ActivityPub::ImageSerializer, if: :header_exists?
  21. delegate :moved?, to: :object
  22. def id
  23. account_url(object)
  24. end
  25. def type
  26. 'Person'
  27. end
  28. def following
  29. account_following_index_url(object)
  30. end
  31. def followers
  32. account_followers_url(object)
  33. end
  34. def inbox
  35. account_inbox_url(object)
  36. end
  37. def outbox
  38. account_outbox_url(object)
  39. end
  40. def featured
  41. account_collection_url(object, :featured)
  42. end
  43. def endpoints
  44. object
  45. end
  46. def preferred_username
  47. object.username
  48. end
  49. def name
  50. object.display_name
  51. end
  52. def summary
  53. Formatter.instance.simplified_format(object)
  54. end
  55. def icon
  56. object.avatar
  57. end
  58. def image
  59. object.header
  60. end
  61. def public_key
  62. object
  63. end
  64. def url
  65. short_account_url(object)
  66. end
  67. def avatar_exists?
  68. object.avatar.exists?
  69. end
  70. def header_exists?
  71. object.header.exists?
  72. end
  73. def manually_approves_followers
  74. object.locked
  75. end
  76. def virtual_tags
  77. object.emojis
  78. end
  79. def moved_to
  80. ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
  81. end
  82. class CustomEmojiSerializer < ActivityPub::EmojiSerializer
  83. end
  84. end