Skip to content

Commit

Permalink
Add own_votes field to poll results in REST API
Browse files Browse the repository at this point in the history
Fixes #10679
  • Loading branch information
ClearlyClaire committed Sep 22, 2019
1 parent 4fe5f8f commit bdfdb7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/poll.rb
Expand Up @@ -54,6 +54,10 @@ def voted?(account)
account.id == account_id || votes.where(account: account).exists?
end

def own_votes(account)
votes.where(account: account).pluck(:choice)
end

delegate :local?, to: :account

def remote?
Expand Down
5 changes: 5 additions & 0 deletions app/serializers/rest/poll_serializer.rb
Expand Up @@ -8,6 +8,7 @@ class REST::PollSerializer < ActiveModel::Serializer
has_many :emojis, serializer: REST::CustomEmojiSerializer

attribute :voted, if: :current_user?
attribute :own_votes, if: :current_user?

def id
object.id.to_s
Expand All @@ -21,6 +22,10 @@ def voted
object.voted?(current_user.account)
end

def own_votes
object.own_votes(current_user.account)
end

def current_user?
!current_user.nil?
end
Expand Down

0 comments on commit bdfdb7b

Please sign in to comment.