flag.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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.reject_reports?(@account.domain)
  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