From 17ebfd17158d9254cd58ad5ad331cb163aa3d359 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 23 Jan 2018 12:05:44 -0500 Subject: [PATCH] FIX: Don't show suggested messages if private messages are disabled --- lib/topic_query.rb | 6 +++++- spec/components/topic_query_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 2d27044739b..1556e085fc6 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -100,7 +100,11 @@ class TopicQuery # Return a list of suggested topics for a topic def list_suggested_for(topic) - return if topic.private_message? && !@user + + # Don't suggest messages unless we have a user, and private messages are + # enabled. + return if topic.private_message? && + (@user.blank? || !SiteSetting.enable_private_messages?) builder = SuggestedTopicsBuilder.new(topic) diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index be119f53099..4ca84492b35 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -695,6 +695,10 @@ describe TopicQuery do expect(TopicQuery.new(user).list_suggested_for(pm_to_user).topics.map(&:id)).to( eq([new_pm.id, unread_pm.id, related_by_user_pm.id]) ) + + SiteSetting.enable_private_messages = false + expect(TopicQuery.new(user).list_suggested_for(pm_to_group)).to be_blank + expect(TopicQuery.new(user).list_suggested_for(pm_to_user)).to be_blank end end