mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-02 03:06:46 +08:00
### Super high level description: Adds a nested/threaded view for Discourse topics, allowing posts to be displayed as an indented reply tree instead of the default flat chronological stream. Backend: - New /n/:slug/:topic_id routes serving roots, children (paginated), and context (ancestor chain) endpoints - TreeLoader recursively fetches reply trees with configurable max depth, Sort supports top/new/old ordering - NestedViewPostStat caches per-post reply counts (direct + total descendants, whisper-aware) with a backfill job for existing data - NestedTopic model tracks per-topic opt-in and pinned post Frontend: - Recursive <NestedPost> / <NestedPostChildren> components with lazy-load expansion, cloaking, and scroll tracking - NestedViewCache service preserves expansion state and scroll position across back/forward navigation (15 entries, 10min TTL) - Context view for deep-linking to a specific post with its ancestor chain - Floating actions bar, sort selector, real-time MessageBus updates Site settings (hidden): nested_replies_enabled, nested_replies_default, nested_replies_default_sort, nested_replies_max_depth, nested_replies_cap_nesting_depth, nested_replies_toggle_mode_groups, plus a per-category default override. Co-authored-by: Rafael Silva <xfalcox@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Sérgio Saquetim <saquetim@discourse.org>
54 lines
1.8 KiB
Ruby
54 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "View as nested button" do
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
fab!(:admin)
|
|
fab!(:category)
|
|
fab!(:nested_category) { Fabricate(:category, name: "Nested Category") }
|
|
fab!(:topic) { Fabricate(:topic, user: user, category: category) }
|
|
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
|
|
fab!(:reply) { Fabricate(:post, topic: topic, user: Fabricate(:user), raw: "A reply") }
|
|
fab!(:nested_topic) { Fabricate(:topic, user: user, category: nested_category) }
|
|
fab!(:nested_op) { Fabricate(:post, topic: nested_topic, user: user, post_number: 1) }
|
|
fab!(:nested_reply) do
|
|
Fabricate(:post, topic: nested_topic, user: Fabricate(:user), raw: "A nested reply")
|
|
end
|
|
|
|
let(:nested_view) { PageObjects::Pages::NestedView.new }
|
|
|
|
before do
|
|
SiteSetting.nested_replies_enabled = true
|
|
nested_category.category_setting.update!(nested_replies_default: true)
|
|
Fabricate(:nested_topic, topic: nested_topic)
|
|
end
|
|
|
|
it "does not show the link on a normal topic" do
|
|
sign_in(admin)
|
|
page.visit("/t/#{topic.slug}/#{topic.id}")
|
|
|
|
expect(nested_view).to have_no_view_as_nested_link
|
|
end
|
|
|
|
it "shows the link on a nested topic for users in the allowed group" do
|
|
sign_in(admin)
|
|
page.visit("/t/#{nested_topic.slug}/#{nested_topic.id}?flat=1")
|
|
|
|
expect(nested_view).to have_view_as_nested_link
|
|
end
|
|
|
|
it "does not show the link for users outside the allowed group" do
|
|
sign_in(user)
|
|
page.visit("/t/#{nested_topic.slug}/#{nested_topic.id}?flat=1")
|
|
|
|
expect(nested_view).to have_no_view_as_nested_link
|
|
end
|
|
|
|
it "shows the link when topic has a nested_topic record" do
|
|
sign_in(admin)
|
|
Fabricate(:nested_topic, topic: topic)
|
|
|
|
page.visit("/t/#{topic.slug}/#{topic.id}?flat=1")
|
|
|
|
expect(nested_view).to have_view_as_nested_link
|
|
end
|
|
end
|