2022-03-26 08:38:44 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-12-01 20:00:41 +09:00
|
|
|
module Status::SnapshotConcern
|
2022-03-26 08:38:44 +09:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
has_many :edits, class_name: 'StatusEdit', inverse_of: :status, dependent: :destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
def edited?
|
|
|
|
edited_at.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_snapshot(account_id: nil, at_time: nil, rate_limit: true)
|
|
|
|
# We don't use `edits#new` here to avoid it having saved when the
|
|
|
|
# status is saved, since we want to control that manually
|
|
|
|
|
|
|
|
StatusEdit.new(
|
|
|
|
status_id: id,
|
|
|
|
text: text,
|
|
|
|
spoiler_text: spoiler_text,
|
|
|
|
sensitive: sensitive,
|
|
|
|
ordered_media_attachment_ids: ordered_media_attachment_ids&.dup || media_attachments.pluck(:id),
|
|
|
|
media_descriptions: ordered_media_attachments.map(&:description),
|
|
|
|
poll_options: preloadable_poll&.options&.dup,
|
|
|
|
account_id: account_id || self.account_id,
|
|
|
|
created_at: at_time || edited_at,
|
|
|
|
rate_limit: rate_limit
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-11-01 00:12:08 +09:00
|
|
|
def snapshot!(**)
|
|
|
|
build_snapshot(**).save!
|
2022-03-26 08:38:44 +09:00
|
|
|
end
|
|
|
|
end
|