Skip to content

Commit

Permalink
✨ [FEAT] #78 채팅방 중복 생성 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jang99u committed Jan 22, 2025
1 parent a014862 commit 7e0c770
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ protected void handleTextMessage(WebSocketSession session, TextMessage textMessa
UserEntity receiver = userRetriever.findByUserId(incomingMessage.receiverId());

// 채팅방 생성이랑 메세지 전송 구분 : 채팅방 생성은 게시글 조회에서 이루어진다.
if (incomingMessage.type().equals("CREATE")) {
if(incomingMessage.type().equals("CREATE")) {

if(chatRoomRepository.existsByPostIdAndOwnerIdAndPeerId(
incomingMessage.postId(),
incomingMessage.senderId(),
incomingMessage.receiverId()
)) {
return; // 채팅방이 존재하는 경우 CREATE 는 잘못된 요청입니다.
}

// 소켓에 연결중인 유저의 세션을 가져옵니다.
WebSocketSession senderSession = sessions.get(incomingMessage.senderId());
WebSocketSession receiverSession = sessions.get(incomingMessage.receiverId());
Expand Down Expand Up @@ -101,15 +110,15 @@ protected void handleTextMessage(WebSocketSession session, TextMessage textMessa
} else {
log.info("상대방이 세션에 없음");
}
} else if (incomingMessage.type().equals("MESSAGE")) {
} else if(incomingMessage.type().equals("MESSAGE")) {
// 소켓에 연결중인 유저의 세션을 가져옵니다.
WebSocketSession receiverSession = sessions.get(incomingMessage.receiverId());

ChatRoom chatRoom = chatRoomRetriever.findByChatRoomId(incomingMessage.ownerChatRoomId());
ChatRoomInfo chatRoomInfo = chatRoomInfoRetriever.findByRoomNumber(chatRoom.getRoomNumber());

// 상대방이 세션에 들어와 있을 때
if (receiverSession != null && receiverSession.isOpen()) {
if(receiverSession != null && receiverSession.isOpen()) {
log.info("상대방이 세션에 있음");
if (chatRoomInfo.getParticipatingUsers().contains(receiver.getId())) {
// 케이스 1-1. 상대방이 채팅방에 들어와 있을 때
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface ChatRoomRepository extends MongoRepository<ChatRoom, String> {
Optional<ChatRoom> findByPostIdAndOwnerIdAndPeerId(Long postId, Long ownerId, Long peerId); // 해당 게시글에 대해 나와 상배당이 진행한 채팅방이 있는지 확인합니다.
Boolean existsByPostIdAndOwnerIdAndPeerId(Long postId, Long ownerId, Long peerId); // 해당 게시글에 대해 나와 상배당이 진행한 채팅방이 있는지 Boolean 으로 확인합니다.
List<ChatRoom> findAllByOwnerId(Long ownerId);
List<ChatRoom> findByOwnerIdOrPeerId(Long ownerId, Long peerId);
}

0 comments on commit 7e0c770

Please sign in to comment.