You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
712 B

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