Skip to content

Commit d413553

Browse files
committed
hotfix : 채팅방 목록 조회 시 상대방 데이터 조회 로직 수정
1 parent ba5dc6a commit d413553

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/main/java/ita/tinybite/domain/chat/dto/res/OneToOneChatRoomDetailResDto.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import ita.tinybite.domain.chat.entity.ChatRoom;
6-
import ita.tinybite.domain.chat.entity.ChatRoomMember;
76
import ita.tinybite.domain.chat.enums.ParticipantType;
87
import ita.tinybite.domain.party.entity.Party;
98
import ita.tinybite.domain.party.entity.PartyParticipant;
@@ -24,9 +23,8 @@ public record OneToOneChatRoomDetailResDto(
2423
String partyTitle
2524
) {
2625

27-
public static OneToOneChatRoomDetailResDto of(Party party, PartyParticipant partyParticipant, User currentUser, ChatRoom groupChatRoom, ChatRoomMember chatRoomMembers) {
26+
public static OneToOneChatRoomDetailResDto of(Party party, PartyParticipant partyParticipant, User currentUser, ChatRoom groupChatRoom, User participant) {
2827
User host = partyParticipant.getParty().getHost();
29-
User participant = chatRoomMembers.getUser();
3028

3129
ParticipantType type = currentUser.getUserId().equals(host.getUserId()) ? ParticipantType.HOST : ParticipantType.PARTICIPANT;
3230
User targetUser = currentUser.getUserId().equals(participant.getUserId()) ? host : participant; // 상대방의 유저 (호스트면 참여자 / 참여자면 호스트)

src/main/java/ita/tinybite/domain/chat/service/ChatRoomService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public List<OneToOneChatRoomResDto> getOneToOneRooms() {
6161
PartyParticipant partyParticipant = partyParticipantRepository.findByOneToOneChatRoom(chatRoom).orElseThrow();
6262
ParticipantStatus status = partyParticipant.getStatus();
6363

64-
// (chatRoom, user)로 채팅참여 엔티티 조회
64+
User targetUser = partyParticipant.getUser();
6565
ChatRoomMember chatRoomMember = chatRoomMemberRepository.findByChatRoomAndUser(chatRoom, user).orElseThrow();
6666

6767
// 마지막으로 읽은 시점을 기점으로 몇 개의 메시지가 안 읽혔는지 확인
6868
long unreadCnt = chatMessageRepository.countByChatRoomIdAndCreatedAtAfterAndSenderIdNot(chatRoom.getId(), chatRoomMember.getLastReadAt(), user.getUserId());
6969

7070
String content = recentMessage != null ? recentMessage.getContent() : "";
7171
// dto로 합침
72-
return OneToOneChatRoomResDto.of(chatRoom, user, chatRoom.getParticipants().get(0).getUser(), content, timeAgo, status, unreadCnt);
72+
return OneToOneChatRoomResDto.of(chatRoom, user, targetUser, content, timeAgo, status, unreadCnt);
7373
})
7474
.toList();
7575
}
@@ -107,8 +107,7 @@ public OneToOneChatRoomDetailResDto getOneToOneRoom(Long chatRoomId) {
107107
if(!chatRoom.getType().equals(ChatRoomType.ONE_TO_ONE)) throw BusinessException.of(ChatRoomErrorCode.NOT_ONE_TO_ONE);
108108

109109
PartyParticipant partyParticipant = partyParticipantRepository.findByOneToOneChatRoomAndStatus(chatRoom, ParticipantStatus.PENDING);
110-
111-
ChatRoomMember participant = chatRoom.getParticipants().stream().findFirst().get();
110+
User participant = partyParticipant.getUser();
112111

113112
ChatRoom groupChatRoom = chatRoomRepository.findByPartyAndType(chatRoom.getParty(), ChatRoomType.GROUP).orElseGet(null);
114113
return OneToOneChatRoomDetailResDto.of(chatRoom.getParty(), partyParticipant, currentUser, groupChatRoom, participant);

0 commit comments

Comments
 (0)