account_serializer.rb 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class REST::AccountSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :username, :acct, :display_name, :locked, :created_at,
  5. :note, :url, :avatar, :avatar_static, :header, :header_static,
  6. :followers_count, :following_count, :statuses_count
  7. has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
  8. def id
  9. object.id.to_s
  10. end
  11. def note
  12. Formatter.instance.simplified_format(object)
  13. end
  14. def url
  15. TagManager.instance.url_for(object)
  16. end
  17. def avatar
  18. full_asset_url(object.avatar_original_url)
  19. end
  20. def avatar_static
  21. full_asset_url(object.avatar_static_url)
  22. end
  23. def header
  24. full_asset_url(object.header_original_url)
  25. end
  26. def header_static
  27. full_asset_url(object.header_static_url)
  28. end
  29. def moved_and_not_nested?
  30. object.moved? && object.moved_to_account.moved_to_account_id.nil?
  31. end
  32. end