|
@@ -48,7 +48,10 @@ module.exports = function(crowi, app) {
|
|
|
const Page = crowi.model('Page');
|
|
const Page = crowi.model('Page');
|
|
|
const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
|
|
const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
|
|
|
const ApiResponse = require('../util/apiResponse');
|
|
const ApiResponse = require('../util/apiResponse');
|
|
|
|
|
+
|
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
|
|
|
+ const userNotificationService = crowi.getUserNotificationService();
|
|
|
|
|
+
|
|
|
const { body } = require('express-validator');
|
|
const { body } = require('express-validator');
|
|
|
const mongoose = require('mongoose');
|
|
const mongoose = require('mongoose');
|
|
|
const ObjectId = mongoose.Types.ObjectId;
|
|
const ObjectId = mongoose.Types.ObjectId;
|
|
@@ -253,8 +256,6 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
res.json(ApiResponse.success({ comment: createdComment }));
|
|
res.json(ApiResponse.success({ comment: createdComment }));
|
|
|
|
|
|
|
|
- const path = page.path;
|
|
|
|
|
-
|
|
|
|
|
// global notification
|
|
// global notification
|
|
|
try {
|
|
try {
|
|
|
await globalNotificationService.fire(GlobalNotificationSetting.EVENT.COMMENT, page, req.user, {
|
|
await globalNotificationService.fire(GlobalNotificationSetting.EVENT.COMMENT, page, req.user, {
|
|
@@ -265,26 +266,21 @@ module.exports = function(crowi, app) {
|
|
|
logger.error('Comment notification failed', err);
|
|
logger.error('Comment notification failed', err);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// slack notification
|
|
// slack notification
|
|
|
if (slackNotificationForm.isSlackEnabled) {
|
|
if (slackNotificationForm.isSlackEnabled) {
|
|
|
- const user = await User.findUserByUsername(req.user.username);
|
|
|
|
|
- const channelsStr = slackNotificationForm.slackChannels || null;
|
|
|
|
|
-
|
|
|
|
|
- page.updateSlackChannels(channelsStr).catch((err) => {
|
|
|
|
|
- logger.error('Error occured in updating slack channels: ', err);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const channels = channelsStr != null ? channelsStr.split(',') : [null];
|
|
|
|
|
-
|
|
|
|
|
- const promises = channels.map((chan) => {
|
|
|
|
|
- return crowi.slack.postComment(createdComment, user, chan, path);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- Promise.all(promises)
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- logger.error('Error occured in sending slack notification: ', err);
|
|
|
|
|
|
|
+ const { slackChannels } = slackNotificationForm;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const results = await userNotificationService.fire(page, req.user, slackChannels, 'comment', {}, createdComment);
|
|
|
|
|
+ results.forEach((result) => {
|
|
|
|
|
+ if (result.status === 'rejected') {
|
|
|
|
|
+ logger.error('Create user notification failed', result.reason);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error('Create user notification failed', err);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|