logo

mastofe

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

account_serializer.rb (1198B)


  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. class FieldSerializer < ActiveModel::Serializer
  9. attributes :name, :value
  10. def value
  11. Formatter.instance.format_field(object.account, object.value)
  12. end
  13. end
  14. has_many :fields
  15. def id
  16. object.id.to_s
  17. end
  18. def note
  19. Formatter.instance.simplified_format(object, custom_emojify: true)
  20. end
  21. def url
  22. TagManager.instance.url_for(object)
  23. end
  24. def avatar
  25. full_asset_url(object.avatar_original_url)
  26. end
  27. def avatar_static
  28. full_asset_url(object.avatar_static_url)
  29. end
  30. def header
  31. full_asset_url(object.header_original_url)
  32. end
  33. def header_static
  34. full_asset_url(object.header_static_url)
  35. end
  36. def moved_and_not_nested?
  37. object.moved? && object.moved_to_account.moved_to_account_id.nil?
  38. end
  39. end