Shun Miyazawa 3 лет назад
Родитель
Сommit
c58b193732

+ 16 - 0
packages/app/src/server/events/activity.ts

@@ -1,14 +1,30 @@
+import { IPage } from '~/interfaces/page';
+import { ActivityDocument } from '~/server/models/activity';
+import loggerFactory from '~/utils/logger';
+
 import Crowi from '../crowi';
 
+const logger = loggerFactory('growi:events:activity');
 
 const events = require('events');
 const util = require('util');
 
 function ActivityEvent(crowi: Crowi) {
   this.crowi = crowi;
+  this.inAppNotificationService = crowi.inAppNotificationService;
 
   events.EventEmitter.call(this);
 }
+
+ActivityEvent.prototype.onUpdate = async function(activity: ActivityDocument, target: IPage) {
+  try {
+    await this.inAppNotificationService.createInAppNotification(activity, target);
+  }
+  catch (err) {
+    logger.error('Create InAppNotification failed', err);
+  }
+};
+
 util.inherits(ActivityEvent, events.EventEmitter);
 
 

+ 1 - 10
packages/app/src/server/service/activity.ts

@@ -18,12 +18,9 @@ class ActivityService {
 
   activityEvent: any;
 
-  inAppNotificationService!: any;
-
   constructor(crowi: Crowi) {
     this.crowi = crowi;
     this.activityEvent = crowi.event('activity');
-    this.inAppNotificationService = crowi.inAppNotificationService;
 
     this.updateByParameters = this.updateByParameters.bind(this);
 
@@ -42,16 +39,10 @@ class ActivityService {
         logger.error('Update activity failed', err);
         return;
       }
-
       // create inAppNotification
       const shouldNotification = (AllSupportedActionToNotifiedType as ReadonlyArray<string>).includes(activity.action);
       if (shouldNotification) {
-        try {
-          await this.inAppNotificationService.createInAppNotification(activity, target);
-        }
-        catch (err) {
-          logger.error('Create InAppNotification failed', err);
-        }
+        this.activityEvent.onUpdate(activity, target);
       }
     });
   }