shinoka7 6 лет назад
Родитель
Сommit
abcbf9297e
3 измененных файлов с 12 добавлено и 6 удалено
  1. 0 6
      src/client/js/components/PageComments.jsx
  2. 11 0
      src/server/models/comment.js
  3. 1 0
      src/server/routes/comment.js

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

@@ -74,12 +74,6 @@ class PageComments extends React.Component {
 
 
   deleteComment() {
   deleteComment() {
     const comment = this.state.commentToDelete;
     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)
     this.props.commentContainer.deleteComment(comment)
       .then(() => {
       .then(() => {

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

@@ -78,6 +78,17 @@ module.exports = function(crowi) {
     }));
     }));
   };
   };
 
 
+  commentSchema.statics.removeRepliesByCommentId = function(commentId) {
+    return new Promise(((resolve, reject) => {
+      this.remove({ replyTo: commentId }, (err, done) => {
+        if (err) {
+          return reject(err);
+        }
+        resolve(done);
+      });
+    }));
+  };
+
   /**
   /**
    * post save hook
    * post save hook
    */
    */

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

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