about summary refs log tree commit diff
path: root/app/models/status.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-03-05 19:23:16 +0100
committerThibaut Girka <thib@sitedethib.com>2019-03-05 19:23:16 +0100
commitf513317ba262d9f5d7aa7dd66f8b61690297e107 (patch)
tree6732fcf1178fc3e27404c6830bc2bc1c832659ae /app/models/status.rb
parent2a4ce7458a16c64029842fde210089453be2ede1 (diff)
parent7d5e2dda78414316f9cf09fcf6096d6a158da312 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/models/status.rb
- db/schema.rb

Both conflicts are caused by us having extra database columns.
Diffstat (limited to 'app/models/status.rb')
-rw-r--r--app/models/status.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 4566c0d20..f576489b4 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -23,6 +23,7 @@
 #  in_reply_to_account_id :bigint(8)
 #  local_only             :boolean
 #  full_status_text       :text             default(""), not null
+#  poll_id                :bigint(8)
 #
 
 class Status < ApplicationRecord
@@ -46,6 +47,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
@@ -64,12 +66,14 @@ 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? }
   validates_with StatusLengthValidator
   validates_with DisallowedHashtagsValidator
   validates :reblog, uniqueness: { scope: :account }, if: :reblog?
+  validates_associated :owned_poll
 
   default_scope { recent }
 
@@ -106,6 +110,7 @@ class Status < ApplicationRecord
                    :tags,
                    :preview_cards,
                    :stream_entry,
+                   :poll,
                    account: :account_stat,
                    active_mentions: { account: :account_stat },
                    reblog: [
@@ -116,6 +121,7 @@ class Status < ApplicationRecord
                      :media_attachments,
                      :conversation,
                      :status_stat,
+                     :poll,
                      account: :account_stat,
                      active_mentions: { account: :account_stat },
                    ],
@@ -257,6 +263,8 @@ class Status < ApplicationRecord
   before_validation :set_conversation
   before_validation :set_local
 
+  after_create :set_poll_id
+
   class << self
     def selectable_visibilities
       visibilities.keys - %w(direct limited)
@@ -458,6 +466,10 @@ class Status < ApplicationRecord
     self.reblog = reblog.reblog if reblog? && reblog.reblog?
   end
 
+  def set_poll_id
+    update_column(: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?