Skip to content

Commit

Permalink
reversed order of messages
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kuba committed Jan 13, 2023
1 parent 57196a6 commit 9299c7e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<StoredMessage> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void chat(HttpServletResponse res) throws IOException {
// prevent race condition on concurrent accesses
List<StoredMessage> 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("<div class=\"message\" style=\"" +
"margin: 10px ; padding: 10px " +
Expand Down

0 comments on commit 9299c7e

Please sign in to comment.