]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/CommentController.php
#47 - Gets rid of simplemde
[bookstack] / app / Http / Controllers / CommentController.php
index 3df4417668bca6cc84ba863893d2aab2c3e8ba11..8e7b1512aa07230a5672fac993605a088c45eacb 100644 (file)
@@ -17,7 +17,7 @@ class CommentController extends Controller
         parent::__construct();
     }
 
-    public function save(Request $request, $pageId, $commentId)
+    public function save(Request $request, $pageId, $commentId = null)
     {
         $this->validate($request, [
             'text' => 'required|string',
@@ -85,7 +85,11 @@ class CommentController extends Controller
         $this->checkOwnablePermission('page-view', $page);
         
         $comments = $this->commentRepo->getCommentsForPage($pageId, $commentId);
-        
+        if (empty($commentId)) {
+            // requesting for parent level comments, send the total count as well.
+            $totalComments = $this->commentRepo->getCommentCount($pageId);
+            return response()->json(array('success' => true, 'comments'=> $comments, 'total' => $totalComments));
+        }
         return response()->json(array('success' => true, 'comments'=> $comments));
     }
 }