A platform for community discussion. Free, open, simple.
DEV: allow API for list_suggested_for to exclude random (#20857)
Samddec7bf6a378
diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 2d93e743925..5dace8bb8a1 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -204,7 +204,8 @@ class TopicQueryend# Return a list of suggested topics for a topic- def list_suggested_for(topic, pm_params: nil)+ # The include_random param was added so plugins can generate a suggested topics list without the random topics+ def list_suggested_for(topic, pm_params: nil, include_random: true)# Don't suggest messages unless we have a user, and private messages are# enabled.if topic.private_message? &&@@ -250,7 +251,7 @@ class TopicQueryendif !topic.private_message?- unless builder.full?+ if include_random && !builder.full?builder.add_results(random_suggested(topic, builder.results_left, builder.excluded_topic_ids),)diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rbindex 8ca8ce492ef..547b16de737 100644--- a/spec/lib/topic_query_spec.rb+++ b/spec/lib/topic_query_spec.rb@@ -1379,6 +1379,10 @@ RSpec.describe TopicQuery doit "should return the new topic" doexpect(TopicQuery.new.list_suggested_for(topic).topics).to eq([new_topic])end++ it "should return the nothing when random topics excluded" do+ expect(TopicQuery.new.list_suggested_for(topic, include_random: false).topics).to eq([])+ endendcontext "when anonymously browsing with invisible, closed and archived" do