diff --git a/src/main/java/capstone/facefriend/chat/controller/MessageController.java b/src/main/java/capstone/facefriend/chat/controller/MessageController.java index 6eaa0715be..54001ef6fb 100644 --- a/src/main/java/capstone/facefriend/chat/controller/MessageController.java +++ b/src/main/java/capstone/facefriend/chat/controller/MessageController.java @@ -86,5 +86,4 @@ public void heartreply( messageService.heartReply(heartReplyRequest, receiveId); } - } \ No newline at end of file diff --git a/src/main/java/capstone/facefriend/chat/service/MessageService.java b/src/main/java/capstone/facefriend/chat/service/MessageService.java index 025d33e2ac..03f7dc5f10 100644 --- a/src/main/java/capstone/facefriend/chat/service/MessageService.java +++ b/src/main/java/capstone/facefriend/chat/service/MessageService.java @@ -150,11 +150,11 @@ public void sendMessage(MessageRequest messageRequest, Long senderId) { public void sendHeart(Long senderId, Long receiveId) { String exceptionDestination = "/sub/chat/" + senderId; -// if (chatRoomMemberRepository.findBySenderAndReceiver(senderId, receiveId).isPresent()){ -// String exceptionMessage = ChatExceptionType.ALREADY_CHATROOM.message(); -// simpMessagingTemplate.convertAndSend(exceptionDestination, exceptionMessage); -// throw new ChatException(ChatExceptionType.ALREADY_CHATROOM); -// } + if (chatRoomMemberRepository.findBySenderAndReceiver(senderId, receiveId).isPresent()){ + String exceptionMessage = ChatExceptionType.ALREADY_CHATROOM.message(); + simpMessagingTemplate.convertAndSend(exceptionDestination, exceptionMessage); + throw new ChatException(ChatExceptionType.ALREADY_CHATROOM); + } ChatRoom chatRoom = ChatRoom.builder() .status(ChatRoom.Status.set) @@ -186,6 +186,7 @@ public void sendHeart(Long senderId, Long receiveId) { sendHeartResponse.setType("Heart"); String topic = channelTopic.getTopic(); + simpMessagingTemplate.convertAndSend(exceptionDestination, "대화 요청 성공"); redisTemplate.convertAndSend(topic, sendHeartResponse); } @Transactional @@ -216,7 +217,10 @@ public void heartReply(HeartReplyRequest heartReplyRequest, Long receiveId) { } // 동적으로 목적지 설정 String destination = "/sub/chat/" + sender.getId(); - + + // 대화 수락 + simpMessagingTemplate.convertAndSend(exceptionDestination, "대화 수락 성공"); + // 메시지 전송 simpMessagingTemplate.convertAndSend(destination, message); } @@ -224,6 +228,7 @@ public void heartReply(HeartReplyRequest heartReplyRequest, Long receiveId) { @Transactional public void enterApplication(Long memberId) { + String exceptionDestination = "/sub/chat/" + memberId; SocketInfo socketInfo = new SocketInfo(); socketInfo.setMemberId(memberId); socketInfo.setConnectTime(LocalDateTime.now()); @@ -235,6 +240,8 @@ public void enterApplication(Long memberId) { if(isExistUnSendHeart(memberId)) { sendSentHeart(memberId); } + + simpMessagingTemplate.convertAndSend(exceptionDestination, "저장 성공"); } @Transactional