33namespace BookStack \Activity \Controllers ;
44
55use BookStack \Activity \CommentRepo ;
6+ use BookStack \Activity \Tools \CommentTree ;
7+ use BookStack \Activity \Tools \CommentTreeNode ;
68use BookStack \Entities \Queries \PageQueries ;
79use BookStack \Http \Controller ;
810use Illuminate \Http \Request ;
@@ -26,6 +28,7 @@ public function savePageComment(Request $request, int $pageId)
2628 $ input = $ this ->validate ($ request , [
2729 'html ' => ['required ' , 'string ' ],
2830 'parent_id ' => ['nullable ' , 'integer ' ],
31+ 'content_ref ' => ['string ' ],
2932 ]);
3033
3134 $ page = $ this ->pageQueries ->findVisibleById ($ pageId );
@@ -40,14 +43,12 @@ public function savePageComment(Request $request, int $pageId)
4043
4144 // Create a new comment.
4245 $ this ->checkPermission ('comment-create-all ' );
43- $ comment = $ this ->commentRepo ->create ($ page , $ input ['html ' ], $ input ['parent_id ' ] ?? null );
46+ $ contentRef = $ input ['content_ref ' ] ?? '' ;
47+ $ comment = $ this ->commentRepo ->create ($ page , $ input ['html ' ], $ input ['parent_id ' ] ?? null , $ contentRef );
4448
4549 return view ('comments.comment-branch ' , [
4650 'readOnly ' => false ,
47- 'branch ' => [
48- 'comment ' => $ comment ,
49- 'children ' => [],
50- ]
51+ 'branch ' => new CommentTreeNode ($ comment , 0 , []),
5152 ]);
5253 }
5354
@@ -74,6 +75,46 @@ public function update(Request $request, int $commentId)
7475 ]);
7576 }
7677
78+ /**
79+ * Mark a comment as archived.
80+ */
81+ public function archive (int $ id )
82+ {
83+ $ comment = $ this ->commentRepo ->getById ($ id );
84+ $ this ->checkOwnablePermission ('page-view ' , $ comment ->entity );
85+ if (!userCan ('comment-update ' , $ comment ) && !userCan ('comment-delete ' , $ comment )) {
86+ $ this ->showPermissionError ();
87+ }
88+
89+ $ this ->commentRepo ->archive ($ comment );
90+
91+ $ tree = new CommentTree ($ comment ->entity );
92+ return view ('comments.comment-branch ' , [
93+ 'readOnly ' => false ,
94+ 'branch ' => $ tree ->getCommentNodeForId ($ id ),
95+ ]);
96+ }
97+
98+ /**
99+ * Unmark a comment as archived.
100+ */
101+ public function unarchive (int $ id )
102+ {
103+ $ comment = $ this ->commentRepo ->getById ($ id );
104+ $ this ->checkOwnablePermission ('page-view ' , $ comment ->entity );
105+ if (!userCan ('comment-update ' , $ comment ) && !userCan ('comment-delete ' , $ comment )) {
106+ $ this ->showPermissionError ();
107+ }
108+
109+ $ this ->commentRepo ->unarchive ($ comment );
110+
111+ $ tree = new CommentTree ($ comment ->entity );
112+ return view ('comments.comment-branch ' , [
113+ 'readOnly ' => false ,
114+ 'branch ' => $ tree ->getCommentNodeForId ($ id ),
115+ ]);
116+ }
117+
77118 /**
78119 * Delete a comment from the system.
79120 */
0 commit comments