Przeglądaj źródła

added the ability to save a snapshot of the pageId when commenting

Shun Miyazawa 4 lat temu
rodzic
commit
e2e4e79a5e
1 zmienionych plików z 4 dodań i 3 usunięć
  1. 4 3
      packages/app/src/server/service/comment.ts

+ 4 - 3
packages/app/src/server/service/comment.ts

@@ -34,9 +34,10 @@ class CommentService {
       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 page = await Page.findById(savedComment.page);
 
 
         const activity = await this.createActivity(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
         const activity = await this.createActivity(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
-        await this.createAndSendNotifications(activity);
+        await this.createAndSendNotifications(activity, page.path);
       }
       }
       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);
@@ -82,14 +83,14 @@ class CommentService {
     return activity;
     return activity;
   };
   };
 
 
-  private createAndSendNotifications = async function(activity) {
+  private createAndSendNotifications = async function(activity, pagePath) {
 
 
     // Get user to be notified
     // Get user to be notified
     let targetUsers: Types.ObjectId[] = [];
     let targetUsers: Types.ObjectId[] = [];
     targetUsers = await activity.getNotificationTargetUsers();
     targetUsers = await activity.getNotificationTargetUsers();
 
 
     // Create and send notifications
     // Create and send notifications
-    await this.inAppNotificationService.upsertByActivity(targetUsers, activity);
+    await this.inAppNotificationService.upsertByActivity(targetUsers, activity, pagePath);
     await this.inAppNotificationService.emitSocketIo(targetUsers);
     await this.inAppNotificationService.emitSocketIo(targetUsers);
   };
   };