feat: `Chatroom.getMessages()` is fully paginated (takes first and last)
authorKai Moritz <kai@juplo.de>
Wed, 28 Dec 2022 16:20:53 +0000 (17:20 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 15 Jan 2023 18:35:59 +0000 (19:35 +0100)
src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java

index 62c9732..115dcd6 100644 (file)
@@ -72,12 +72,16 @@ public class Chatroom
     return sink.asFlux();
   }
 
-  public Stream<Message> getMessages(long firstMessage)
+  public Stream<Message> getMessages(long first, long last)
   {
     return messages
         .values()
         .stream()
-        .filter(message -> message.getSerialNumber() >= firstMessage);
+        .filter(message ->
+        {
+          long serial = message.getSerialNumber();
+          return serial >= first && serial <= last;
+        });
   }