Просмотр исходного кода

moving Activity operation (onCreate)

kaori 4 лет назад
Родитель
Сommit
e8f4028d3b

+ 1 - 12
packages/app/src/server/models/comment.js

@@ -137,18 +137,7 @@ module.exports = function(crowi) {
       throw err;
     }
 
-    await commentEvent.emit('create', savedComment.creator);
-
-    /**
-     * TODO: move Activity operation from this model scope by GW-7506
-     */
-    try {
-      const activityLog = await Activity.createByPageComment(savedComment);
-      debug('Activity created', activityLog);
-    }
-    catch (err) {
-      throw err;
-    }
+    await commentEvent.emit('create', savedComment);
   });
 
   return mongoose.model('Comment', commentSchema);

+ 19 - 1
packages/app/src/server/service/in-app-notification.ts

@@ -1,5 +1,11 @@
 import Crowi from '../crowi';
 import { InAppNotification } from '~/server/models/in-app-notification';
+import { Activity } from '~/server/models/activity';
+
+import loggerFactory from '~/utils/logger';
+
+const logger = loggerFactory('growi:service:inAppNotification');
+
 
 class InAppNotificationService {
 
@@ -21,8 +27,16 @@ class InAppNotificationService {
 
   initCommentEvent(): void {
     // create
-    this.commentEvent.on('create', (user) => {
+    this.commentEvent.on('create', async(savedComment) => {
       this.commentEvent.onCreate();
+
+      try {
+        const activityLog = await Activity.createByPageComment(savedComment);
+        logger.info('Activity created', activityLog);
+      }
+      catch (err) {
+        throw err;
+      }
     });
 
     // update
@@ -32,9 +46,13 @@ class InAppNotificationService {
       if (this.socketIoService.isInitialized) {
         this.socketIoService.getDefaultSocket().emit('comment updated', { user });
       }
+
     });
 
     // remove
+    this.commentEvent.on('remove', (commentData) => {
+      this.commentEvent.onRemove();
+    });
 
   }