2022-08-20 12:22:20 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-20 12:17:08 -07:00
|
|
|
class Moderation::ReportsController < ApplicationController
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
|
|
|
@type = params[:type]
|
|
|
|
@reports = list_reports(type: @type, last_id: params[:last_id])
|
|
|
|
@reports_last_id = @reports.map(&:id).min
|
|
|
|
@more_data_available = !list_reports(type: @type, last_id: @reports_last_id, size: 1).count.zero?
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2022-09-07 15:55:10 -07:00
|
|
|
format.turbo_stream { render "index", layout: false, status: :see_other }
|
2022-08-20 12:17:08 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def list_reports(type:, last_id:, size: nil)
|
2022-08-20 12:22:20 -07:00
|
|
|
cursor_params = { last_id:, size: }.compact
|
2022-08-20 12:17:08 -07:00
|
|
|
|
2022-08-20 12:22:20 -07:00
|
|
|
if type == "all"
|
2022-08-20 12:17:08 -07:00
|
|
|
Report.cursored_reports(**cursor_params)
|
|
|
|
else
|
|
|
|
Report.cursored_reports_of_type(type, **cursor_params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|