FIX: Suggested topic links to nested replies topics (#40302)

Fixes bug reported here ->
https://meta.discourse.org/t/link-to-nested-topic-in-my-suggested-topics-doesnt-work/403743?u=markvanlan
This commit is contained in:
Mark VanLandingham
2026-05-26 08:40:38 -05:00
committed by GitHub
parent ad459f7806
commit 0a9ac164bd
3 changed files with 29 additions and 0 deletions
@@ -16,6 +16,7 @@ class SuggestedTopicSerializer < ListableTopicSerializer
:category_id,
:featured_link,
:featured_link_root_domain,
:is_nested_view,
:op_like_count
has_many :posters, serializer: SuggestedPosterSerializer, embed: :objects
@@ -38,4 +39,12 @@ class SuggestedTopicSerializer < ListableTopicSerializer
def include_featured_link_root_domain?
SiteSetting.topic_featured_link_enabled && object.featured_link
end
def is_nested_view
true
end
def include_is_nested_view?
object.nested_view?
end
end
+1
View File
@@ -22,6 +22,7 @@ class SuggestedTopicsBuilder
results = results.where(category_id: @category_id)
end
results = results.includes(:nested_topic) if SiteSetting.nested_replies_enabled
results = results.to_a
results.reject! { |topic| @category_topic_ids.include?(topic.id) }
@@ -77,4 +77,23 @@ RSpec.describe SuggestedTopicSerializer do
expect(json[:op_like_count]).to eq(5)
end
end
describe "#is_nested_view" do
before { SiteSetting.nested_replies_enabled = true }
it "returns true when the topic uses nested replies" do
topic = Fabricate(:topic)
Fabricate(:nested_topic, topic: topic)
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
expect(json[:is_nested_view]).to eq(true)
end
it "omits the attribute when the topic uses the flat view" do
topic = Fabricate(:topic)
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
expect(json).not_to have_key(:is_nested_view)
end
end
end