From 003b5438053d921ce4c5d649f4f38082cf19cfd9 Mon Sep 17 00:00:00 2001 From: HyemIin Date: Sat, 20 Jan 2024 16:37:20 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20:=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B5=9C=EC=8B=A0=EC=88=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EB=A1=9C=EC=A7=81=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Comparator 활용 - null 처리(임시) --- .../chat/global/pubsub/RedisSubscriber.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java b/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java index 913cd66..02842aa 100644 --- a/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java +++ b/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java @@ -48,8 +48,17 @@ public void sendRoomList(String publishMessage) { ChatMessageDto chatMessage = objectMapper.readValue(publishMessage, MessageSubDto.class).getChatMessageDto(); List chatRoomListGetResponseList = objectMapper.readValue(publishMessage, MessageSubDto.class) .getList(); - - Collections.sort(chatRoomListGetResponseList, new ChatRoomListGetResponseComparator()); + Comparator comparator = new Comparator() { + @Override + public int compare(ChatRoomListGetResponse o1, ChatRoomListGetResponse o2) { + if (o1.getChatMessageDto() != null && o2.getChatMessageDto() != null) { + return LocalDateTime.parse(o1.getChatMessageDto().getTime()).withNano(0).compareTo(LocalDateTime.parse(o2.getChatMessageDto().getTime()).withNano(0)); + } else { + return 0; + } + } + }; + Collections.sort(chatRoomListGetResponseList,comparator); // 로그인 유저 채팅방 리스트 최신화 messagingTemplate.convertAndSend("/sub/chat/roomlist/" + chatMessage.getUserId(), chatRoomListGetResponseList); } catch (Exception e) { @@ -59,12 +68,3 @@ public void sendRoomList(String publishMessage) { } -class ChatRoomListGetResponseComparator implements Comparator { - @Override - public int compare(ChatRoomListGetResponse response1, ChatRoomListGetResponse response2) { - LocalDateTime time1 = LocalDateTime.parse(response1.getChatMessageDto().getTime()); - LocalDateTime time2 = LocalDateTime.parse(response2.getChatMessageDto().getTime()); - return time1.compareTo(time2); - } -} -