Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ public ChatCommonDTO.MessageInfo toCommonMessageInfo(
ChatMessage message,
String senderProfileImageUrl,
List<ChatCommonDTO.ImageInfo> processedImages,
boolean isMyMessage) {
boolean isMyMessage,
boolean isSenderWithdrawn) {

return ChatCommonDTO.MessageInfo.builder()
.messageId(message.getId())
.senderId(message.getSender().getId())
.senderName(message.getSender().getMemberName())
.senderProfileImageUrl(senderProfileImageUrl)
.isSenderWithdrawn(isSenderWithdrawn)
.content(message.getContent())
.messageType(message.getType())
.images(processedImages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record MessageInfo(
Long senderId,
String senderName,
String senderProfileImageUrl,
boolean isSenderWithdrawn,
String content,
MessageType messageType,
List<ImageInfo> images,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public record MessageInfo(
Long senderId,
String senderName,
String senderProfileImageUrl,
boolean isSenderWithdrawn,
String content,
MessageType messageType,
List<ChatCommonDTO.ImageInfo> images,
Expand All @@ -35,6 +36,7 @@ public static MessageInfo from(ChatCommonDTO.MessageInfo common) {
.senderId(common.senderId())
.senderName(common.senderName())
.senderProfileImageUrl(common.senderProfileImageUrl())
.isSenderWithdrawn(common.isSenderWithdrawn())
.content(common.content())
.messageType(common.messageType())
.images(common.images())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public record MessageInfo(
Long senderId,
String senderName,
String senderProfileImageUrl,
boolean isSenderWithdrawn,
String content,
MessageType messageType,
List<ChatCommonDTO.ImageInfo> images,
Expand All @@ -47,6 +48,7 @@ public static MessageInfo from(ChatCommonDTO.MessageInfo common) {
.senderId(common.senderId())
.senderName(common.senderName())
.senderProfileImageUrl(common.senderProfileImageUrl())
.isSenderWithdrawn(common.isSenderWithdrawn())
.content(common.content())
.messageType(common.messageType())
.images(common.images())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import umc.cockple.demo.domain.image.service.ImageService;
import umc.cockple.demo.domain.member.domain.Member;
import umc.cockple.demo.domain.member.domain.ProfileImg;
import umc.cockple.demo.domain.member.enums.MemberStatus;

import java.util.Comparator;
import java.util.List;
Expand All @@ -33,7 +34,8 @@ private ChatCommonDTO.MessageInfo processAndConvertMessage(ChatMessage message,
String senderProfileImageUrl = generateProfileImageUrl(sender.getProfileImg());
List<ChatCommonDTO.ImageInfo> processedImages = processMessageImages(message);
boolean isMyMessage = isMyMessage(sender.getId(), memberId);
return chatConverter.toCommonMessageInfo(message, senderProfileImageUrl, processedImages, isMyMessage);
boolean isSenderWithdrawn = sender.getIsActive() == MemberStatus.INACTIVE;
return chatConverter.toCommonMessageInfo(message, senderProfileImageUrl, processedImages, isMyMessage, isSenderWithdrawn);
}

public String generateProfileImageUrl(ProfileImg profileImg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import umc.cockple.demo.domain.party.domain.PartyImg;
import umc.cockple.demo.domain.party.repository.PartyRepository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -102,8 +103,9 @@ public ChatRoomDetailDTO.Response getChatRoomDetail(Long roomId, Long memberId)

Pageable pageable = PageRequest.of(0, 50);
List<ChatMessage> recentMessages = findRecentMessagesWithImages(roomId, pageable);
Collections.reverse(recentMessages);
List<ChatCommonDTO.MessageInfo> commonMessages = chatProcessor.processMessages(memberId, recentMessages);
List<ChatMessage> resultMessages = new ArrayList<>(recentMessages);
Collections.reverse(resultMessages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거는 머하는 메서드예요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

궁금해서...안써봐서...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그 Collection 중에 순서가 있는 자료형에서 그 순서를 역으로 돌리는? 메서드입니다.

List<ChatCommonDTO.MessageInfo> commonMessages = chatProcessor.processMessages(memberId, resultMessages);
List<ChatRoomDetailDTO.MessageInfo> messageInfos = chatConverter.toChatRoomDetailMessageInfos(commonMessages);

List<ChatRoomMember> participants = findChatRoomMembersWithMemberOrThrow(roomId);
Expand All @@ -126,18 +128,18 @@ public ChatMessageDTO.Response getChatMessages(Long roomId, Long memberId, Long
List<ChatMessage> messages = findMessagesWithCursor(roomId, cursor, pageable);

boolean hasNext = messages.size() > size;
if (hasNext) {
messages = messages.subList(0, size);
}
List<ChatMessage> resultMessages = hasNext
? new ArrayList<>(messages.subList(0, size))
: new ArrayList<>(messages);

Collections.reverse(messages);
List<ChatCommonDTO.MessageInfo> commonMessages = chatProcessor.processMessages(memberId, messages);
Collections.reverse(resultMessages);
List<ChatCommonDTO.MessageInfo> commonMessages = chatProcessor.processMessages(memberId, resultMessages);
List<ChatMessageDTO.MessageInfo> messageInfos = chatConverter.toChatMessageInfos(commonMessages);

Long nextCursor = hasNext && !messages.isEmpty()
? messages.get(0).getId() : null;
Long nextCursor = hasNext && !resultMessages.isEmpty()
? resultMessages.get(0).getId() : null;

log.info("[채팅방 과거 메시지 조회 완료] - 메시지 수: {}, hasNext: {}", messages.size(), hasNext);
log.info("[채팅방 과거 메시지 조회 완료] - 메시지 수: {}, hasNext: {}", resultMessages.size(), hasNext);

return chatConverter.toChatMessageResponse(messageInfos, hasNext, nextCursor);
}
Expand Down
Loading