* Add polls

Fix #1629

* Add tests

* Fixes

* Change API for creating polls

* Use name instead of content for votes

* Remove poll validation for remote polls

* Add polls to public pages

* When updating the poll, update options just in case they were changed

* Fix public pages showing both poll and other media
This commit is contained in:
Eugen Rochko 2019-03-03 22:18:23 +01:00 committed by GitHub
parent 99dc212ae5
commit 230a012f00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 1038 additions and 19 deletions

View file

@ -21,6 +21,7 @@
# account_id :bigint(8) not null
# application_id :bigint(8)
# in_reply_to_account_id :bigint(8)
# poll_id :bigint(8)
#
class Status < ApplicationRecord
@ -44,6 +45,7 @@ class Status < ApplicationRecord
belongs_to :account, inverse_of: :statuses
belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account', optional: true
belongs_to :conversation, optional: true
belongs_to :poll, optional: true
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
@ -61,6 +63,7 @@ class Status < ApplicationRecord
has_one :notification, as: :activity, dependent: :destroy
has_one :stream_entry, as: :activity, inverse_of: :status
has_one :status_stat, inverse_of: :status
has_one :owned_poll, class_name: 'Poll', inverse_of: :status, dependent: :destroy
validates :uri, uniqueness: true, presence: true, unless: :local?
validates :text, presence: true, unless: -> { with_media? || reblog? }
@ -101,6 +104,7 @@ class Status < ApplicationRecord
:tags,
:preview_cards,
:stream_entry,
:poll,
account: :account_stat,
active_mentions: { account: :account_stat },
reblog: [
@ -111,6 +115,7 @@ class Status < ApplicationRecord
:media_attachments,
:conversation,
:status_stat,
:poll,
account: :account_stat,
active_mentions: { account: :account_stat },
],
@ -250,6 +255,8 @@ class Status < ApplicationRecord
before_validation :set_conversation
before_validation :set_local
before_save :set_poll_id
class << self
def selectable_visibilities
visibilities.keys - %w(direct limited)
@ -438,6 +445,10 @@ class Status < ApplicationRecord
self.reblog = reblog.reblog if reblog? && reblog.reblog?
end
def set_poll_id
self.poll_id = owned_poll.id unless owned_poll.nil?
end
def set_visibility
self.visibility = (account.locked? ? :private : :public) if visibility.nil?
self.visibility = reblog.visibility if reblog?