account_serializer.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # frozen_string_literal: true
  2. class REST::AccountSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. include FormattingHelper
  5. attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :group, :created_at,
  6. :note, :url, :avatar, :avatar_static, :header, :header_static,
  7. :followers_count, :following_count, :statuses_count, :last_status_at
  8. has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
  9. has_many :emojis, serializer: REST::CustomEmojiSerializer
  10. attribute :suspended, if: :suspended?
  11. attribute :silenced, key: :limited, if: :silenced?
  12. attribute :noindex, if: :local?
  13. class FieldSerializer < ActiveModel::Serializer
  14. include FormattingHelper
  15. attributes :name, :value, :verified_at
  16. def value
  17. account_field_value_format(object)
  18. end
  19. end
  20. has_many :fields
  21. def id
  22. object.id.to_s
  23. end
  24. def acct
  25. object.pretty_acct
  26. end
  27. def note
  28. object.suspended? ? '' : account_bio_format(object)
  29. end
  30. def url
  31. ActivityPub::TagManager.instance.url_for(object)
  32. end
  33. def avatar
  34. full_asset_url(object.suspended? ? object.avatar.default_url : object.avatar_original_url)
  35. end
  36. def avatar_static
  37. full_asset_url(object.suspended? ? object.avatar.default_url : object.avatar_static_url)
  38. end
  39. def header
  40. full_asset_url(object.suspended? ? object.header.default_url : object.header_original_url)
  41. end
  42. def header_static
  43. full_asset_url(object.suspended? ? object.header.default_url : object.header_static_url)
  44. end
  45. def created_at
  46. object.created_at.midnight.as_json
  47. end
  48. def last_status_at
  49. object.last_status_at&.to_date&.iso8601
  50. end
  51. def display_name
  52. object.suspended? ? '' : object.display_name
  53. end
  54. def locked
  55. object.suspended? ? false : object.locked
  56. end
  57. def bot
  58. object.suspended? ? false : object.bot
  59. end
  60. def discoverable
  61. object.suspended? ? false : object.discoverable
  62. end
  63. def moved_to_account
  64. object.suspended? ? nil : object.moved_to_account
  65. end
  66. def emojis
  67. object.suspended? ? [] : object.emojis
  68. end
  69. def fields
  70. object.suspended? ? [] : object.fields
  71. end
  72. def suspended
  73. object.suspended?
  74. end
  75. def silenced
  76. object.silenced?
  77. end
  78. def noindex
  79. object.user_prefers_noindex?
  80. end
  81. delegate :suspended?, :silenced?, :local?, to: :object
  82. def moved_and_not_nested?
  83. object.moved? && object.moved_to_account.moved_to_account_id.nil?
  84. end
  85. end