DEV: allow API for list_suggested_for to exclude random (#20857)

This is needed so plugins can potentially create lists without random topics
This commit is contained in:
Sam 2023-03-28 15:52:17 +11:00 committed by GitHub
parent 3ea8df4b06
commit ddec7bf6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -204,7 +204,8 @@ class TopicQuery
end
# 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 TopicQuery
end
if !topic.private_message?
unless builder.full?
if include_random && !builder.full?
builder.add_results(
random_suggested(topic, builder.results_left, builder.excluded_topic_ids),
)

View File

@ -1379,6 +1379,10 @@ RSpec.describe TopicQuery do
it "should return the new topic" do
expect(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([])
end
end
context "when anonymously browsing with invisible, closed and archived" do