25 lines
669 B
Ruby
25 lines
669 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Question::AnswerMethods
|
|
include CursorPaginatable
|
|
|
|
define_cursor_paginator :cursored_answers, :ordered_answers
|
|
|
|
def ordered_answers(current_user: nil)
|
|
answers
|
|
.for_user(current_user)
|
|
.includes([{ user: :profile }, :question])
|
|
.then do |query|
|
|
next query unless current_user
|
|
|
|
blocked_and_muted_user_ids = current_user.blocked_user_ids_cached + current_user.muted_user_ids_cached
|
|
next query if blocked_and_muted_user_ids.empty?
|
|
|
|
query
|
|
.where.not(answers: { user_id: blocked_and_muted_user_ids })
|
|
end
|
|
.order(:created_at)
|
|
.reverse_order
|
|
end
|
|
end
|