Skip to content

Commit

Permalink
[수정] chat 중복 코드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeDragoN1123 committed Nov 13, 2023
1 parent f0ffebf commit e216a66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<br>
<br>
## 👥 참가한 사람들

![Project Logo](images/catheeyong.jpg)

<table>
<tr>
<th style="width: 300px;">이름</th>
Expand Down
6 changes: 4 additions & 2 deletions src/chats/chats.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ export class ChatsGateway
);

// MongoDB의 socketModel에 사용자 정보 저장
await this.socketModel.create({
const userInfo = await this.socketModel.create({
socketId: socket.id,
nickname: payload.nickname,
roomId: payload.roomId,
profileImg: payload.profileImg,
userId: payload.userId,
});
// sockets db에 저장된 유저정보를 userList배열에 추가
this.userList.push(userInfo);

// 이전 채팅 내용을 불러옵니다.
const chatHistory = await this.getChatHistory(payload.roomId);
Expand All @@ -127,6 +129,7 @@ export class ChatsGateway

// 이전 채팅 내용과 함께 사용자 정보를 클라이언트에게 전송합니다.
socket.emit('chat_history', chatHistory);
// this.server.to(String(payload.roomId)).emit('chat_history', chatHistory);
// 방에 있는 모든 사용자에게 userList 전송
this.server.to(String(payload.roomId)).emit('user_connected', payload);
// console.log('유저리스트 콘솔', this.userList);
Expand Down Expand Up @@ -174,7 +177,6 @@ export class ChatsGateway
nickname: messageData.nickname,
profileImg: messageData.profileImg,
roomId: messageData.roomId,
time: messageData.time,
chat: messageData.message, // 수정: messageData.message를 사용하여 채팅 저장
});

Expand Down

0 comments on commit e216a66

Please sign in to comment.