about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/account_associations.rb3
-rw-r--r--app/models/conversation.rb3
-rw-r--r--app/models/status.rb23
3 files changed, 16 insertions, 13 deletions
diff --git a/app/models/concerns/account_associations.rb b/app/models/concerns/account_associations.rb
index cca3a17fa..db7396582 100644
--- a/app/models/concerns/account_associations.rb
+++ b/app/models/concerns/account_associations.rb
@@ -60,5 +60,8 @@ module AccountAssociations
     # Hashtags
     has_and_belongs_to_many :tags
     has_many :featured_tags, -> { includes(:tag) }, dependent: :destroy, inverse_of: :account
+
+    # Threads
+    has_many :threads, class_name: 'Conversation', inverse_of: :account, dependent: :nullify
   end
 end
diff --git a/app/models/conversation.rb b/app/models/conversation.rb
index bbe3ada31..d1674fe4e 100644
--- a/app/models/conversation.rb
+++ b/app/models/conversation.rb
@@ -7,6 +7,8 @@
 #  uri        :string
 #  created_at :datetime         not null
 #  updated_at :datetime         not null
+#  account_id :bigint(8)
+#  public     :boolean          default(FALSE), not null
 #
 
 class Conversation < ApplicationRecord
@@ -14,6 +16,7 @@ class Conversation < ApplicationRecord
 
   has_many :statuses
   has_many :mutes, class_name: 'ConversationMute', inverse_of: :conversation, dependent: :destroy
+  belongs_to :account, inverse_of: :threads
 
   def local?
     uri.nil?
diff --git a/app/models/status.rb b/app/models/status.rb
index 120a69715..657fcaca0 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -290,8 +290,7 @@ class Status < ApplicationRecord
 
   before_validation :prepare_contents, if: :local?
   before_validation :set_reblog
-  before_validation :set_conversation
-  before_validation :set_visibility
+  before_validation :set_conversation_perms
   before_validation :set_local
 
   after_create :set_poll_id
@@ -537,27 +536,25 @@ class Status < ApplicationRecord
     update_column(:poll_id, poll.id) unless poll.nil?
   end
 
-  def set_visibility
-    self.visibility = reblog.visibility if reblog? && visibility.nil?
-    self.visibility = (account.locked? ? :private : :public) if visibility.nil?
-    self.visibility = thread.visibility unless thread.nil? || %w(public unlisted).include?(thread.visibility) || ['direct', 'limited', thread.visibility].include?(visibility.to_s)
-    self.sensitive  = false if sensitive.nil?
-  end
-
   def set_locality
     self.local_only = marked_local_only? if account.domain.nil? && !attribute_changed?(:local_only)
   end
 
-  def set_conversation
+  def set_conversation_perms
     self.thread = thread.reblog if thread&.reblog?
-
     self.reply = !(in_reply_to_id.nil? && thread.nil?) unless reply
+    self.visibility = reblog.visibility if reblog? && visibility.nil?
+    self.visibility = (account.locked? ? :private : :public) if visibility.nil?
+    self.visibility = thread.visibility unless thread.nil? || %w(public unlisted).include?(thread.visibility) || ['direct', 'limited', thread.visibility].include?(visibility.to_s)
+    self.sensitive  = false if sensitive.nil?
 
     if reply? && !thread.nil?
       self.in_reply_to_account_id = carried_over_reply_to_account_id
       self.conversation_id        = thread.conversation_id if conversation_id.nil?
     elsif conversation_id.nil?
-      self.conversation = Conversation.new
+      self.conversation = reply? ? Conversation.new(account_id: nil, public: false) : Conversation.new(account_id: account_id, public: %w(public unlisted).include?(visibility.to_s))
+    elsif !reply? && account_id != conversation.account_id
+      conversation.update!(account_id: account_id, public: %w(public unlisted).include?(visibility.to_s))
     end
   end
 
@@ -616,4 +613,4 @@ class Status < ApplicationRecord
     end
   end
 end
-# rubocop:enable Metrics/ClassLength
\ No newline at end of file
+# rubocop:enable Metrics/ClassLength