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.

33 lines
1.0 KiB

  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. next if Report.where(account: @account, target_account: target_account).exists?
  9. target_statuses = target_statuses_by_account[target_account.id]
  10. ReportService.new.call(
  11. @account,
  12. target_account,
  13. status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
  14. comment: @json['content'] || ''
  15. )
  16. end
  17. end
  18. private
  19. def skip_reports?
  20. DomainBlock.find_by(domain: @account.domain)&.reject_reports?
  21. end
  22. def object_uris
  23. @object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
  24. end
  25. end