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

call emitSocketIo method from activity service

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

+ 6 - 0
packages/app/src/server/service/activity.ts

@@ -11,10 +11,13 @@ class ActivityService {
 
   crowi: any;
 
+  inAppNotificationService: any;
+
   commentEvent!: any;
 
   constructor(crowi) {
     this.crowi = crowi;
+    this.inAppNotificationService = crowi.inAppNotificationService
     this.commentEvent = crowi.event('comment');
 
     // init
@@ -39,6 +42,9 @@ class ActivityService {
     // update
     this.commentEvent.on('update', (user) => {
       this.commentEvent.onUpdate();
+      const inAppNotificationService = new InAppNotificationService(this.crowi)
+
+      inAppNotificationService.emitSocketIo(user);
     });
 
     // remove

+ 5 - 11
packages/app/src/server/service/in-app-notification.ts

@@ -19,21 +19,15 @@ class InAppNotificationService {
   constructor(crowi: Crowi) {
     this.crowi = crowi;
     this.socketIoService = crowi.socketIoService;
-    this.commentEvent = crowi.event('comment');
-
-    // init
-    this.initCommentEvent();
   }
 
 
-  initCommentEvent(): void {
-    // update
-    this.commentEvent.on('update', (user) => {
-      if (this.socketIoService.isInitialized) {
-        this.socketIoService.getDefaultSocket().emit('comment updated', { user });
-      }
-    });
+  emitSocketIo = async(user) => {
+    if (this.socketIoService.isInitialized) {
+      console.log('socketIoServiceHoge');
 
+      await this.socketIoService.getDefaultSocket().emit('comment updated', { user });
+    }
   }
 
 }