From: Kai Moritz Date: Wed, 28 Dec 2022 16:20:53 +0000 (+0100) Subject: feat: `Chatroom.getMessages()` is fully paginated (takes first and last) X-Git-Tag: wip~95 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=93f9e5cea5fb73d35d6df60518533cdd7cc9d12d;p=demos%2Fkafka%2Fchat feat: `Chatroom.getMessages()` is fully paginated (takes first and last) --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java index 62c97327..115dcd69 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java @@ -72,12 +72,16 @@ public class Chatroom return sink.asFlux(); } - public Stream getMessages(long firstMessage) + public Stream 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; + }); }