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.

36 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. 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. uri: report_uri
  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. def report_uri
  26. @json['id'] unless @json['id'].nil? || invalid_origin?(@json['id'])
  27. end
  28. end