diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProvider.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProvider.java index d9f69098d..2e4c1da4b 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProvider.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProvider.java @@ -30,6 +30,8 @@ @RequiredArgsConstructor public class ChatWebSocketHandleTextMessageProvider implements WebSocketHandleTextMessageProvider { + private static final String CHATROOM_ID_KEY = "chatRoomId"; + private final WebSocketChatSessions sessions; private final ObjectMapper objectMapper; private final MessageService messageService; @@ -47,10 +49,19 @@ public List handleCreateSendMessage( final Map data ) throws JsonProcessingException { final SessionAttributeDto sessionAttribute = getSessionAttributes(session); - final ChatMessageDataDto messageData = objectMapper.convertValue(data, ChatMessageDataDto.class); - sessions.add(session, messageData.chatRoomId()); + final long chatRoomId = getChatRoomId(data); + sessions.add(session, chatRoomId); + + return createSendMessageResponse(data, sessionAttribute); + } + private long getChatRoomId(final Map data) { + return Long.parseLong(data.get(CHATROOM_ID_KEY)); + } + + private List createSendMessageResponse(final Map data, final SessionAttributeDto sessionAttribute) throws JsonProcessingException { final Long writerId = sessionAttribute.userId(); + final ChatMessageDataDto messageData = objectMapper.convertValue(data, ChatMessageDataDto.class); final CreateMessageDto createMessageDto = createMessageDto(messageData, writerId); final Message message = messageService.create(createMessageDto); sendNotificationIfReceiverNotInSession(message, sessionAttribute);