|
@@ -1,7 +1,7 @@
|
|
|
import { Types } from 'mongoose';
|
|
import { Types } from 'mongoose';
|
|
|
import loggerFactory from '../../utils/logger';
|
|
import loggerFactory from '../../utils/logger';
|
|
|
import { getModelSafely } from '../util/mongoose-utils';
|
|
import { getModelSafely } from '../util/mongoose-utils';
|
|
|
-import { ActivityDocument } from '../models/activity';
|
|
|
|
|
|
|
+import ActivityDefine from '../util/activityDefine';
|
|
|
import Crowi from '../crowi';
|
|
import Crowi from '../crowi';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:service:CommentService');
|
|
const logger = loggerFactory('growi:service:CommentService');
|
|
@@ -32,13 +32,12 @@ class CommentService {
|
|
|
initCommentEventListeners(): void {
|
|
initCommentEventListeners(): void {
|
|
|
// create
|
|
// create
|
|
|
this.commentEvent.on('create', async(savedComment) => {
|
|
this.commentEvent.on('create', async(savedComment) => {
|
|
|
- const { activityService } = this.crowi;
|
|
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
|
|
const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
|
|
|
await Page.updateCommentCount(savedComment.page);
|
|
await Page.updateCommentCount(savedComment.page);
|
|
|
|
|
|
|
|
- const savedActivity = await activityService.createByPageComment(savedComment);
|
|
|
|
|
|
|
+ const savedActivity = await this.createByPageComment(savedComment);
|
|
|
|
|
|
|
|
let targetUsers: Types.ObjectId[] = [];
|
|
let targetUsers: Types.ObjectId[] = [];
|
|
|
targetUsers = await savedActivity.getNotificationTargetUsers();
|
|
targetUsers = await savedActivity.getNotificationTargetUsers();
|
|
@@ -73,6 +72,27 @@ class CommentService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param {Comment} comment
|
|
|
|
|
+ * @return {Promise}
|
|
|
|
|
+ */
|
|
|
|
|
+ createByPageComment = function(comment) {
|
|
|
|
|
+ const { activityService } = this.crowi;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ user: comment.creator,
|
|
|
|
|
+ targetModel: ActivityDefine.MODEL_PAGE,
|
|
|
|
|
+ target: comment.page,
|
|
|
|
|
+ eventModel: ActivityDefine.MODEL_COMMENT,
|
|
|
|
|
+ event: comment._id,
|
|
|
|
|
+ action: ActivityDefine.ACTION_COMMENT,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return activityService.createByParameters(parameters);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = CommentService;
|
|
module.exports = CommentService;
|