diff --git a/chat-server/src/main/java/cz/muni/chat/server/rest/ChatRestController.java b/chat-server/src/main/java/cz/muni/chat/server/rest/ChatRestController.java index ad9cc4d..5cc4a54 100644 --- a/chat-server/src/main/java/cz/muni/chat/server/rest/ChatRestController.java +++ b/chat-server/src/main/java/cz/muni/chat/server/rest/ChatRestController.java @@ -98,7 +98,7 @@ public ChatRestController(ChatService chatService) { @Operation( // metadata for inclusion into OpenAPI document summary = "Get all messages", description = """ - Returns an array of objects representing chat messages, ordered from the oldest to the newest. + Returns an array of objects representing chat messages, ordered from the newest to the oldest. Each message must have a **text** and **timestamp**, and optionally may have an **author**, a **text color** and a **background color**. It is possible to use [MarkDown](https://www.markdownguide.org/) in descriptions. @@ -187,7 +187,7 @@ public ChatMessage createMessage(@Valid @RequestBody NewChatMessageRequest r, @Operation( summary = "Paged messages", description = """ - Returns a page of chat messages. + Returns a page of chat messages. Messages are ordered from the newest to the oldest. The parameter `page` specifies zero-based index of the requested page, and the parameter `size` specifies the size of the page. """) diff --git a/chat-server/src/main/java/cz/muni/chat/server/service/ChatServiceImpl.java b/chat-server/src/main/java/cz/muni/chat/server/service/ChatServiceImpl.java index e2522db..ff00da0 100644 --- a/chat-server/src/main/java/cz/muni/chat/server/service/ChatServiceImpl.java +++ b/chat-server/src/main/java/cz/muni/chat/server/service/ChatServiceImpl.java @@ -36,7 +36,7 @@ public List getAllChatMessages() { public StoredMessage createNewChatMessage(String text, String author, String textColor, String backgroundColor) { UUID uuid = UUID.randomUUID(); StoredMessage c = new StoredMessage(uuid.toString(), ZonedDateTime.now(), text, author, textColor, backgroundColor); - messages.add(c); + messages.add(0, c); return c; } diff --git a/chat-server/src/main/java/cz/muni/chat/server/ui/ChatUIController.java b/chat-server/src/main/java/cz/muni/chat/server/ui/ChatUIController.java index ecc9787..8b14de4 100644 --- a/chat-server/src/main/java/cz/muni/chat/server/ui/ChatUIController.java +++ b/chat-server/src/main/java/cz/muni/chat/server/ui/ChatUIController.java @@ -40,7 +40,7 @@ public void chat(HttpServletResponse res) throws IOException { // prevent race condition on concurrent accesses List chatMessages = chatService.getAllChatMessages(); // iterate messages in reverse order - for (int i = chatMessages.size(); i-- > 0; ) { + for (int i = 0 ; i < chatMessages.size(); i++) { StoredMessage cm = chatMessages.get(i); out.println("