From f13722c764dcc59b54b03306f41587db48ad6ae8 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:17:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Path=20to=20Retrieve=20Last?= =?UTF-8?q?=20Message=20ID=20(#192)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: impl last_message_id_save_service * feat: add message path about read_message * fix: outstream debug mesage level is changed from info to debug * rename: fix message_mapping end-point --- .../config/WebSocketMessageBrokerConfig.java | 2 +- .../socket/controller/ChatMessageController.java | 12 ++++++++++++ .../socket/service/LastMessageIdSaveService.java | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 pennyway-socket/src/main/java/kr/co/pennyway/socket/service/LastMessageIdSaveService.java diff --git a/pennyway-socket/src/main/java/kr/co/pennyway/socket/config/WebSocketMessageBrokerConfig.java b/pennyway-socket/src/main/java/kr/co/pennyway/socket/config/WebSocketMessageBrokerConfig.java index 09017723..4b8f743d 100644 --- a/pennyway-socket/src/main/java/kr/co/pennyway/socket/config/WebSocketMessageBrokerConfig.java +++ b/pennyway-socket/src/main/java/kr/co/pennyway/socket/config/WebSocketMessageBrokerConfig.java @@ -73,7 +73,7 @@ public void configureClientOutboundChannel(ChannelRegistration registration) { @Override public Message preSend(@NonNull Message message, @NonNull MessageChannel channel) { StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); - log.info("Outbound message: {}", accessor); + log.debug("Outbound message: {}", accessor); return message; } }); diff --git a/pennyway-socket/src/main/java/kr/co/pennyway/socket/controller/ChatMessageController.java b/pennyway-socket/src/main/java/kr/co/pennyway/socket/controller/ChatMessageController.java index a0a896e3..a34f7f0b 100644 --- a/pennyway-socket/src/main/java/kr/co/pennyway/socket/controller/ChatMessageController.java +++ b/pennyway-socket/src/main/java/kr/co/pennyway/socket/controller/ChatMessageController.java @@ -1,10 +1,12 @@ package kr.co.pennyway.socket.controller; +import jakarta.validation.constraints.NotNull; import kr.co.pennyway.socket.command.SendMessageCommand; import kr.co.pennyway.socket.common.annotation.PreAuthorize; import kr.co.pennyway.socket.common.security.authenticate.UserPrincipal; import kr.co.pennyway.socket.dto.ChatMessageDto; import kr.co.pennyway.socket.service.ChatMessageSendService; +import kr.co.pennyway.socket.service.LastMessageIdSaveService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.handler.annotation.DestinationVariable; @@ -17,10 +19,20 @@ @RequiredArgsConstructor public class ChatMessageController { private final ChatMessageSendService chatMessageSendService; + private final LastMessageIdSaveService lastMessageIdSaveService; @MessageMapping("chat.message.{chatRoomId}") @PreAuthorize("#isAuthenticated(#principal) and @chatRoomAccessChecker.hasPermission(#chatRoomId, #principal)") public void sendMessage(@DestinationVariable Long chatRoomId, @Validated ChatMessageDto.Request payload, UserPrincipal principal) { chatMessageSendService.execute(SendMessageCommand.createUserMessage(chatRoomId, payload.content(), payload.contentType(), principal.getUserId())); } + + @MessageMapping("chat.message.{chatRoomId}.read.{lastReadMessageId}") + @PreAuthorize("#isAuthenticated(#principal) and @chatRoomAccessChecker.hasPermission(#chatRoomId, #principal)") + public void readMessage(@DestinationVariable(value = "chatRoomId") @Validated @NotNull Long chatRoomId, + @DestinationVariable(value = "lastReadMessageId") @Validated @NotNull Long lastReadMessageId, + UserPrincipal principal + ) { + lastMessageIdSaveService.execute(principal.getUserId(), chatRoomId, lastReadMessageId); + } } diff --git a/pennyway-socket/src/main/java/kr/co/pennyway/socket/service/LastMessageIdSaveService.java b/pennyway-socket/src/main/java/kr/co/pennyway/socket/service/LastMessageIdSaveService.java new file mode 100644 index 00000000..725f0127 --- /dev/null +++ b/pennyway-socket/src/main/java/kr/co/pennyway/socket/service/LastMessageIdSaveService.java @@ -0,0 +1,15 @@ +package kr.co.pennyway.socket.service; + +import kr.co.pennyway.domain.domains.chatstatus.service.ChatMessageStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class LastMessageIdSaveService { + private final ChatMessageStatusService chatMessageStatusService; + + public void execute(Long userId, Long chatRoomId, Long lastReadMessageId) { + chatMessageStatusService.saveLastReadMessageId(userId, chatRoomId, lastReadMessageId); + } +}