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.

90 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::ActorSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :type, :following, :followers,
  5. :inbox, :outbox, :preferred_username,
  6. :name, :summary, :url
  7. has_one :public_key, serializer: ActivityPub::PublicKeySerializer
  8. attribute :locked, key: '_:locked'
  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. has_one :icon, serializer: ImageSerializer, if: :avatar_exists?
  20. has_one :image, serializer: ImageSerializer, if: :header_exists?
  21. def id
  22. account_url(object)
  23. end
  24. def type
  25. 'Person'
  26. end
  27. def following
  28. account_following_index_url(object)
  29. end
  30. def followers
  31. account_followers_url(object)
  32. end
  33. def inbox
  34. account_inbox_url(object)
  35. end
  36. def outbox
  37. account_outbox_url(object)
  38. end
  39. def preferred_username
  40. object.username
  41. end
  42. def name
  43. object.display_name
  44. end
  45. def summary
  46. Formatter.instance.simplified_format(object)
  47. end
  48. def icon
  49. object.avatar
  50. end
  51. def image
  52. object.header
  53. end
  54. def public_key
  55. object
  56. end
  57. def url
  58. short_account_url(object)
  59. end
  60. def avatar_exists?
  61. object.avatar.exists?
  62. end
  63. def header_exists?
  64. object.header.exists?
  65. end
  66. end