Skip to content

Commit

Permalink
Merge pull request #94 from 100-hours-a-week/fix-exitRoom
Browse files Browse the repository at this point in the history
fix: 채팅방 나가기 시 pendingList 업데이트 및 활성 멤버 수 계산 수정
  • Loading branch information
sen2y authored Aug 26, 2024
2 parents e110a4a + f392754 commit 19d9ce6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import connectripbe.connectrip_be.chat.entity.ChatRoomEntity;

import connectripbe.connectrip_be.chat.entity.type.ChatRoomMemberStatus;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
Expand All @@ -28,6 +29,11 @@ public static ChatRoomListResponse fromEntity(ChatRoomEntity chatRoom) {
? chatRoom.getLastChatTime()
: chatRoom.getCreatedAt();

// 활성 멤버 수 계산
int activeMemberCnt = (int) chatRoom.getChatRoomMembers().stream()
.filter(member -> member.getStatus().equals(ChatRoomMemberStatus.ACTIVE))
.count();

return ChatRoomListResponse.builder()
.chatRoomId(chatRoom.getId())
.accompanyPostId(chatRoom.getAccompanyPost().getId())
Expand All @@ -37,7 +43,7 @@ public static ChatRoomListResponse fromEntity(ChatRoomEntity chatRoom) {
.endDate(formatToUTC(chatRoom.getAccompanyPost().getEndDate()))
.lastChatMessage(chatRoom.getLastChatMessage())
.lastChatMessageTime(formatToUTC(lastChatTime))
.memberNumber(chatRoom.getChatRoomMembers().size())
.memberNumber(activeMemberCnt)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public void exitChatRoom(Long chatRoomId, Long memberId) {
// 사용자가 존재하는지 확인
ChatRoomMemberEntity chatRoomMember = getRoomMember(chatRoomId, memberId);

// 채팅방에서 나가기 전 pendingList 업데이트
pendingListUpdate(chatRoomMember, chatRoom);

// 사용자가 채팅방에서 나가기
chatRoomMember.exitChatRoom();

Expand Down Expand Up @@ -163,12 +166,13 @@ public void exitChatRoom(Long chatRoomId, Long memberId) {

chatRoomRepository.save(chatRoom);

}

private void pendingListUpdate(ChatRoomMemberEntity chatRoomMember, ChatRoomEntity chatRoom) {
AccompanyPostEntity accompanyPost = chatRoomMember.getChatRoom().getAccompanyPost();

// 방장이 아닌 경우에만 pendingList 업데이트
if (!chatRoomMember.getMember().equals(chatRoom.getCurrentLeader().getMember())) {

// 채팅방 나가기 처리 후, 방장이 아닌 일반 사용자가 참여한 pendingList EXIT_ROOM 으로 변경
PendingListEntity pendingMember = pendingListRepository.findByAccompanyPostAndMember(
accompanyPost, chatRoomMember.getMember())
.orElseThrow(() -> new GlobalException(ErrorCode.PENDING_LIST_NOT_FOUND));
Expand Down

0 comments on commit 19d9ce6

Please sign in to comment.