flag.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.filter_map { |uri| account_from_uri(uri) }.select(&:local?)
  6. target_statuses_by_account = object_uris.filter_map { |uri| status_from_uri(uri) }.select(&:local?).group_by(&:account_id)
  7. target_accounts.each do |target_account|
  8. target_statuses = target_statuses_by_account[target_account.id]
  9. next if target_account.suspended?
  10. ReportService.new.call(
  11. @account,
  12. target_account,
  13. status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
  14. comment: @json['content'] || '',
  15. uri: report_uri
  16. )
  17. end
  18. end
  19. private
  20. def skip_reports?
  21. DomainBlock.reject_reports?(@account.domain)
  22. end
  23. def object_uris
  24. @object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
  25. end
  26. def report_uri
  27. @json['id'] unless @json['id'].nil? || invalid_origin?(@json['id'])
  28. end
  29. end