Skip to content

Commit

Permalink
refactor: emit create_room with nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Nov 18, 2023
1 parent 130cc56 commit 08e7155
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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')
Expand Down

0 comments on commit 08e7155

Please sign in to comment.