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/conversation.rb3
-rw-r--r--app/models/status.rb10
-rw-r--r--app/models/status_mute.rb2
3 files changed, 13 insertions, 2 deletions
diff --git a/app/models/conversation.rb b/app/models/conversation.rb
index d1674fe4e..e065c34c8 100644
--- a/app/models/conversation.rb
+++ b/app/models/conversation.rb
@@ -9,6 +9,7 @@
 #  updated_at :datetime         not null
 #  account_id :bigint(8)
 #  public     :boolean          default(FALSE), not null
+#  root       :string
 #
 
 class Conversation < ApplicationRecord
@@ -16,7 +17,7 @@ class Conversation < ApplicationRecord
 
   has_many :statuses
   has_many :mutes, class_name: 'ConversationMute', inverse_of: :conversation, dependent: :destroy
-  belongs_to :account, inverse_of: :threads
+  belongs_to :account, inverse_of: :threads, optional: true
 
   def local?
     uri.nil?
diff --git a/app/models/status.rb b/app/models/status.rb
index 9067f44df..9c061bf85 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -376,6 +376,7 @@ class Status < ApplicationRecord
   after_destroy_commit :decrement_counter_caches
 
   after_create_commit :store_uri, if: :local?
+  after_create_commit :store_url, if: :local?
   after_create_commit :update_statistics, if: :local?
 
   around_create Mastodon::Snowflake::Callbacks
@@ -392,6 +393,7 @@ class Status < ApplicationRecord
 
   after_save :set_domain_permissions, if: :local?
   after_save :set_semiprivate, if: :local?
+  after_save :set_conversation_root
 
   class << self
     def selectable_visibilities
@@ -676,6 +678,10 @@ class Status < ApplicationRecord
     update_column(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
   end
 
+  def store_url
+    update_column(:url, ActivityPub::TagManager.instance.url_for(self)) if url.nil?
+  end
+
   def prepare_contents
     text&.strip!
     spoiler_text&.strip!
@@ -717,6 +723,10 @@ class Status < ApplicationRecord
     end
   end
 
+  def set_conversation_root
+    conversation.update!(root: uri, account_id: account_id, public: distributable?) if !reply && conversation.root.blank?
+  end
+
   def carried_over_reply_to_account_id
     if thread.account_id == account_id && thread.reply?
       thread.in_reply_to_account_id
diff --git a/app/models/status_mute.rb b/app/models/status_mute.rb
index 223893604..1e01f0278 100644
--- a/app/models/status_mute.rb
+++ b/app/models/status_mute.rb
@@ -4,7 +4,7 @@
 # Table name: status_mutes
 #
 #  id         :bigint(8)        not null, primary key
-#  account_id :integer          not null
+#  account_id :bigint(8)        not null
 #  status_id  :bigint(8)        not null
 #