瀏覽代碼

Merge pull request #960 from weseek/feat/thread_comments_backend

changes
Yuki Takei 6 年之前
父節點
當前提交
9b92e3ccbe

+ 2 - 0
src/client/js/components/PageComment/CommentForm.jsx

@@ -113,6 +113,7 @@ export default class CommentForm extends React.Component {
         page_id: this.props.pageId,
         revision_id: this.props.revisionId,
         is_markdown: this.state.isMarkdown,
+        replyTo: this.props.replyTo,
       },
       slackNotificationForm: {
         isSlackEnabled: this.state.isSlackEnabled,
@@ -375,6 +376,7 @@ CommentForm.propTypes = {
   pagePath: PropTypes.string,
   editorOptions: PropTypes.object,
   slackChannels: PropTypes.string,
+  replyTo: PropTypes.string,
 };
 CommentForm.defaultProps = {
   editorOptions: {},

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

@@ -8,6 +8,7 @@ module.exports = form(
   field('commentForm.comment').trim().required(),
   field('commentForm.comment_position').trim().toInt(),
   field('commentForm.is_markdown').trim().toBooleanStrict(),
+  field('commentForm.replyTo').trim(),
 
   field('slackNotificationForm.isSlackEnabled').trim().toBooleanStrict().required(),
   field('slackNotificationForm.slackChannels').trim(),

+ 3 - 3
src/server/models/comment.js

@@ -14,10 +14,10 @@ module.exports = function(crowi) {
     commentPosition: { type: Number, default: -1 },
     createdAt: { type: Date, default: Date.now },
     isMarkdown: { type: Boolean, default: false },
-    // replyTo: { type: ObjectId, default: null },
+    replyTo: { type: ObjectId, default: undefined },
   });
 
-  commentSchema.statics.create = function(pageId, creatorId, revisionId, comment, position, isMarkdown /* , replyTo */) {
+  commentSchema.statics.create = function(pageId, creatorId, revisionId, comment, position, isMarkdown, replyTo) {
     const Comment = this;
 
     return new Promise(((resolve, reject) => {
@@ -29,7 +29,7 @@ module.exports = function(crowi) {
       newComment.comment = comment;
       newComment.commentPosition = position;
       newComment.isMarkdown = isMarkdown || false;
-      // newComment.replyTo = replyTo || null;
+      newComment.replyTo = replyTo;
 
       newComment.save((err, data) => {
         if (err) {

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

@@ -74,6 +74,7 @@ module.exports = function(crowi, app) {
     const comment = commentForm.comment;
     const position = commentForm.comment_position || -1;
     const isMarkdown = commentForm.is_markdown;
+    const replyTo = commentForm.replyTo === '' ? undefined : commentForm.replyTo;
 
     // check whether accessible
     const isAccessible = await Page.isAccessiblePageByViewer(pageId, req.user);
@@ -81,7 +82,7 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error('Current user is not accessible to this page.'));
     }
 
-    const createdComment = await Comment.create(pageId, req.user._id, revisionId, comment, position, isMarkdown)
+    const createdComment = await Comment.create(pageId, req.user._id, revisionId, comment, position, isMarkdown, replyTo)
       .catch((err) => {
         return res.json(ApiResponse.error(err));
       });