FEATURE: add ?bookmarked=true for topic lists
This commit is contained in:
parent
efc717c14a
commit
95f9788a77
|
@ -260,6 +260,7 @@ class ListController < ApplicationController
|
|||
min_posts: params[:min_posts],
|
||||
max_posts: params[:max_posts],
|
||||
status: params[:status],
|
||||
bookmarked: params[:bookmarked].present?,
|
||||
state: params[:state],
|
||||
search: params[:search]
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class TopicQuery
|
|||
state
|
||||
search
|
||||
slow_platform
|
||||
bookmarked
|
||||
).map(&:to_sym)
|
||||
|
||||
# Maps `order` to a columns in `topics`
|
||||
|
@ -310,6 +311,18 @@ class TopicQuery
|
|||
end
|
||||
end
|
||||
|
||||
if options[:bookmarked] && @user
|
||||
result = result.where('topics.id IN (SELECT pp.topic_id
|
||||
FROM post_actions pa
|
||||
JOIN posts pp ON pp.id = pa.post_id
|
||||
WHERE pa.user_id = :user_id AND
|
||||
pa.post_action_type_id = :bookmarked AND
|
||||
pa.deleted_at IS NULL
|
||||
)', user_id: @user.id,
|
||||
bookmarked: PostActionType.types[:bookmark]
|
||||
)
|
||||
end
|
||||
|
||||
result = result.where('topics.deleted_at IS NULL') if require_deleted_clause
|
||||
result = result.where('topics.posts_count <= ?', options[:max_posts]) if options[:max_posts].present?
|
||||
result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_posts].present?
|
||||
|
|
Loading…
Reference in New Issue