|
2 | 2 |
|
3 | 3 | namespace BookStack\Entities\Controllers; |
4 | 4 |
|
| 5 | +use BookStack\Activity\Tools\CommentTree; |
5 | 6 | use BookStack\Entities\Queries\EntityQueries; |
6 | 7 | use BookStack\Entities\Queries\PageQueries; |
7 | 8 | use BookStack\Entities\Repos\PageRepo; |
@@ -88,21 +89,32 @@ public function create(Request $request) |
88 | 89 | /** |
89 | 90 | * View the details of a single page. |
90 | 91 | * Pages will always have HTML content. They may have markdown content |
91 | | - * if the markdown editor was used to last update the page. |
| 92 | + * if the Markdown editor was used to last update the page. |
92 | 93 | * |
93 | | - * The 'html' property is the fully rendered & escaped HTML content that BookStack |
| 94 | + * The 'html' property is the fully rendered and escaped HTML content that BookStack |
94 | 95 | * would show on page view, with page includes handled. |
95 | 96 | * The 'raw_html' property is the direct database stored HTML content, which would be |
96 | 97 | * what BookStack shows on page edit. |
97 | 98 | * |
98 | 99 | * See the "Content Security" section of these docs for security considerations when using |
99 | 100 | * the page content returned from this endpoint. |
| 101 | + * |
| 102 | + * Comments for the page are provided in a tree-structure representing the hierarchy of top-level |
| 103 | + * comments and replies, for both archived and active comments. |
100 | 104 | */ |
101 | 105 | public function read(string $id) |
102 | 106 | { |
103 | 107 | $page = $this->queries->findVisibleByIdOrFail($id); |
104 | 108 |
|
105 | | - return response()->json($page->forJsonDisplay()); |
| 109 | + $page = $page->forJsonDisplay(); |
| 110 | + $commentTree = (new CommentTree($page)); |
| 111 | + $commentTree->loadVisibleHtml(); |
| 112 | + $page->setAttribute('comments', [ |
| 113 | + 'active' => $commentTree->getActive(), |
| 114 | + 'archived' => $commentTree->getArchived(), |
| 115 | + ]); |
| 116 | + |
| 117 | + return response()->json($page); |
106 | 118 | } |
107 | 119 |
|
108 | 120 | /** |
|
0 commit comments