From 4be8de21a17a088946085b162c8ab4a652e9879a Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 15 Dec 2015 13:26:35 +1100 Subject: [PATCH] FIX: not searching group messages when searching private --- lib/search.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/search.rb b/lib/search.rb index 31d2b1cef5a..a7c5c12121f 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -442,7 +442,15 @@ class Search if @search_context.is_a?(User) if opts[:private_messages] - posts = posts.where("topics.id IN (SELECT topic_id FROM topic_allowed_users WHERE user_id = ?)", @search_context.id) + posts = posts.where("topics.id IN (SELECT topic_id + FROM topic_allowed_users + WHERE user_id = :user_id + UNION ALL + SELECT tg.topic_id + FROM topic_allowed_groups tg + JOIN group_users gu ON gu.user_id = :user_id AND + gu.group_id = tg.group_id)", + user_id: @search_context.id) else posts = posts.where("posts.user_id = #{@search_context.id}") end