Merge remote-tracking branch 'parent/main' into upstream-20241113

This commit is contained in:
KMY 2024-11-13 08:17:38 +09:00
commit 910eafda63
177 changed files with 1625 additions and 659 deletions

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
module Account::Sensitizes
extend ActiveSupport::Concern
included do
scope :sensitized, -> { where.not(sensitized_at: nil) }
end
def sensitized?
sensitized_at.present?
end
def sensitize!(date = Time.now.utc)
update!(sensitized_at: date)
end
def unsensitize!
update!(sensitized_at: nil)
end
end

View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
module Account::Silences
extend ActiveSupport::Concern
included do
scope :silenced, -> { where.not(silenced_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
end
def silenced?
silenced_at.present?
end
def silence!(date = Time.now.utc)
update!(silenced_at: date)
end
def unsilence!
update!(silenced_at: nil)
end
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
module InetContainer
extend ActiveSupport::Concern
included do
scope :containing, ->(value) { where('ip >>= ?', value) }
scope :contained_by, ->(value) { where('ip <<= ?', value) }
end
end

View file

@ -15,7 +15,9 @@ module Status::SafeReblogInsert
#
# The code is kept similar to ActiveRecord::Persistence code and calls it
# directly when we are not handling a reblog.
def _insert_record(values, returning)
#
# https://github.com/rails/rails/blob/v7.2.1.1/activerecord/lib/active_record/persistence.rb#L238-L263
def _insert_record(connection, values, returning)
return super unless values.is_a?(Hash) && values['reblog_of_id']&.value.present?
primary_key = self.primary_key
@ -30,14 +32,19 @@ module Status::SafeReblogInsert
# The following line departs from stock ActiveRecord
# Original code was:
# im.insert(values.transform_keys { |name| arel_table[name] })
# im = Arel::InsertManager.new(arel_table)
# Instead, we use a custom builder when a reblog is happening:
im = _compile_reblog_insert(values)
connection.insert(im, "#{self} Create", primary_key || false, primary_key_value, returning: returning).tap do |result|
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
# For our purposes, it's equivalent to a foreign key constraint violation
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil?
with_connection do |_c|
connection.insert(
im, "#{self} Create", primary_key || false, primary_key_value,
returning: returning
).tap do |result|
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
# For our purposes, it's equivalent to a foreign key constraint violation
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil?
end
end
end