mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
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:
parent
3ea8df4b06
commit
ddec7bf6a3
|
@ -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),
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user