Skip to content

Commit fcf8361

Browse files
committed
2 parents 7b42722 + 804bbdd commit fcf8361

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/chat-room/chat-room.service.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,27 @@ export class ChatRoomService {
2323
userId,
2424
})
2525
.andWhere('chatRoom.status = :status', { status: 'activated' })
26+
.andWhere('chatRoom.requestStatus = :requestStatus', {
27+
requestStatus: 'accepted',
28+
})
2629
.orderBy('chatMessages.createdAt', 'DESC')
2730
.getMany();
2831

2932
// 각 채팅방에서 최신 메시지를 선택
3033
const chatRoomsWithLatestMessages = chatRooms.map((room) => {
34+
const otherUser =
35+
room.fromUser.id === userId ? room.toUser : room.fromUser;
3136
const latestMessage =
3237
room.chatMessages.length > 0 ? room.chatMessages[0] : null; // 가장 최근 메시지 선택
38+
3339
return {
34-
...room,
35-
latestMessage, // 최신 메시지 포함
40+
chatRoomId: room.id,
41+
otherUser: {
42+
id: otherUser.id,
43+
nickname: otherUser.nickname,
44+
profileUrl: otherUser.profilePictureUrl,
45+
},
46+
latestMessage: latestMessage,
3647
};
3748
});
3849
return chatRoomsWithLatestMessages;

0 commit comments

Comments
 (0)