FEATURE: search your bookmarks using in:bookmarks

This commit is contained in:
Sam 2015-02-05 11:50:20 +11:00
parent eb7a5c251d
commit 16465edd88
2 changed files with 17 additions and 2 deletions

View file

@ -2228,6 +2228,7 @@ en:
<tr><td><code>status:open</code></td><td><code>status:closed</code></td><td><code>status:archived</code></td><td><code>status:noreplies</code></td><td><code>status:singleuser</code></td></tr>
<tr><td><code>category:foo</code></td><td><code>user:foo</code></td><td colspan=3></td></tr>
<tr><td><code>in:likes</code></td><td><code>in:posted</code></td><td><code>in:watching</code></td><td><code>in:tracking</code></td><td><code>in:private</code></td></tr>
<tr><td><code>in:bookmarks</code></td><td colspan=4></td></tr>
</table>
</p>
<p>

View file

@ -192,6 +192,9 @@ class Search
elsif word == 'in:private'
@search_pms = true
nil
elsif word == 'in:bookmarks'
@bookmarked_only = true
nil
else
word
end
@ -329,11 +332,15 @@ class Search
end
if @guardian.user
if @liked_only
if @liked_only || @bookmarked_only
post_action_type = PostActionType.types[:like] if @liked_only
post_action_type = PostActionType.types[:bookmark] if @bookmarked_only
posts = posts.where("posts.id IN (
SELECT pa.post_id FROM post_actions pa
WHERE pa.user_id = #{@guardian.user.id} AND
pa.post_action_type_id = #{PostActionType.types[:like]}
pa.post_action_type_id = #{post_action_type}
)")
end
@ -341,6 +348,13 @@ class Search
posts = posts.where("posts.user_id = #{@guardian.user.id}")
end
if @search_bookmarks
post_action_type = @search_likes ? PostActionType.types(:like) : PostActionType.types[:bookmark]
posts = posts.where(["posts.id IN (SELECT post_id FROM post_actions
WHERE user_id = ? AND post_action_type_id = ?)",
@guardian.user.id, post_action_type])
end
if @notification_level
posts = posts.where("posts.topic_id IN (
SELECT tu.topic_id FROM topic_users tu