2020-04-20 14:03:57 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Question::AnswerMethods
|
|
|
|
include CursorPaginatable
|
|
|
|
|
|
|
|
define_cursor_paginator :cursored_answers, :ordered_answers
|
|
|
|
|
2023-02-21 01:12:13 -08:00
|
|
|
def ordered_answers(current_user: nil)
|
2020-04-20 14:03:57 -07:00
|
|
|
answers
|
2023-11-26 10:32:50 -08:00
|
|
|
.for_user(current_user)
|
2023-10-22 10:51:23 -07:00
|
|
|
.includes([{ user: :profile }, :question])
|
2023-02-21 01:12:13 -08:00
|
|
|
.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
|
2020-04-20 14:03:57 -07:00
|
|
|
.order(:created_at)
|
|
|
|
.reverse_order
|
|
|
|
end
|
|
|
|
end
|