Skip to content

Commit

Permalink
Merge pull request #64 from kookmin-sw/refactor/sendheart
Browse files Browse the repository at this point in the history
Refactor: 성공에 대한 response 필요로 코드 리팩토링
  • Loading branch information
imjanghyeok authored May 10, 2024
2 parents 8b0b73b + 4169a89 commit b457c7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ public void heartreply(

messageService.heartReply(heartReplyRequest, receiveId);
}

}
19 changes: 13 additions & 6 deletions src/main/java/capstone/facefriend/chat/service/MessageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -216,14 +217,18 @@ public void heartReply(HeartReplyRequest heartReplyRequest, Long receiveId) {
}
// 동적으로 목적지 설정
String destination = "/sub/chat/" + sender.getId();


// 대화 수락
simpMessagingTemplate.convertAndSend(exceptionDestination, "대화 수락 성공");

// 메시지 전송
simpMessagingTemplate.convertAndSend(destination, message);
}


@Transactional
public void enterApplication(Long memberId) {
String exceptionDestination = "/sub/chat/" + memberId;
SocketInfo socketInfo = new SocketInfo();
socketInfo.setMemberId(memberId);
socketInfo.setConnectTime(LocalDateTime.now());
Expand All @@ -235,6 +240,8 @@ public void enterApplication(Long memberId) {
if(isExistUnSendHeart(memberId)) {
sendSentHeart(memberId);
}

simpMessagingTemplate.convertAndSend(exceptionDestination, "저장 성공");
}

@Transactional
Expand Down

0 comments on commit b457c7f

Please sign in to comment.