支持评论级联软删与后台回收站,并完善 Markdown 代码围栏嵌套。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-06 17:49:05 +08:00
parent e6e7ed73e3
commit bb8d415eb7
13 changed files with 479 additions and 28 deletions

View File

@@ -22,6 +22,22 @@ export function isGuestComment(c: Comment): boolean {
return !c.user_id || c.user_id === 0;
}
/** 收集评论及其 reply_to 后代的 ID含自身 */
export function collectCommentSubtreeIds(comments: Comment[], rootId: number): Set<number> {
const ids = new Set<number>([rootId]);
let changed = true;
while (changed) {
changed = false;
for (const c of comments) {
if (!ids.has(c.id) && c.reply_to != null && ids.has(c.reply_to)) {
ids.add(c.id);
changed = true;
}
}
}
return ids;
}
/** 构建嵌套评论树(优先 thread_parent_id回退 reply_to */
export function buildCommentTree(comments: Comment[]): CommentNode[] {
const map = new Map<number, CommentNode>();