Add voters count support (#11917)
* Add voters count to polls * Add ActivityPub serialization and parsing of voters count * Add support for voters count in WebUI * Move incrementation of voters count out of redis lock * Reword “voters” to “people”
This commit is contained in:
parent
cfe2d1cc4a
commit
3babf8464b
13 changed files with 113 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri, :conversation, :sensitive
|
||||
context_extensions :atom_uri, :conversation, :sensitive, :voters_count
|
||||
|
||||
attributes :id, :type, :summary,
|
||||
:in_reply_to, :published, :url,
|
||||
|
@ -23,6 +23,8 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
attribute :end_time, if: :poll_and_expires?
|
||||
attribute :closed, if: :poll_and_expired?
|
||||
|
||||
attribute :voters_count, if: :poll_and_voters_count?
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
@ -141,6 +143,10 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
|
||||
alias end_time closed
|
||||
|
||||
def voters_count
|
||||
object.preloadable_poll.voters_count
|
||||
end
|
||||
|
||||
def poll_and_expires?
|
||||
object.preloadable_poll&.expires_at&.present?
|
||||
end
|
||||
|
@ -149,6 +155,10 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
object.preloadable_poll&.expired?
|
||||
end
|
||||
|
||||
def poll_and_voters_count?
|
||||
object.preloadable_poll&.voters_count
|
||||
end
|
||||
|
||||
class MediaAttachmentSerializer < ActivityPub::Serializer
|
||||
context_extensions :blurhash, :focal_point
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue