Просмотр исходного кода

Merge pull request #1008 from weseek/feat/thread_comments_killchildrencomments

server side deletion
Yuki Takei 6 лет назад
Родитель
Сommit
478fa555e3

+ 0 - 6
src/client/js/components/PageComments.jsx

@@ -74,12 +74,6 @@ class PageComments extends React.Component {
 
   deleteComment() {
     const comment = this.state.commentToDelete;
-    const comments = this.props.commentContainer.state.comments;
-    comments.forEach((reply) => {
-      if (reply.replyTo === comment._id) {
-        this.props.commentContainer.deleteComment(reply);
-      }
-    });
 
     this.props.commentContainer.deleteComment(comment)
       .then(() => {

+ 8 - 0
src/server/models/comment.js

@@ -78,6 +78,14 @@ module.exports = function(crowi) {
     }));
   };
 
+  commentSchema.methods.removeWithReplies = async function() {
+    const Comment = crowi.model('Comment');
+    return Comment.remove({
+      $or: (
+        [{ replyTo: this._id }, { _id: this._id }]),
+    });
+  };
+
   /**
    * post save hook
    */

+ 1 - 1
src/server/routes/comment.js

@@ -174,7 +174,7 @@ module.exports = function(crowi, app) {
         throw new Error('Current user is not accessible to this page.');
       }
 
-      await comment.remove();
+      await comment.removeWithReplies();
       await Page.updateCommentCount(comment.page);
     }
     catch (err) {