From 2647944cc7fdf646168de66f7d1ff86f91c32970 Mon Sep 17 00:00:00 2001 From: Lee-DoHa Date: Thu, 24 Nov 2022 02:02:20 +0900 Subject: [PATCH] Update MessageService.java --- .../csletter/message/service/MessageService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/project/csletter/message/service/MessageService.java b/src/main/java/com/project/csletter/message/service/MessageService.java index 74f2c94..8e6a7a2 100644 --- a/src/main/java/com/project/csletter/message/service/MessageService.java +++ b/src/main/java/com/project/csletter/message/service/MessageService.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import static java.lang.Math.min; @@ -117,6 +118,21 @@ public List getMessageFeed(Long cursor, Pageable pageable, f.setBody(Collections.singletonList(f.getBody().get(0).length() > 20 ? initialList(f.getBody().get(0)).substring(0, 20) : initialList(f.getBody().get(0)))); f.setHaveNextMessage(!messageRepository.mainFeedLess(memberToken, f.getMessageId(), pageable).isEmpty()); + + if(cursor == 0) { + f.setPrevCursor(null); + }else { + List messages = messageRepository.prevCursor(memberToken, mainList.get(0).getMessageId(), Pageable.ofSize(7)); + if (Objects.equals(messages.get(messages.size() - 1).getId(), messageRepository.mainFeed(memberToken, pageable).get(0).getId())) { + f.setPrevCursor(0L); + } else { + f.setPrevCursor(messages.get(messages.size() - 1).getId()); + } + } + + + + f.setNextCursor(mainList.get(mainList.size()-1).getMessageId()); }); return mainList;