|
3 | 3 | import com.sys.stm.domains.messenger.dto.request.ChatMessageRequestDto; |
4 | 4 | import com.sys.stm.domains.messenger.dto.request.MessageReadRequestDto; |
5 | 5 | import com.sys.stm.domains.messenger.dto.response.ChatMessageResponseDto; |
| 6 | +import com.sys.stm.domains.messenger.dto.response.ChatRoomListUpdateResponseDto; |
6 | 7 | import com.sys.stm.domains.messenger.dto.response.MessageReadResponseDto; |
7 | 8 | import com.sys.stm.domains.messenger.dto.response.TotalUnreadCountResponseDto; |
8 | 9 | import com.sys.stm.domains.messenger.service.ChatMessageServiceImpl; |
@@ -37,22 +38,32 @@ public void sendMessage(ChatMessageRequestDto message) { |
37 | 38 | // 메시지를 구독자들(채팅방 참여자)에게 전송 |
38 | 39 | messagingTemplate.convertAndSend("/topic/chatroom/" + message.getChatRoomId(), chatMessageResponseDto); |
39 | 40 |
|
40 | | - // 3. 채팅방 참여자들에게 최신 전체 안읽음 카운트 전송 |
| 41 | + // 채팅방 참여자들에게 최신 전체 안읽음 카운트 전송 |
41 | 42 | List<Long> participantIds = |
42 | 43 | chatRoomParticipantService.findParticipantIdsByRoomId(message.getChatRoomId()); |
43 | 44 |
|
| 45 | + // 채팅방의 최신 메시지 조회 |
| 46 | + String recentMessage = chatRoomService.getRecentMessageById(message.getChatRoomId()); |
| 47 | + |
44 | 48 | for (Long participantId : participantIds) { |
45 | 49 | if (participantId.equals(message.getSenderId())) { |
46 | 50 | continue; // 메시지 보낸 사람은 제외 |
47 | 51 | } |
48 | 52 |
|
49 | | - // 4. 해당 참여자의 전체 안 읽은 메시지 개수를 다시 계산 |
| 53 | + // 채팅방 목록 구독자들에게 최신 정보 전송 |
| 54 | + long totalUnreadCountForRoom = chatRoomService.getUnreadCount(participantId, message.getChatRoomId()); |
| 55 | + messagingTemplate.convertAndSend( |
| 56 | + "/topic/chatroom-list", |
| 57 | + new ChatRoomListUpdateResponseDto(message.getChatRoomId(), totalUnreadCountForRoom, recentMessage,participantId) |
| 58 | + ); |
| 59 | + |
| 60 | + // 해당 참여자의 전체 안 읽은 메시지 개수를 다시 계산 |
50 | 61 | long totalUnreadCount = chatRoomService.getTotalUnreadCount(participantId); |
51 | 62 |
|
52 | | - // 5. 개인 큐로 최신 총합 전송 |
| 63 | + // 개인 큐로 최신 총합 전송 |
53 | 64 | messagingTemplate.convertAndSend( |
54 | | - "/queue/total-unread/" + participantId.toString() |
55 | | - , new TotalUnreadCountResponseDto(totalUnreadCount) |
| 65 | + "/topic/update", |
| 66 | + new TotalUnreadCountResponseDto(totalUnreadCount, recentMessage, participantId, message.getChatRoomId()) |
56 | 67 | ); |
57 | 68 | } |
58 | 69 |
|
|
0 commit comments