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

notification count can be retrieved via socket

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

+ 1 - 3
packages/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

@@ -41,7 +41,7 @@ const InAppNotificationDropdown: FC = (props) => {
     console.log(props);
 
     const socket = props.socketIoContainer.getSocket();
-    socket.on('comment updated', (data: { user: string }) => {
+    socket.on('InAppNotification count update', (data: { user: string, count: number }) => {
       // eslint-disable-next-line no-console
       console.log('socketData', data);
 
@@ -49,8 +49,6 @@ const InAppNotificationDropdown: FC = (props) => {
         // TODO: Fetch notification list by #78557
         // fetchNotificationList();
 
-        // TODO Consider a way to fetch notification status
-        fetchNotificationStatus(props);
       }
     });
   };

+ 4 - 1
packages/app/src/server/service/in-app-notification.ts

@@ -26,12 +26,15 @@ export default class InAppNotificationService {
     this.crowi = crowi;
     this.socketIoService = crowi.socketIoService;
     this.activityEvent = crowi.event('activity');
+
+    this.getUnreadCountByUser = this.getUnreadCountByUser.bind(this);
   }
 
 
   emitSocketIo = async(user) => {
     if (this.socketIoService.isInitialized) {
-      await this.socketIoService.getDefaultSocket().emit('comment updated', { user });
+      const count = await this.getUnreadCountByUser(user);
+      await this.socketIoService.getDefaultSocket().emit('InAppNotification count update', { user, count });
     }
   }