From 4ef910ec38d1ee39e25297e25bf7c0994ab9785a Mon Sep 17 00:00:00 2001 From: pipisebastian Date: Tue, 3 Dec 2024 01:06:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=20remote=20checkbox?= =?UTF-8?q?=20gateway=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #270 --- server/src/workspace/workspace.gateway.ts | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/server/src/workspace/workspace.gateway.ts b/server/src/workspace/workspace.gateway.ts index b8351f6..80c45c8 100644 --- a/server/src/workspace/workspace.gateway.ts +++ b/server/src/workspace/workspace.gateway.ts @@ -20,6 +20,7 @@ import { RemoteBlockUpdateOperation, RemotePageCreateOperation, RemoteBlockReorderOperation, + RemoteBlockCheckboxOperation, RemoteCharUpdateOperation, CursorPosition, } from "@noctaCrdt/Interfaces"; @@ -669,6 +670,50 @@ export class WorkspaceGateway implements OnGatewayInit, OnGatewayConnection, OnG } } + /** + * 블록 Checkbox 연산 처리 + */ + @SubscribeMessage("checkbox/block") + async handleBlockCheckbox( + @MessageBody() data: RemoteBlockCheckboxOperation, + @ConnectedSocket() client: Socket, + ): Promise { + const clientInfo = this.clientMap.get(client.id); + try { + this.logger.debug( + `Block checkbox 연산 수신 - Client ID: ${clientInfo?.clientId}, Data:`, + JSON.stringify(data), + ); + const { workspaceId } = client.data; + const currentBlock = await this.workSpaceService.getBlock( + workspaceId, + data.pageId, + data.blockId, + ); + + if (!currentBlock) { + throw new Error(`Block with id ${data.blockId} not found`); + } + + currentBlock.isChecked = data.isChecked; + + const operation = { + type: "blockCheckbox", + blockId: data.blockId, + pageId: data.pageId, + isChecked: data.isChecked, + }; + + client.broadcast.to(data.pageId).emit("checkbox/block", operation); + } catch (error) { + this.logger.error( + `Block Checkbox 연산 처리 중 오류 발생 - Client ID: ${clientInfo?.clientId}`, + error.stack, + ); + throw new WsException(`Checkbox 연산 실패: ${error.message}`); + } + } + /** * 글자 삽입 연산 처리 */