mirror of
https://github.com/discourse/discourse.git
synced 2025-03-07 19:59:33 +00: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
|
end
|
||||||
|
|
||||||
# Return a list of suggested topics for a topic
|
# 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
|
# Don't suggest messages unless we have a user, and private messages are
|
||||||
# enabled.
|
# enabled.
|
||||||
if topic.private_message? &&
|
if topic.private_message? &&
|
||||||
@ -250,7 +251,7 @@ class TopicQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
if !topic.private_message?
|
if !topic.private_message?
|
||||||
unless builder.full?
|
if include_random && !builder.full?
|
||||||
builder.add_results(
|
builder.add_results(
|
||||||
random_suggested(topic, builder.results_left, builder.excluded_topic_ids),
|
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
|
it "should return the new topic" do
|
||||||
expect(TopicQuery.new.list_suggested_for(topic).topics).to eq([new_topic])
|
expect(TopicQuery.new.list_suggested_for(topic).topics).to eq([new_topic])
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when anonymously browsing with invisible, closed and archived" do
|
context "when anonymously browsing with invisible, closed and archived" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user