Merge pull request #169 from informatik-ag-ngl/f/message_order
Fix message order with insertion method
This commit is contained in:
commit
3bcd40d49e
@ -32,7 +32,8 @@ public final class Chat implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Provides the list of messages that the recipient receives.<p>
|
||||
* Provides the list of messages that the recipient receives.
|
||||
* <p>
|
||||
* Saves the Messages in the corresponding chat at that Point.
|
||||
*
|
||||
* @param recipient the user who receives the messages
|
||||
@ -93,6 +94,21 @@ public final class Chat implements Serializable {
|
||||
*/
|
||||
public boolean isUnread() { return !messages.isEmpty() && messages.get(messages.size() - 1).getStatus() != MessageStatus.READ; }
|
||||
|
||||
/**
|
||||
* Inserts a message at the correct place according to its creation date.
|
||||
*
|
||||
* @param message the message to insert
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
public void insert(Message message) {
|
||||
for (int i = messages.size() - 1; i >= 0; --i)
|
||||
if (message.getCreationDate().isAfter(messages.get(i).getCreationDate())) {
|
||||
messages.add(i + 1, message);
|
||||
return;
|
||||
}
|
||||
messages.add(0, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all messages in the current chat
|
||||
* @since Envoy Client v0.1-beta
|
||||
|
@ -101,7 +101,7 @@ public final class ChatScene {
|
||||
eventBus.register(MessageCreationEvent.class, e -> {
|
||||
final var message = e.get();
|
||||
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
||||
chat.getMessages().add(message);
|
||||
chat.insert(message);
|
||||
|
||||
if (chat.equals(currentChat)) {
|
||||
try {
|
||||
@ -317,7 +317,8 @@ public final class ChatScene {
|
||||
writeProxy.writeMessage(message);
|
||||
|
||||
// Add message to LocalDB and update UI
|
||||
messageList.getItems().add(message);
|
||||
currentChat.insert(message);
|
||||
messageList.refresh();
|
||||
scrollToMessageListEnd();
|
||||
|
||||
// Request a new ID generator if all IDs were used
|
||||
|
@ -151,8 +151,7 @@ public final class LoginScene {
|
||||
loadChatScene();
|
||||
}
|
||||
} catch (IOException | InterruptedException | TimeoutException e) {
|
||||
logger.log(Level.WARNING, "Could not connect to server: ", e);
|
||||
logger.log(Level.FINER, "Attempting offline mode...");
|
||||
logger.log(Level.INFO, "Could not connect to server. Entering offline mode...");
|
||||
attemptOfflineMode(credentials);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user