Skip to content

Commit

Permalink
refactor: 메시지 전송 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
swonny committed Apr 30, 2024
1 parent dea1232 commit b67692b
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,10 +49,19 @@ public List<SendMessageDto> handleCreateSendMessage(
final Map<String, String> 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<String, String> data) {
return Long.parseLong(data.get(CHATROOM_ID_KEY));
}

private List<SendMessageDto> createSendMessageResponse(final Map<String, String> 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);
Expand Down

0 comments on commit b67692b

Please sign in to comment.