|
@@ -35,7 +35,8 @@ class CommentService {
|
|
|
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);
|
|
|
|
|
|
|
|
- await this.createAndSendNotifications(savedComment);
|
|
|
|
|
|
|
+ const activity = await this.createActivity(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
|
|
|
|
|
+ await this.createAndSendNotifications(activity);
|
|
|
}
|
|
}
|
|
|
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);
|
|
@@ -44,9 +45,10 @@ class CommentService {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// update
|
|
// update
|
|
|
- this.commentEvent.on('update', async() => {
|
|
|
|
|
|
|
+ this.commentEvent.on('update', async(updatedComment) => {
|
|
|
try {
|
|
try {
|
|
|
this.commentEvent.onUpdate();
|
|
this.commentEvent.onUpdate();
|
|
|
|
|
+ await this.createActivity(updatedComment, ActivityDefine.ACTION_COMMENT_UPDATE);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error('Error occurred while handling the comment update event:\n', err);
|
|
logger.error('Error occurred while handling the comment update event:\n', err);
|
|
@@ -67,18 +69,20 @@ class CommentService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private createAndSendNotifications = async function(comment) {
|
|
|
|
|
-
|
|
|
|
|
- // Create activity
|
|
|
|
|
|
|
+ private createActivity = async function(comment, action) {
|
|
|
const parameters = {
|
|
const parameters = {
|
|
|
user: comment.creator,
|
|
user: comment.creator,
|
|
|
targetModel: ActivityDefine.MODEL_PAGE,
|
|
targetModel: ActivityDefine.MODEL_PAGE,
|
|
|
target: comment.page,
|
|
target: comment.page,
|
|
|
eventModel: ActivityDefine.MODEL_COMMENT,
|
|
eventModel: ActivityDefine.MODEL_COMMENT,
|
|
|
event: comment._id,
|
|
event: comment._id,
|
|
|
- action: ActivityDefine.ACTION_COMMENT,
|
|
|
|
|
|
|
+ action,
|
|
|
};
|
|
};
|
|
|
const activity = await this.activityService.createByParameters(parameters);
|
|
const activity = await this.activityService.createByParameters(parameters);
|
|
|
|
|
+ return activity;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ private createAndSendNotifications = async function(activity) {
|
|
|
|
|
|
|
|
// Get user to be notified
|
|
// Get user to be notified
|
|
|
let targetUsers: Types.ObjectId[] = [];
|
|
let targetUsers: Types.ObjectId[] = [];
|