Shun Miyazawa 1 год назад
Родитель
Сommit
e3c63d906f

+ 2 - 9
apps/app/src/client/services/side-effects/yjs.ts

@@ -3,16 +3,11 @@ import { useCallback, useEffect } from 'react';
 import { useGlobalSocket } from '@growi/core/dist/swr';
 
 import { SocketEventName } from '~/interfaces/websocket';
-import { type CurrentPageYjsDraft } from '~/interfaces/yjs';
 import { useCurrentPageYjsData } from '~/stores/yjs';
 
 export const useCurrentPageYjsDataEffect = (): void => {
   const { data: socket } = useGlobalSocket();
-  const { updateHasDraft, updateHasRevisionBodyDiff, updateAwarenessStateSize } = useCurrentPageYjsData();
-
-  const yjsDraftUpdateHandler = useCallback(((currentPageYjsDraft: CurrentPageYjsDraft) => {
-    updateHasDraft(currentPageYjsDraft.hasYjsDraft);
-  }), [updateHasDraft]);
+  const { updateHasRevisionBodyDiff, updateAwarenessStateSize } = useCurrentPageYjsData();
 
   const yjsHasRevisionBodyDiffUpdateHandler = useCallback((hasRevisionBodyDiff: boolean) => {
     updateHasRevisionBodyDiff(hasRevisionBodyDiff);
@@ -26,15 +21,13 @@ export const useCurrentPageYjsDataEffect = (): void => {
 
     if (socket == null) { return }
 
-    socket.on(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
     socket.on(SocketEventName.YjsHasRevisionBodyDiffUpdated, yjsHasRevisionBodyDiffUpdateHandler);
     socket.on(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
 
     return () => {
-      socket.off(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
       socket.off(SocketEventName.YjsHasRevisionBodyDiffUpdated, yjsHasRevisionBodyDiffUpdateHandler);
       socket.off(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
     };
 
-  }, [socket, yjsAwarenessStateUpdateHandler, yjsDraftUpdateHandler, yjsHasRevisionBodyDiffUpdateHandler]);
+  }, [socket, yjsAwarenessStateUpdateHandler, yjsHasRevisionBodyDiffUpdateHandler]);
 };

+ 0 - 1
apps/app/src/interfaces/websocket.ts

@@ -50,7 +50,6 @@ export const SocketEventName = {
   PageDeleted: 'page:delete',
 
   // Yjs
-  YjsDraftUpdated: 'yjs:draft-update',
   YjsAwarenessStateUpdated: 'yjs:awareness-state-update',
   YjsHasRevisionBodyDiffUpdated: 'yjs:has-revision-body-diff-update',
 } as const;

+ 0 - 7
apps/app/src/interfaces/yjs.ts

@@ -1,11 +1,4 @@
-export type CurrentPageYjsDraft = {
-  hasYjsDraft: boolean,
-}
-
-export const CurrentPageYjsDraftData = { hasYjsDraft: true };
-
 export type CurrentPageYjsData = {
-  hasDraft?: boolean,
   hasRevisionBodyDiff?: boolean,
   awarenessStateSize?: number,
 }

+ 0 - 1
apps/app/src/server/service/page/index.ts

@@ -4455,7 +4455,6 @@ class PageService implements IPageService {
     const yjsDraft = currentYdoc?.getText('codemirror').toString();
 
     return {
-      hasDraft: currentYdoc != null,
       hasRevisionBodyDiff: yjsDraft != null && revisionBody != null && yjsDraft !== revisionBody,
       awarenessStateSize: currentYdoc?.awareness.states.size,
     };

+ 1 - 7
apps/app/src/server/service/socket-io.js

@@ -3,7 +3,6 @@ import mongoose from 'mongoose';
 import { Server } from 'socket.io';
 
 import { SocketEventName } from '~/interfaces/websocket';
-import { CurrentPageYjsDraftData } from '~/interfaces/yjs';
 import loggerFactory from '~/utils/logger';
 
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -171,6 +170,7 @@ class SocketIoService {
   setupYjsConnection() {
     const yjsConnectionManager = getYjsConnectionManager();
     const Page = mongoose.model('Page');
+
     this.io.on('connection', (socket) => {
 
       yjsConnectionManager.ysocketioInstance.on('awareness-update', async(update) => {
@@ -198,12 +198,6 @@ class SocketIoService {
       });
 
       socket.on(GlobalSocketEventName.YDocSync, async({ pageId, initialValue }) => {
-
-        // Emit to the client in the room of the target pageId.
-        this.io
-          .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
-          .emit(SocketEventName.YjsDraftUpdated, CurrentPageYjsDraftData);
-
         try {
           await yjsConnectionManager.handleYDocSync(pageId, initialValue);
         }

+ 1 - 6
apps/app/src/stores/yjs.ts

@@ -6,7 +6,6 @@ import type { SWRResponse } from 'swr';
 import type { CurrentPageYjsData } from '~/interfaces/yjs';
 
 type CurrentPageYjsDataUtils = {
-  updateHasDraft(hasYjsDraft: boolean): void
   updateHasRevisionBodyDiff(hasRevisionBodyDiff: boolean): void
   updateAwarenessStateSize(awarenessStateSize: number): void
 }
@@ -14,10 +13,6 @@ type CurrentPageYjsDataUtils = {
 export const useCurrentPageYjsData = (): SWRResponse<CurrentPageYjsData, Error> & CurrentPageYjsDataUtils => {
   const swrResponse = useSWRStatic<CurrentPageYjsData, Error>('currentPageYjsData', undefined);
 
-  const updateHasDraft = useCallback((hasDraft: boolean) => {
-    swrResponse.mutate({ ...swrResponse.data, hasDraft });
-  }, [swrResponse]);
-
   const updateHasRevisionBodyDiff = useCallback((hasRevisionBodyDiff: boolean) => {
     swrResponse.mutate({ ...swrResponse.data, hasRevisionBodyDiff });
   }, [swrResponse]);
@@ -27,6 +22,6 @@ export const useCurrentPageYjsData = (): SWRResponse<CurrentPageYjsData, Error>
   }, [swrResponse]);
 
   return {
-    ...swrResponse, updateHasDraft, updateHasRevisionBodyDiff, updateAwarenessStateSize,
+    ...swrResponse, updateHasRevisionBodyDiff, updateAwarenessStateSize,
   };
 };