2022-07-18 07:26:11 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TimelineController < ApplicationController
|
|
|
|
before_action :authenticate_user!
|
2022-10-24 06:31:49 -07:00
|
|
|
before_action :set_list, only: %i[list]
|
|
|
|
before_action :set_lists
|
2022-07-18 07:26:11 -07:00
|
|
|
|
|
|
|
def index
|
2022-07-19 08:28:38 -07:00
|
|
|
paginate_timeline { |args| current_user.cursored_timeline(**args) }
|
2022-07-18 07:26:11 -07:00
|
|
|
end
|
2022-07-18 13:26:13 -07:00
|
|
|
|
|
|
|
def list
|
2022-10-24 06:31:49 -07:00
|
|
|
@title = list_title(@list)
|
2022-07-19 08:28:38 -07:00
|
|
|
paginate_timeline { |args| @list.cursored_timeline(**args) }
|
2022-07-18 13:26:13 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def public
|
2022-07-19 09:41:33 -07:00
|
|
|
@title = generate_title(t(".title"))
|
2022-07-19 08:28:38 -07:00
|
|
|
paginate_timeline { |args| Answer.cursored_public_timeline(**args) }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-10-24 06:31:49 -07:00
|
|
|
def set_list
|
|
|
|
@list = current_user.lists.find_by!(name: params[:list_name]) if params[:list_name].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_lists
|
|
|
|
@lists = current_user.lists
|
|
|
|
@lists = @lists.where.not(id: @list.id) if @list.present?
|
|
|
|
end
|
|
|
|
|
2022-07-19 08:28:38 -07:00
|
|
|
def paginate_timeline
|
|
|
|
@timeline = yield(last_id: params[:last_id])
|
2022-07-18 13:26:13 -07:00
|
|
|
@timeline_last_id = @timeline.map(&:id).min
|
2022-07-19 08:28:38 -07:00
|
|
|
@more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero?
|
2022-07-18 13:26:13 -07:00
|
|
|
|
|
|
|
respond_to do |format|
|
2022-07-19 08:28:38 -07:00
|
|
|
format.html { render "timeline/timeline" }
|
2022-09-08 13:41:32 -07:00
|
|
|
format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other }
|
2022-07-18 13:26:13 -07:00
|
|
|
end
|
|
|
|
end
|
2022-07-18 07:26:11 -07:00
|
|
|
end
|