flag.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Flag < ActivityPub::Activity
  3. COMMENT_SIZE_LIMIT = 5000
  4. def perform
  5. return if skip_reports?
  6. target_accounts = object_uris.filter_map { |uri| account_from_uri(uri) }
  7. target_statuses_by_account = object_uris.filter_map { |uri| status_from_uri(uri) }.group_by(&:account_id)
  8. target_accounts.each do |target_account|
  9. target_statuses = target_statuses_by_account[target_account.id]
  10. replied_to_accounts = target_statuses.nil? ? [] : Account.local.where(id: target_statuses.filter_map(&:in_reply_to_account_id))
  11. next if target_account.suspended? || (!target_account.local? && replied_to_accounts.none?)
  12. ReportService.new.call(
  13. @account,
  14. target_account,
  15. status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
  16. comment: report_comment,
  17. uri: report_uri
  18. )
  19. end
  20. end
  21. private
  22. def skip_reports?
  23. DomainBlock.reject_reports?(@account.domain)
  24. end
  25. def object_uris
  26. @object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
  27. end
  28. def report_uri
  29. @json['id'] unless @json['id'].nil? || non_matching_uri_hosts?(@account.uri, @json['id'])
  30. end
  31. def report_comment
  32. (@json['content'] || '')[0...COMMENT_SIZE_LIMIT]
  33. end
  34. end