Skip to content

Commit

Permalink
Merge pull request #91 from catchroom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sungjiwoon authored Jan 27, 2024
2 parents ddfebe3 + d11b534 commit 626cff2
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.catchroom.chat.message.service.ChatService;
import com.catchroom.chat.message.type.MessageType;
import java.util.ArrayList;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -109,19 +110,17 @@ private void setListChatLastMessage(ChatRoomListGetResponse chatRoomListGetRespo
public void sortChatRoomListLatest (
List<ChatRoomListGetResponse> chatRoomListGetResponseList
) {
Comparator<ChatRoomListGetResponse> comparator = (o1, o2) -> {

if (o1.getLastChatmessageDto() != null && o2.getLastChatmessageDto() != null) {
return LocalDateTime.parse(o2.getLastChatmessageDto().getTime()).withNano(0)
.compareTo(
LocalDateTime.parse(o1.getLastChatmessageDto().getTime()).withNano(0)
);
} else {
return 0;
}
};

Collections.sort(chatRoomListGetResponseList,comparator);
chatRoomListGetResponseList = chatRoomListGetResponseList.stream()
.filter(it -> it.getLastChatmessageDto() != null)
.collect(Collectors.toList());

Comparator<ChatRoomListGetResponse> comparator = (o1, o2) ->
LocalDateTime.parse(o2.getLastChatmessageDto().getTime()).withNano(0)
.compareTo(
LocalDateTime.parse(o1.getLastChatmessageDto().getTime()).withNano(0)
);

Collections.sort(chatRoomListGetResponseList, comparator);
}

/**
Expand Down

0 comments on commit 626cff2

Please sign in to comment.