2
0
Эх сурвалжийг харах

added emit in notificationservice

kaori 4 жил өмнө
parent
commit
6d1b909239

+ 1 - 1
packages/app/src/server/events/notification.ts

@@ -14,7 +14,7 @@ function NotificationEvent(crowi) {
 util.inherits(NotificationEvent, events.EventEmitter);
 
 
-NotificationEvent.prototype.onUpdate = function(user) {
+NotificationEvent.prototype.onUpdate = function() {
   logger.info('onUpdate event fired');
 };
 

+ 0 - 8
packages/app/src/server/models/notification.ts

@@ -194,14 +194,6 @@ export default (crowi: Crowi) => {
     }
   };
 
-  notificationEvent.on('update', (user) => {
-    const socket = crowi.getSocketIo();
-
-    if (socket != null) {
-      socket.emit('notification updated', { user });
-    }
-  });
-
   notificationSchema.statics.STATUS_UNOPENED = function() {
     return STATUS_UNOPENED;
   };

+ 12 - 0
packages/app/src/server/service/notification.ts

@@ -4,15 +4,27 @@ class NortificationService {
 
   crowi!: any;
 
+  socketIoService!: any;
+
   notificationEvent!: any;
 
 
   constructor(crowi: Crowi) {
     this.crowi = crowi;
+    this.socketIoService = crowi.socketIoService;
     this.notificationEvent = crowi.event('notification');
 
     // init
+    this.updateNotificationevent();
+  }
+
+  updateNotificationevent() {
     this.notificationEvent.on('update', this.notificationEvent.onUpdate);
+
+    if (this.socketIoService.isInitialized) {
+      // need to pass user in second argument
+      this.socketIoService.getDefaultSocket().emit('notification updated');
+    }
   }
 
 }