where i deviate from standard mastodon assets
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.

report_filter.rb 750B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. class ReportFilter
  3. KEYS = %i(
  4. resolved
  5. account_id
  6. target_account_id
  7. by_target_domain
  8. ).freeze
  9. attr_reader :params
  10. def initialize(params)
  11. @params = params
  12. end
  13. def results
  14. scope = Report.unresolved
  15. params.each do |key, value|
  16. scope = scope.merge scope_for(key, value)
  17. end
  18. scope
  19. end
  20. def scope_for(key, value)
  21. case key.to_sym
  22. when :by_target_domain
  23. Report.where(target_account: Account.where(domain: value))
  24. when :resolved
  25. Report.resolved
  26. when :account_id
  27. Report.where(account_id: value)
  28. when :target_account_id
  29. Report.where(target_account_id: value)
  30. else
  31. raise "Unknown filter: #{key}"
  32. end
  33. end
  34. end