retrospring/app/controllers/concerns/paginates_answers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

13 lines
493 B
Ruby
Raw Normal View History

2023-02-17 00:35:03 +01:00
# frozen_string_literal: true
module PaginatesAnswers
def paginate_answers
@answers = yield(last_id: params[:last_id])
2023-02-17 00:35:03 +01:00
answer_ids = @answers.map(&:id)
@answers_last_id = answer_ids.min
answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present?
@more_data_available = !yield(last_id: @answers_last_id, size: 1).count.zero?
2023-03-19 16:00:15 +01:00
@subscribed_answer_ids = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in?
2023-02-17 00:35:03 +01:00
end
end