mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-02 15:52:21 +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>
39 lines
936 B
Ruby
39 lines
936 B
Ruby
# frozen_string_literal: true
|
|
|
|
class NestedTopic < ActiveRecord::Base
|
|
self.ignored_columns = ["pinned_post_number"]
|
|
|
|
MAX_PINNED_POSTS = 10
|
|
|
|
belongs_to :topic, -> { with_deleted }
|
|
|
|
validates :topic_id, presence: true, uniqueness: true
|
|
|
|
def pin_limit_reached?
|
|
pinned_post_ids.length >= MAX_PINNED_POSTS
|
|
end
|
|
|
|
def toggle_pin(post_id)
|
|
if pinned_post_ids.include?(post_id)
|
|
self.pinned_post_ids = pinned_post_ids - [post_id]
|
|
else
|
|
self.pinned_post_ids = pinned_post_ids + [post_id]
|
|
end
|
|
save!
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: nested_topics
|
|
#
|
|
# id :bigint not null, primary key
|
|
# pinned_post_ids :bigint default([]), not null, is an Array
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# topic_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_nested_topics_on_topic_id (topic_id) UNIQUE
|
|
#
|