Merge commit '71db616fed' into kb_migration

This commit is contained in:
KMY 2023-07-14 12:43:55 +09:00
commit f18fa97f0c
607 changed files with 3491 additions and 2677 deletions

View file

@ -93,7 +93,7 @@ class AccountSearchService < BaseService
.objects
.compact
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
ActiveRecord::Associations::Preloader.new(records: records, associations: :account_stat)
records
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
@ -133,8 +133,12 @@ class AccountSearchService < BaseService
end
def must_clause
fields = %w(username username.* display_name display_name.*)
fields << 'text' << 'text.*' if options[:use_searchable_text]
if options[:start_with_hashtag]
fields = %w(text text.*)
else
fields = %w(username username.* display_name display_name.*)
fields << 'text' << 'text.*' if options[:use_searchable_text]
end
[
{

View file

@ -79,6 +79,9 @@ class ActivityPub::ProcessAccountService < BaseService
@account.silenced_at = domain_block.created_at if auto_silence?
@account.searchability = :private # not null
@account.dissubscribable = false # not null
set_immediate_protocol_attributes!
@account.save
end

View file

@ -23,7 +23,7 @@ class AppealService < BaseService
def notify_staff!
User.those_who_can(:manage_appeals).includes(:account).each do |u|
AdminMailer.new_appeal(u.account, @appeal).deliver_later if u.allows_appeal_emails?
AdminMailer.with(recipient: u.account).new_appeal(@appeal).deliver_later if u.allows_appeal_emails?
end
end
end

View file

@ -8,7 +8,10 @@ class BatchedRemoveStatusService < BaseService
# @param [Hash] options
# @option [Boolean] :skip_side_effects Do not modify feeds and send updates to streaming API
def call(statuses, **options)
ActiveRecord::Associations::Preloader.new.preload(statuses, options[:skip_side_effects] ? :reblogs : [:account, :tags, reblogs: :account])
ActiveRecord::Associations::Preloader.new(
records: statuses,
associations: options[:skip_side_effects] ? :reblogs : [:account, :tags, reblogs: :account]
)
statuses_and_reblogs = statuses.flat_map { |status| [status] + status.reblogs }
@ -17,7 +20,10 @@ class BatchedRemoveStatusService < BaseService
# rely on direct visibility statuses being relatively rare.
statuses_with_account_conversations = statuses.select(&:direct_visibility?)
ActiveRecord::Associations::Preloader.new.preload(statuses_with_account_conversations, [mentions: :account])
ActiveRecord::Associations::Preloader.new(
records: statuses_with_account_conversations,
associations: [mentions: :account]
)
statuses_with_account_conversations.each(&:unlink_from_conversations!)

View file

@ -163,7 +163,12 @@ class NotifyService < BaseService
end
def send_email!
NotificationMailer.public_send(@notification.type, @recipient, @notification).deliver_later(wait: 2.minutes) if NotificationMailer.respond_to?(@notification.type)
return unless NotificationMailer.respond_to?(@notification.type)
NotificationMailer
.with(recipient: @recipient, notification: @notification)
.public_send(@notification.type)
.deliver_later(wait: 2.minutes)
end
def email_needed?

View file

@ -16,7 +16,11 @@ class ReportService < BaseService
create_report!
notify_staff!
forward_to_origin! if forward?
if forward?
forward_to_origin!
forward_to_replied_to!
end
@report
end
@ -29,7 +33,7 @@ class ReportService < BaseService
status_ids: reported_status_ids,
comment: @comment,
uri: @options[:uri],
forwarded: forward?,
forwarded: forward_to_origin?,
category: @category,
rule_ids: @rule_ids
)
@ -40,22 +44,38 @@ class ReportService < BaseService
User.those_who_can(:manage_reports).includes(:account).each do |u|
LocalNotificationWorker.perform_async(u.account_id, @report.id, 'Report', 'admin.report')
AdminMailer.new_report(u.account, @report).deliver_later if u.allows_report_emails?
AdminMailer.with(recipient: u.account).new_report(@report).deliver_later if u.allows_report_emails?
end
end
def forward_to_origin!
ActivityPub::DeliveryWorker.perform_async(
payload,
some_local_account.id,
@target_account.inbox_url
)
return unless forward_to_origin?
# Send report to the server where the account originates from
ActivityPub::DeliveryWorker.perform_async(payload, some_local_account.id, @target_account.inbox_url)
end
def forward_to_replied_to!
# Send report to servers to which the account was replying to, so they also have a chance to act
inbox_urls = Account.remote.where(domain: forward_to_domains).where(id: Status.where(id: reported_status_ids).where.not(in_reply_to_account_id: nil).select(:in_reply_to_account_id)).inboxes - [@target_account.inbox_url]
inbox_urls.each do |inbox_url|
ActivityPub::DeliveryWorker.perform_async(payload, some_local_account.id, inbox_url)
end
end
def forward?
!@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward])
end
def forward_to_origin?
forward? && forward_to_domains.include?(@target_account.domain)
end
def forward_to_domains
@forward_to_domains ||= (@options[:forward_to_domains] || [@target_account.domain]).filter_map { |domain| TagManager.instance.normalize_domain(domain&.strip) }.uniq
end
def reported_status_ids
return AccountStatusesFilter.new(@target_account, @source_account).results.with_discarded.find(Array(@status_ids)).pluck(:id) if @source_account.local?

View file

@ -63,7 +63,7 @@ class ResolveURLService < BaseService
end
def fetch_resource_service
@_fetch_resource_service ||= FetchResourceService.new
@fetch_resource_service ||= FetchResourceService.new
end
def resource_url

View file

@ -38,7 +38,8 @@ class SearchService < BaseService
resolve: @resolve,
offset: @offset,
use_searchable_text: true,
following: @following
following: @following,
start_with_hashtag: @query.start_with?('#')
)
end
@ -102,7 +103,7 @@ class SearchService < BaseService
end
def url_resource
@_url_resource ||= ResolveURLService.new.call(@query, on_behalf_of: @account)
@url_resource ||= ResolveURLService.new.call(@query, on_behalf_of: @account)
end
def url_resource_symbol
@ -112,11 +113,11 @@ class SearchService < BaseService
def full_text_searchable?
return false unless Chewy.enabled?
statuses_search? && !@account.nil? && !((@query.start_with?('#') || @query.include?('@')) && !@query.include?(' '))
statuses_search? && !@account.nil? && !(@query.include?('@') && !@query.include?(' '))
end
def account_searchable?
account_search? && !(@query.start_with?('#') || (@query.include?('@') && @query.include?(' ')))
account_search? && !(@query.include?('@') && @query.include?(' '))
end
def hashtag_searchable?