logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

actor_serializer.rb (2285B)


  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. '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.exists?
  70. end
  71. def header_exists?
  72. object.header.exists?
  73. end
  74. def manually_approves_followers
  75. object.locked
  76. end
  77. def virtual_tags
  78. object.emojis
  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 Account::FieldSerializer < ActiveModel::Serializer
  89. attributes :type, :name, :value
  90. def type
  91. 'PropertyValue'
  92. end
  93. def value
  94. Formatter.instance.format_field(object.account, object.value)
  95. end
  96. end
  97. end