|
@@ -1,5 +1,7 @@
|
|
|
|
|
+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 Crowi from '../crowi';
|
|
import Crowi from '../crowi';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:service:CommentService');
|
|
const logger = loggerFactory('growi:service:CommentService');
|
|
@@ -9,12 +11,18 @@ class CommentService {
|
|
|
|
|
|
|
|
crowi!: Crowi;
|
|
crowi!: Crowi;
|
|
|
|
|
|
|
|
|
|
+ inAppNotificationService!: any;
|
|
|
|
|
+
|
|
|
commentEvent!: any;
|
|
commentEvent!: any;
|
|
|
|
|
|
|
|
|
|
+ activityEvent!: any;
|
|
|
|
|
+
|
|
|
constructor(crowi: Crowi) {
|
|
constructor(crowi: Crowi) {
|
|
|
this.crowi = crowi;
|
|
this.crowi = crowi;
|
|
|
|
|
+ this.inAppNotificationService = crowi.inAppNotificationService;
|
|
|
|
|
|
|
|
this.commentEvent = crowi.event('comment');
|
|
this.commentEvent = crowi.event('comment');
|
|
|
|
|
+ this.activityEvent = crowi.event('activity');
|
|
|
|
|
|
|
|
// init
|
|
// init
|
|
|
this.initCommentEvent();
|
|
this.initCommentEvent();
|
|
@@ -30,9 +38,12 @@ class CommentService {
|
|
|
await Page.updateCommentCount(savedComment.page);
|
|
await Page.updateCommentCount(savedComment.page);
|
|
|
|
|
|
|
|
const Activity = getModelSafely('Activity') || require('../models/activity')(this.crowi);
|
|
const Activity = getModelSafely('Activity') || require('../models/activity')(this.crowi);
|
|
|
- const activityLog = await Activity.createByPageComment(savedComment);
|
|
|
|
|
|
|
+ const savedActivity = await Activity.createByPageComment(savedComment);
|
|
|
|
|
+
|
|
|
|
|
+ let targetUsers: Types.ObjectId[] = [];
|
|
|
|
|
+ targetUsers = await savedActivity.getNotificationTargetUsers();
|
|
|
|
|
|
|
|
- logger.info('Activity created', activityLog);
|
|
|
|
|
|
|
+ await this.inAppNotificationService.upsertByActivity(targetUsers, savedActivity);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error('Error occurred while handling the comment create event:\n', err);
|
|
logger.error('Error occurred while handling the comment create event:\n', err);
|