2020-04-20 14:03:57 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module User::TimelineMethods
|
|
|
|
include CursorPaginatable
|
|
|
|
|
|
|
|
define_cursor_paginator :cursored_timeline, :timeline
|
|
|
|
|
2023-01-28 12:17:08 -08:00
|
|
|
# @return [ActiveRecord::Relation<Answer>] the user's timeline
|
2020-04-20 14:03:57 -07:00
|
|
|
def timeline
|
2023-01-28 12:17:08 -08:00
|
|
|
Answer
|
2023-11-26 10:32:50 -08:00
|
|
|
.for_user(self)
|
2023-02-20 12:06:10 -08:00
|
|
|
.then do |query|
|
|
|
|
blocked_and_muted_user_ids = blocked_user_ids_cached + muted_user_ids_cached
|
|
|
|
next query if blocked_and_muted_user_ids.empty?
|
|
|
|
|
|
|
|
# build a more complex query if we block or mute someone
|
|
|
|
# otherwise the query ends up as "anon OR (NOT anon AND user_id NOT IN (NULL))" which will only return anonymous questions
|
|
|
|
query
|
|
|
|
.joins(:question)
|
|
|
|
.where("questions.author_is_anonymous OR (NOT questions.author_is_anonymous AND questions.user_id NOT IN (?))", blocked_and_muted_user_ids)
|
|
|
|
end
|
|
|
|
.where("answers.user_id in (?) OR answers.user_id = ?", following_ids, id)
|
2023-01-28 12:17:08 -08:00
|
|
|
.order(:created_at)
|
|
|
|
.reverse_order
|
2023-10-22 12:51:21 -07:00
|
|
|
.includes(question: { user: [:profile] }, user: [:profile])
|
2020-04-20 14:03:57 -07:00
|
|
|
end
|
|
|
|
end
|