From 16465edd8859c94dedf2da38f07d6afc46def712 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Feb 2015 11:50:20 +1100 Subject: [PATCH] FEATURE: search your bookmarks using in:bookmarks --- config/locales/server.en.yml | 1 + lib/search.rb | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 7d8575f5f..eb4809ced 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2228,6 +2228,7 @@ en: status:openstatus:closedstatus:archivedstatus:norepliesstatus:singleuser category:foouser:foo in:likesin:postedin:watchingin:trackingin:private + in:bookmarks

diff --git a/lib/search.rb b/lib/search.rb index 31b0f270f..3b9500f96 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -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