diff --git a/secondhand/src/main/java/com/codesquad/secondhand/common/interceptor/StompInterceptor.java b/secondhand/src/main/java/com/codesquad/secondhand/common/interceptor/StompInterceptor.java index d491f1010..183c2681b 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/common/interceptor/StompInterceptor.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/common/interceptor/StompInterceptor.java @@ -74,6 +74,7 @@ private Long getChatRoomId(StompHeaderAccessor accessor) { private Long validateAccessToken(StompHeaderAccessor accessor) { try { String token = extractAccessTokenFromAccessor(accessor); + log.info("token : {}", token); return jwtProvider.getClaims(token).get("memberId", Long.class); } catch (RuntimeException e) { throw new CustomRuntimeException(JwtException.from(e)); diff --git a/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/controller/ChatController.java b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/controller/ChatController.java index 862f5cd7a..f6483dd8c 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/controller/ChatController.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/controller/ChatController.java @@ -21,6 +21,7 @@ import com.codesquad.secondhand.domain.chat.dto.request.MessageRequest; import com.codesquad.secondhand.domain.chat.dto.response.ChatRoomDetailsResponse; import com.codesquad.secondhand.domain.chat.dto.response.ChatRoomListResponse; +import com.codesquad.secondhand.domain.chat.dto.response.ChatSendMessageResponse; import com.codesquad.secondhand.domain.chat.service.ChatService; import lombok.RequiredArgsConstructor; @@ -36,10 +37,10 @@ public class ChatController { @MessageMapping("/message") public void sendMessage(MessageRequest messageRequest) { - chatService.sendMessage(messageRequest); + ChatSendMessageResponse chatSendMessageResponse = chatService.sendMessage(messageRequest); // 채널아이디 만들기 simpMessageSendingOperations.convertAndSend("/sub/room/" + messageRequest.getChatRoomId(), - messageRequest.getMessage()); + chatSendMessageResponse); } @PostMapping("/api/chats/room-id") diff --git a/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/dto/response/ChatSendMessageResponse.java b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/dto/response/ChatSendMessageResponse.java new file mode 100644 index 000000000..0911d1bc7 --- /dev/null +++ b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/dto/response/ChatSendMessageResponse.java @@ -0,0 +1,24 @@ +package com.codesquad.secondhand.domain.chat.dto.response; + +import com.codesquad.secondhand.domain.chat.entity.ChatMessage; +import com.codesquad.secondhand.domain.chat.entity.ChatRoom; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +@AllArgsConstructor +public class ChatSendMessageResponse { + + private Long chatRoomId; + private ChatMessageResponse messages; + + public static ChatSendMessageResponse of(ChatMessage chatMessage, ChatRoom chatRoom) { + return ChatSendMessageResponse.builder() + .messages(ChatMessageResponse.of(chatMessage)) + .chatRoomId(chatRoom.getId()) + .build(); + } +} diff --git a/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/service/ChatService.java b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/service/ChatService.java index 0fd19706a..c6f6ae5ac 100644 --- a/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/service/ChatService.java +++ b/secondhand/src/main/java/com/codesquad/secondhand/domain/chat/service/ChatService.java @@ -15,6 +15,7 @@ import com.codesquad.secondhand.domain.chat.dto.response.ChatRoomMessageResponse; import com.codesquad.secondhand.domain.chat.dto.response.ChatRoomOpponentResponse; import com.codesquad.secondhand.domain.chat.dto.response.ChatRoomProductResponse; +import com.codesquad.secondhand.domain.chat.dto.response.ChatSendMessageResponse; import com.codesquad.secondhand.domain.chat.entity.ChatMessage; import com.codesquad.secondhand.domain.chat.entity.ChatRoom; import com.codesquad.secondhand.domain.chat.redis.RedisChatMember; @@ -39,7 +40,7 @@ public class ChatService { private final NotificationService notificationService; @Transactional - public void sendMessage(MessageRequest messageRequest) { + public ChatSendMessageResponse sendMessage(MessageRequest messageRequest) { //1. chatRoomId 가 존재하는지 검증 ChatRoom chatRoom = chatQueryService.findChatRoomByChatRoomId(messageRequest.getChatRoomId()); @@ -55,11 +56,12 @@ public void sendMessage(MessageRequest messageRequest) { if (redisChatMembers.size() == MAX_CHAT_MEMBERS) { // 메세지의 읽음 상태를 true 로 변경 (채팅방에 user 가 2명이기 때문에) chatMessage.updateReadStatusToTrue(); - return; + return ChatSendMessageResponse.of(chatMessage, chatRoom); } //SSE 재요청 알림 보내기 Long receiverId = chatRoom.findOpponentId(sender); notificationService.refreshChatRoomList(receiverId); + return ChatSendMessageResponse.of(chatMessage, chatRoom); } @Transactional