2017-05-12 19:09:21 +02:00
|
|
|
# frozen_string_literal: true
|
2023-02-20 00:58:28 -05:00
|
|
|
|
2017-05-12 19:09:21 +02:00
|
|
|
# == Schema Information
|
|
|
|
|
#
|
|
|
|
|
# Table name: conversations
|
|
|
|
|
#
|
2025-09-05 12:28:29 -07:00
|
|
|
# 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)
|
2017-05-12 19:09:21 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
class Conversation < ApplicationRecord
|
2019-07-28 17:47:37 +02:00
|
|
|
validates :uri, uniqueness: true, if: :uri?
|
|
|
|
|
|
2023-12-01 10:52:47 -05:00
|
|
|
has_many :statuses, dependent: nil
|
2019-07-28 17:47:37 +02:00
|
|
|
|
2025-12-03 15:33:27 +01:00
|
|
|
belongs_to :parent_status, class_name: 'Status', optional: true, inverse_of: :owned_conversation
|
2025-09-05 12:28:29 -07:00
|
|
|
belongs_to :parent_account, class_name: 'Account', optional: true
|
|
|
|
|
|
|
|
|
|
scope :local, -> { where(uri: nil) }
|
|
|
|
|
|
|
|
|
|
before_validation :set_parent_account, on: :create
|
|
|
|
|
|
2025-09-09 20:27:30 +02:00
|
|
|
def to_param
|
|
|
|
|
"#{parent_account_id}-#{parent_status_id}" unless parent_account_id.nil? || parent_status_id.nil?
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-28 17:47:37 +02:00
|
|
|
def local?
|
|
|
|
|
uri.nil?
|
|
|
|
|
end
|
2025-09-05 12:28:29 -07:00
|
|
|
|
|
|
|
|
def object_type
|
|
|
|
|
:conversation
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def set_parent_account
|
|
|
|
|
self.parent_account = parent_status.account if parent_status.present?
|
|
|
|
|
end
|
2017-05-12 19:09:21 +02:00
|
|
|
end
|