2022-01-17 08:41:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::StatusFilter
|
|
|
|
KEYS = %i(
|
|
|
|
media
|
|
|
|
report_id
|
|
|
|
).freeze
|
|
|
|
|
2023-05-04 03:33:55 +00:00
|
|
|
IGNORED_PARAMS = %w(page report_id).freeze
|
|
|
|
|
2022-01-17 08:41:33 +00:00
|
|
|
attr_reader :params
|
|
|
|
|
|
|
|
def initialize(account, params)
|
|
|
|
@account = account
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def results
|
|
|
|
scope = @account.statuses.where(visibility: [:public, :unlisted])
|
|
|
|
|
|
|
|
params.each do |key, value|
|
2023-05-04 03:33:55 +00:00
|
|
|
next if IGNORED_PARAMS.include?(key.to_s)
|
2022-01-17 08:41:33 +00:00
|
|
|
|
|
|
|
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
scope
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-10-26 11:42:29 +00:00
|
|
|
def scope_for(key, _value)
|
2022-01-17 08:41:33 +00:00
|
|
|
case key.to_s
|
|
|
|
when 'media'
|
2023-11-30 13:30:35 +00:00
|
|
|
Status.joins(:media_attachments).merge(@account.media_attachments).group(:id).reorder('statuses.id desc')
|
2022-01-17 08:41:33 +00:00
|
|
|
else
|
2022-11-14 07:06:06 +00:00
|
|
|
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
|
2022-01-17 08:41:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|