mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-27 10:31:36 +01:00
75580360cd
Conflicts: - `.rubocop_todo.yml`: Upstream fixed a bunch lint issues, and changed the `Max` parameter of the `Metrics/AbcSize` cop. Glitch-soc has different code and slightly higher `AbcSize` complexity, modified the `.rubocop_todo.yml` file accordingly. - `app/policies/status_policy.rb`: Upstream changed `account.suspended?` to `account.unavailable?` to prepare for delete flags. Glitch-soc has additional local-only conditions. Ported upstream's refactor while keeping glitch-soc's additional condition. - `app/serializers/initial_state_serializer.rb`: Upstream refactored a bunch of stuff while glitch-soc has more settings. Refactored as upstream did while keeping glitch-soc's settings.
36 lines
1 KiB
Ruby
36 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Status::SnapshotConcern
|
|
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,
|
|
content_type: content_type,
|
|
created_at: at_time || edited_at,
|
|
rate_limit: rate_limit
|
|
)
|
|
end
|
|
|
|
def snapshot!(**options)
|
|
build_snapshot(**options).save!
|
|
end
|
|
end
|