mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 09:11:11 +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>
65 lines
2.2 KiB
Ruby
65 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CategorySetting < ActiveRecord::Base
|
|
# TODO: drop columns require_topic_approval, require_reply_approval in a future migration
|
|
self.ignored_columns += %i[require_topic_approval require_reply_approval]
|
|
|
|
belongs_to :category
|
|
|
|
enum :topic_posting_review_mode,
|
|
{ no_one: 0, everyone: 1, everyone_except: 2, no_one_except: 3 },
|
|
prefix: true
|
|
enum :reply_posting_review_mode,
|
|
{ no_one: 0, everyone: 1, everyone_except: 2, no_one_except: 3 },
|
|
prefix: true
|
|
|
|
def require_topic_approval=(value)
|
|
self.topic_posting_review_mode =
|
|
ActiveModel::Type::Boolean.new.cast(value) ? :everyone : :no_one
|
|
end
|
|
|
|
def require_reply_approval=(value)
|
|
self.reply_posting_review_mode =
|
|
ActiveModel::Type::Boolean.new.cast(value) ? :everyone : :no_one
|
|
end
|
|
|
|
alias_method :require_topic_approval, :topic_posting_review_mode_everyone?
|
|
alias_method :require_topic_approval?, :topic_posting_review_mode_everyone?
|
|
alias_method :require_reply_approval, :reply_posting_review_mode_everyone?
|
|
alias_method :require_reply_approval?, :reply_posting_review_mode_everyone?
|
|
|
|
GROUP_BASED_MODES = %w[everyone_except no_one_except].freeze
|
|
|
|
validates :num_auto_bump_daily,
|
|
numericality: {
|
|
only_integer: true,
|
|
greater_than_or_equal_to: 0,
|
|
allow_nil: true,
|
|
}
|
|
|
|
validates :auto_bump_cooldown_days,
|
|
numericality: {
|
|
only_integer: true,
|
|
greater_than_or_equal_to: 0,
|
|
allow_nil: true,
|
|
}
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: category_settings
|
|
#
|
|
# id :bigint not null, primary key
|
|
# auto_bump_cooldown_days :integer default(1)
|
|
# nested_replies_default :boolean default(FALSE), not null
|
|
# num_auto_bump_daily :integer default(0)
|
|
# reply_posting_review_mode :integer default("no_one"), not null
|
|
# topic_posting_review_mode :integer default("no_one"), not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# category_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_category_settings_on_category_id (category_id) UNIQUE
|
|
#
|