Skip to content

Commit

Permalink
Update MessageService.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-DoHa committed Nov 23, 2022
1 parent f70f4cc commit 2647944
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +118,21 @@ public List<MessageListResponse> 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<Message> 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;
Expand Down

0 comments on commit 2647944

Please sign in to comment.