Implement FEP 7888: Part 1 - publish conversation context (#35959)

This commit is contained in:
Jesse Karmani 2025-09-05 12:28:29 -07:00 committed by GitHub
parent 9463a31107
commit 65b4a0a6f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 309 additions and 12 deletions

View file

@ -4,10 +4,12 @@
#
# Table name: conversations
#
# id :bigint(8) not null, primary key
# uri :string
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint(8) not null, primary key
# uri :string
# created_at :datetime not null
# updated_at :datetime not null
# parent_account_id :bigint(8)
# parent_status_id :bigint(8)
#
class Conversation < ApplicationRecord
@ -15,7 +17,24 @@ class Conversation < ApplicationRecord
has_many :statuses, dependent: nil
belongs_to :parent_status, class_name: 'Status', optional: true, inverse_of: :conversation
belongs_to :parent_account, class_name: 'Account', optional: true
scope :local, -> { where(uri: nil) }
before_validation :set_parent_account, on: :create
def local?
uri.nil?
end
def object_type
:conversation
end
private
def set_parent_account
self.parent_account = parent_status.account if parent_status.present?
end
end

View file

@ -70,6 +70,8 @@ class Status < ApplicationRecord
belongs_to :reblog, foreign_key: 'reblog_of_id', inverse_of: :reblogs
end
has_one :owned_conversation, class_name: 'Conversation', foreign_key: 'parent_status_id', inverse_of: :parent_status, dependent: nil
has_many :favourites, inverse_of: :status, dependent: :destroy
has_many :bookmarks, inverse_of: :status, dependent: :destroy
has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy
@ -442,7 +444,8 @@ class Status < ApplicationRecord
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
conversation = build_owned_conversation
self.conversation = conversation
end
end