|
@@ -52,18 +52,19 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {Number} comment_position=-1 Line number of the comment
|
|
* @apiParam {Number} comment_position=-1 Line number of the comment
|
|
|
*/
|
|
*/
|
|
|
api.add = async function(req, res) {
|
|
api.add = async function(req, res) {
|
|
|
- const form = req.form.commentForm;
|
|
|
|
|
|
|
+ const commentForm = req.form.commentForm;
|
|
|
|
|
+ const slackNotificationForm = req.form.slackNotificationForm;
|
|
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
if (!req.form.isValid) {
|
|
|
// return res.json(ApiResponse.error('Invalid comment.'));
|
|
// return res.json(ApiResponse.error('Invalid comment.'));
|
|
|
return res.json(ApiResponse.error('コメントを入力してください。'));
|
|
return res.json(ApiResponse.error('コメントを入力してください。'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const pageId = form.page_id;
|
|
|
|
|
- const revisionId = form.revision_id;
|
|
|
|
|
- const comment = form.comment;
|
|
|
|
|
- const position = form.comment_position || -1;
|
|
|
|
|
- const isMarkdown = form.is_markdown;
|
|
|
|
|
|
|
+ const pageId = commentForm.page_id;
|
|
|
|
|
+ const revisionId = commentForm.revision_id;
|
|
|
|
|
+ const comment = commentForm.comment;
|
|
|
|
|
+ const position = commentForm.comment_position || -1;
|
|
|
|
|
+ const isMarkdown = commentForm.is_markdown;
|
|
|
|
|
|
|
|
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)
|
|
|
.catch(function(err) {
|
|
.catch(function(err) {
|
|
@@ -77,16 +78,16 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// slack notification
|
|
// slack notification
|
|
|
- // if (form.slackOn) {
|
|
|
|
|
- const slackNotify = new slack(crowi);
|
|
|
|
|
- const user = await User.findUserByUsername(req.user.username);
|
|
|
|
|
- const path = page.path;
|
|
|
|
|
- // const channels = form.channel;
|
|
|
|
|
- const channels = 'general';
|
|
|
|
|
- channels.split(',').map(function(chan) {
|
|
|
|
|
- slackNotify.postComment(createdComment, user, chan, path);
|
|
|
|
|
- });
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ if (slackNotificationForm.isNotification) {
|
|
|
|
|
+ const slackNotify = new slack(crowi);
|
|
|
|
|
+ const user = await User.findUserByUsername(req.user.username);
|
|
|
|
|
+ const path = page.path;
|
|
|
|
|
+ const channels = slackNotificationForm.notifSlackChannel;
|
|
|
|
|
+
|
|
|
|
|
+ channels.split(',').map(function(chan) {
|
|
|
|
|
+ slackNotify.postComment(createdComment, user, chan, path);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return res.json(ApiResponse.success({comment: createdComment}));
|
|
return res.json(ApiResponse.success({comment: createdComment}));
|
|
|
};
|
|
};
|