From 08e715589aa651261d49cf9e6f587e2d773f482d Mon Sep 17 00:00:00 2001 From: kyeah <39901387+dmobtxx19@users.noreply.github.com> Date: Sun, 19 Nov 2023 01:52:18 +0900 Subject: [PATCH] refactor: emit create_room with nickname --- src/chat/chat.gateway.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/chat/chat.gateway.ts b/src/chat/chat.gateway.ts index ced7e84..7a8e11b 100644 --- a/src/chat/chat.gateway.ts +++ b/src/chat/chat.gateway.ts @@ -47,10 +47,10 @@ export class ChatGateway @MessageBody() user: number, ) { const users: number[] = [user, client.data.userId]; - let roomId; const room = await this.chatService.findCreatedRoom(users); if (room) { - roomId = room.id; + const roomId = room.id; + client.emit('create_room', roomId); } else { const roomId = await this.chatService.newChatRoom(users); @@ -64,10 +64,13 @@ export class ChatGateway } else { this.chatService.pushCreateRoom(user); } - } - client.join(`${roomId}_list`); - client.emit('create_room', roomId); + client.join(`${roomId}_list`); + client.emit('create_room', { + roomId: roomId, + nickname: socketUser.userNickname, + }); + } } @SubscribeMessage('join_chat')