Skip to content

Commit

Permalink
Fix timestamp when restoring chat rooms
Browse files Browse the repository at this point in the history
The timestamp could be wrong for some lines.
  • Loading branch information
zapek committed Jan 7, 2025
1 parent 66ed45d commit 45e5181
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 by David Gerber - https://zapek.com
* Copyright (c) 2024-2025 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
Expand All @@ -23,6 +23,6 @@

import java.time.Instant;

public record ChatRoomBacklog(Instant create, GxsId gxsId, String nickname, String message)
public record ChatRoomBacklog(Instant created, GxsId gxsId, String nickname, String message)
{
}
15 changes: 10 additions & 5 deletions ui/src/main/java/io/xeres/ui/controller/chat/ChatListView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023 by David Gerber - https://zapek.com
* Copyright (c) 2019-2025 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
Expand Down Expand Up @@ -153,9 +153,14 @@ public void addUserMessage(Instant when, String from, String message)
}

public void addUserMessage(String from, GxsId gxsId, String message)
{
addUserMessage(Instant.now(), from, gxsId, message);
}

public void addUserMessage(Instant when, String from, GxsId gxsId, String message)
{
var chatAction = new ChatAction(SAY, from, gxsId);
addMessage(Instant.now(), chatAction, message);
addMessage(when, chatAction, message);
}

private void addMessage(Instant time, ChatAction chatAction, String message)
Expand All @@ -172,7 +177,7 @@ private void addMessage(Instant time, ChatAction chatAction, String message)
var image = new Image(data);
if (!image.isError())
{
addMessageLine(chatAction, image);
addMessageLine(time, chatAction, image);
}
}
}
Expand Down Expand Up @@ -317,9 +322,9 @@ private void addMessageLine(ChatLine line)
trimScrollBackIfNeeded();
}

private void addMessageLine(ChatAction action, Image image)
private void addMessageLine(Instant when, ChatAction action, Image image)
{
var chatLine = new ChatLine(Instant.now(), action, new ContentImage(image, chatView));
var chatLine = new ChatLine(when, action, new ContentImage(image, chatView));
addMessageLine(chatLine);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,11 @@ private void fillBacklog(ChatListView chatListView, List<ChatRoomBacklog> messag
messages.forEach(message -> {
if (message.gxsId() == null)
{
chatListView.addOwnMessage(message.create(), message.message());
chatListView.addOwnMessage(message.created(), message.message());
}
else
{
chatListView.addUserMessage(message.nickname(), message.gxsId(), message.message());
chatListView.addUserMessage(message.created(), message.nickname(), message.gxsId(), message.message());
}
});
chatListView.jumpToBottom(true);
Expand Down

0 comments on commit 45e5181

Please sign in to comment.