poll_serializer.rb 814 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class REST::PollSerializer < ActiveModel::Serializer
  3. # Please update `app/javascript/mastodon/api_types/polls.ts` when making changes to the attributes
  4. attributes :id, :expires_at, :expired,
  5. :multiple, :votes_count, :voters_count
  6. has_many :loaded_options, key: :options
  7. has_many :emojis, serializer: REST::CustomEmojiSerializer
  8. attribute :voted, if: :current_user?
  9. attribute :own_votes, if: :current_user?
  10. def id
  11. object.id.to_s
  12. end
  13. def expired
  14. object.expired?
  15. end
  16. def voted
  17. object.voted?(current_user.account)
  18. end
  19. def own_votes
  20. object.own_votes(current_user.account)
  21. end
  22. def current_user?
  23. !current_user.nil?
  24. end
  25. class OptionSerializer < ActiveModel::Serializer
  26. attributes :title, :votes_count
  27. end
  28. end