1
0

account_serializer.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # frozen_string_literal: true
  2. class REST::AccountSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :group, :created_at,
  5. :note, :url, :avatar, :avatar_static, :header, :header_static,
  6. :followers_count, :following_count, :statuses_count, :last_status_at
  7. has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
  8. has_many :emojis, serializer: REST::CustomEmojiSerializer
  9. class FieldSerializer < ActiveModel::Serializer
  10. attributes :name, :value, :verified_at
  11. def value
  12. Formatter.instance.format_field(object.account, object.value)
  13. end
  14. end
  15. has_many :fields
  16. def id
  17. object.id.to_s
  18. end
  19. def acct
  20. object.pretty_acct
  21. end
  22. def note
  23. Formatter.instance.simplified_format(object)
  24. end
  25. def url
  26. ActivityPub::TagManager.instance.url_for(object)
  27. end
  28. def avatar
  29. full_asset_url(object.avatar_original_url)
  30. end
  31. def avatar_static
  32. full_asset_url(object.avatar_static_url)
  33. end
  34. def header
  35. full_asset_url(object.header_original_url)
  36. end
  37. def header_static
  38. full_asset_url(object.header_static_url)
  39. end
  40. def moved_and_not_nested?
  41. object.moved? && object.moved_to_account.moved_to_account_id.nil?
  42. end
  43. def last_status_at
  44. object.last_status_at&.to_date&.iso8601
  45. end
  46. end