diff --git a/app/lib/account_statuses_filter.rb b/app/lib/account_statuses_filter.rb index cfc9be96608..db1c3df7763 100644 --- a/app/lib/account_statuses_filter.rb +++ b/app/lib/account_statuses_filter.rb @@ -48,12 +48,20 @@ class AccountStatusesFilter def filtered_scope scope = account.statuses.left_outer_joins(:mentions) - scope.merge!(scope.where(visibility: follower? ? %i(public unlisted private) : %i(public unlisted)).or(scope.where(mentions: { account_id: current_account.id })).group(Status.arel_table[:id])) + scope.merge!(visibility_scope(scope).or(scope.where(mentions: { account_id: current_account.id })).group(Status.arel_table[:id])) scope.merge!(filtered_reblogs_scope) if reblogs_may_occur? scope end + def visibility_scope(scope) + if follower? + scope.list_eligible_visibility + else + scope.distributable_visibility + end + end + def filtered_reblogs_scope scope = Status.left_outer_joins(reblog: :account) scope diff --git a/app/services/report_service.rb b/app/services/report_service.rb index c95e216c790..40749c807fd 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -82,15 +82,24 @@ 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('EXISTS (SELECT 1 FROM mentions m JOIN accounts a ON m.account_id = a.id WHERE lower(a.domain) = ?)', domain))) + scope.merge!(visibility_scope(scope).or(scope.where('EXISTS (SELECT 1 FROM mentions m JOIN accounts a ON m.account_id = a.id WHERE lower(a.domain) = ?)', @source_account.domain.to_s.downcase))) # Allow missing posts to not drop reports that include e.g. a deleted post scope.where(id: Array(@status_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 Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account)) end