Shun Miyazawa 4 лет назад
Родитель
Сommit
4c4c39ce43

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

@@ -73,7 +73,7 @@ module.exports = function(crowi) {
       { $set: { comment, isMarkdown } },
     );
 
-    await commentEvent.emit('update', commentData.creator);
+    await commentEvent.emit('update', commentData.creator, commentData.page);
 
     return commentData;
   };

+ 2 - 2
packages/app/src/server/service/comment.ts

@@ -51,11 +51,11 @@ class CommentService {
     });
 
     // update
-    this.commentEvent.on('update', (user) => {
+    this.commentEvent.on('update', (userId, pageId) => {
       this.commentEvent.onUpdate();
       const { inAppNotificationService } = this.crowi;
 
-      inAppNotificationService.emitSocketIo(user);
+      inAppNotificationService.emitSocketIo(userId, pageId);
     });
 
     // remove

+ 7 - 3
packages/app/src/server/service/in-app-notification.ts

@@ -7,6 +7,7 @@ import {
 import { ActivityDocument } from '~/server/models/activity';
 
 import loggerFactory from '~/utils/logger';
+import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 
 const logger = loggerFactory('growi:service:inAppNotification');
 
@@ -31,10 +32,13 @@ export default class InAppNotificationService {
   }
 
 
-  emitSocketIo = async(user) => {
+  emitSocketIo = async(userId, pageId) => {
     if (this.socketIoService.isInitialized) {
-      const count = await this.getUnreadCountByUser(user);
-      await this.socketIoService.getDefaultSocket().emit('InAppNotification:countUpdate', { user, count });
+      const count = await this.getUnreadCountByUser(userId);
+      await this.socketIoService.getDefaultSocket()
+        .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
+        .except(getRoomNameWithId(RoomPrefix.USER, userId))
+        .emit('InAppNotification:countUpdate', { userId, count });
     }
   }