You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
940 B

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Flag < ActivityPub::Activity
  3. def perform
  4. return if skip_reports?
  5. target_accounts = object_uris.map { |uri| account_from_uri(uri) }.compact.select(&:local?)
  6. target_statuses_by_account = object_uris.map { |uri| status_from_uri(uri) }.compact.select(&:local?).group_by(&:account_id)
  7. target_accounts.each do |target_account|
  8. target_statuses = target_statuses_by_account[target_account.id]
  9. ReportService.new.call(
  10. @account,
  11. target_account,
  12. status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
  13. comment: @json['content'] || ''
  14. )
  15. end
  16. end
  17. private
  18. def skip_reports?
  19. DomainBlock.find_by(domain: @account.domain)&.reject_reports?
  20. end
  21. def object_uris
  22. @object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
  23. end
  24. end