|
|
@@ -6,7 +6,6 @@ import Crowi from '../crowi';
|
|
|
|
|
|
const logger = loggerFactory('growi:service:CommentService');
|
|
|
|
|
|
-
|
|
|
class CommentService {
|
|
|
|
|
|
crowi!: Crowi;
|
|
|
@@ -28,7 +27,6 @@ class CommentService {
|
|
|
this.initCommentEventListeners();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
initCommentEventListeners(): void {
|
|
|
// create
|
|
|
this.commentEvent.on('create', async(savedComment) => {
|
|
|
@@ -37,7 +35,8 @@ class CommentService {
|
|
|
const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
|
|
|
await Page.updateCommentCount(savedComment.page);
|
|
|
|
|
|
- await this.createAndSendNotifications(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
|
|
|
+ const activity = await this.createActivity(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
|
|
|
+ await this.createAndSendNotifications(activity);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error('Error occurred while handling the comment create event:\n', err);
|
|
|
@@ -49,8 +48,7 @@ class CommentService {
|
|
|
this.commentEvent.on('update', async(updatedComment) => {
|
|
|
try {
|
|
|
this.commentEvent.onUpdate();
|
|
|
-
|
|
|
- await this.createAndSendNotifications(updatedComment, ActivityDefine.ACTION_COMMENT_UPDATE);
|
|
|
+ await this.createActivity(updatedComment, ActivityDefine.ACTION_COMMENT_UPDATE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error('Error occurred while handling the comment update event:\n', err);
|
|
|
@@ -71,18 +69,20 @@ class CommentService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private createAndSendNotifications = async function(comment, actionType) {
|
|
|
-
|
|
|
- // Create activity
|
|
|
+ private createActivity = async function(comment, action) {
|
|
|
const parameters = {
|
|
|
user: comment.creator,
|
|
|
targetModel: ActivityDefine.MODEL_PAGE,
|
|
|
target: comment.page,
|
|
|
eventModel: ActivityDefine.MODEL_COMMENT,
|
|
|
event: comment._id,
|
|
|
- action: actionType,
|
|
|
+ action,
|
|
|
};
|
|
|
const activity = await this.activityService.createByParameters(parameters);
|
|
|
+ return activity;
|
|
|
+ };
|
|
|
+
|
|
|
+ private createAndSendNotifications = async function(activity) {
|
|
|
|
|
|
// Get user to be notified
|
|
|
let targetUsers: Types.ObjectId[] = [];
|