mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-03 22:38:10 +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>
76 lines
2 KiB
Ruby
76 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Nested view cloaking" do
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
fab!(:topic) { Fabricate(:topic, user: user) }
|
|
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
|
|
|
|
let(:nested_view) { PageObjects::Pages::NestedView.new }
|
|
|
|
before do
|
|
SiteSetting.nested_replies_enabled = true
|
|
sign_in(user)
|
|
end
|
|
|
|
context "with many root posts" do
|
|
before do
|
|
20.times do |i|
|
|
root =
|
|
Fabricate(
|
|
:post,
|
|
topic: topic,
|
|
user: Fabricate(:user),
|
|
raw: "Root post number #{i + 1} with enough content to take up space",
|
|
)
|
|
Fabricate(
|
|
:post,
|
|
topic: topic,
|
|
user: Fabricate(:user),
|
|
raw: "Child reply to root #{i + 1}",
|
|
reply_to_post_number: root.post_number,
|
|
)
|
|
end
|
|
end
|
|
|
|
it "cloaks root subtrees far from the viewport" do
|
|
nested_view.visit_nested(topic)
|
|
expect(nested_view).to have_nested_view
|
|
|
|
expect(nested_view).to have_cloaked_root
|
|
|
|
expect(page).to have_no_css(
|
|
".nested-view__roots > .nested-post:first-child.nested-post--cloaked",
|
|
)
|
|
end
|
|
|
|
it "uncloaks roots when scrolling to them" do
|
|
nested_view.visit_nested(topic)
|
|
expect(nested_view).to have_nested_view
|
|
|
|
send_keys(:end)
|
|
|
|
expect(page).to have_css(
|
|
".nested-view__roots > .nested-post:first-child.nested-post--cloaked",
|
|
wait: 5,
|
|
)
|
|
|
|
send_keys(:home)
|
|
|
|
expect(page).to have_no_css(
|
|
".nested-view__roots > .nested-post:first-child.nested-post--cloaked",
|
|
)
|
|
end
|
|
|
|
it "hides children content when root is cloaked" do
|
|
nested_view.visit_nested(topic)
|
|
expect(nested_view).to have_nested_view
|
|
|
|
expect(page).to have_no_css(
|
|
".nested-view__roots > .nested-post--cloaked .nested-post__article",
|
|
)
|
|
expect(page).to have_no_css(
|
|
".nested-view__roots > .nested-post--cloaked .nested-post-children",
|
|
)
|
|
end
|
|
end
|
|
end
|