Browse Source

adding getter for SocketIoSesrvice

kaori 4 years ago
parent
commit
0c795becff

+ 4 - 0
packages/app/src/server/crowi/index.js

@@ -308,6 +308,10 @@ Crowi.prototype.scanRuntimeVersions = async function() {
   });
   });
 };
 };
 
 
+Crowi.prototype.getSocketIoService = function() {
+  return this.socketIoService;
+};
+
 Crowi.prototype.getSlack = function() {
 Crowi.prototype.getSlack = function() {
   return this.slack;
   return this.slack;
 };
 };

+ 4 - 5
packages/app/src/server/models/notification.ts

@@ -195,11 +195,10 @@ export default (crowi: Crowi) => {
   };
   };
 
 
   notificationEvent.on('update', (user) => {
   notificationEvent.on('update', (user) => {
-    // TODO: be able to use getIo method by GW7221
-    // const io = crowi.getIo();
-    // if (io) {
-    //   io.sockets.emit('notification updated', { user });
-    // }
+    const io = crowi.getSocketIoService();
+    if (io) {
+      io.sockets.emit('notification updated', { user });
+    }
   });
   });
 
 
   notificationSchema.statics.STATUS_UNOPENED = function() {
   notificationSchema.statics.STATUS_UNOPENED = function() {