Skip to content

Commit

Permalink
feat: ✨ Path to Retrieve Last Message ID (#192)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
psychology50 authored Nov 6, 2024
1 parent 727c2df commit f13722c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit f13722c

Please sign in to comment.