From 51a175cfbfcd2998e715440749a6486fe7ec943b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 28 Jan 2026 09:50:03 -0500 Subject: [PATCH] Extract `visibility_scope` method to re-use existing scopes in `ReportService` --- app/services/report_service.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/services/report_service.rb b/app/services/report_service.rb index 9366a69e759..371d1b97c38 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -84,19 +84,16 @@ class ReportService < BaseService return AccountStatusesFilter.new(@target_account, @source_account).results.with_discarded.find(Array(@status_ids)).pluck(:id) if @source_account.local? # If the account making reports is remote, it is likely anonymized so we have to relax the requirements for attaching statuses. - domain = @source_account.domain.to_s.downcase - has_followers = @target_account.followers.with_domain(domain).exists? - visibility = has_followers ? %i(public unlisted private) : %i(public unlisted) scope = @target_account.statuses.with_discarded - scope.merge!(scope.where(visibility: visibility).or(scope.where(domain_mentions(domain)))) + scope.merge!(visibility_scope(scope).or(scope.where(domain_mentions))) # Allow missing posts to not drop reports that include e.g. a deleted post scope.where(id: Array(@status_ids)).pluck(:id) end - def domain_mentions(domain) + def domain_mentions Mention .joins(:account) - .where(Account.arel_table[:domain].lower.eq domain) + .merge(Account.with_domain(@source_account.domain)) .select(1).arel.exists end @@ -104,6 +101,18 @@ class ReportService < BaseService @target_account.collections.find(Array(@collection_ids)).pluck(:id) end + def visibility_scope(scope) + if target_has_source_domain_followers? + scope.list_eligible_visibility + else + scope.distributable_visibility + end + end + + def target_has_source_domain_followers? + @target_account.followers.with_domain(@source_account.domain).exists? + end + def payload serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account).to_json end