From 973fd69cf2d80f20d72dd23487abeca8971cf466 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Wed, 8 Jul 2020 14:15:44 +0200 Subject: [PATCH] Applied suggestions from @delvh --- .../java/envoy/client/data/GroupChat.java | 15 ++-- src/main/java/envoy/client/net/Client.java | 88 +++++++++++-------- .../envoy/client/ui/controller/ChatScene.java | 9 +- .../client/ui/controller/LoginScene.java | 38 ++++---- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/src/main/java/envoy/client/data/GroupChat.java b/src/main/java/envoy/client/data/GroupChat.java index 4f29eb6..3c1e98d 100644 --- a/src/main/java/envoy/client/data/GroupChat.java +++ b/src/main/java/envoy/client/data/GroupChat.java @@ -11,6 +11,9 @@ import envoy.data.User; import envoy.event.GroupMessageStatusChange; /** + * Represents a chat between a user and a group + * as a list of messages. + *

* Project: envoy-client
* File: GroupChat.java
* Created: 05.07.2020
@@ -26,7 +29,7 @@ public class GroupChat extends Chat { /** * @param sender the user sending the messages - * @param recipient the user who receives the messages + * @param recipient the group whose members receive the messages * @since Envoy Client v0.1-beta */ public GroupChat(User sender, Contact recipient) { @@ -37,13 +40,13 @@ public class GroupChat extends Chat { @Override public void read(WriteProxy writeProxy) throws IOException { for (int i = messages.size() - 1; i >= 0; --i) { - final GroupMessage g = (GroupMessage) messages.get(i); - if (g.getSenderID() != sender.getID()) { - if (g.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; + final GroupMessage gmsg = (GroupMessage) messages.get(i); + if (gmsg.getSenderID() != sender.getID()) { + if (gmsg.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; else { - g.getMemberStatuses().replace(sender.getID(), MessageStatus.READ); + gmsg.getMemberStatuses().replace(sender.getID(), MessageStatus.READ); writeProxy - .writeMessageStatusChange(new GroupMessageStatusChange(g.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID())); + .writeMessageStatusChange(new GroupMessageStatusChange(gmsg.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID())); } } } diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index fb4f114..7348abe 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -53,22 +53,26 @@ public class Client implements Closeable { * will block for up to 5 seconds. If the handshake does exceed this time limit, * an exception is thrown. * - * @param credentials the login credentials of the user - * @param receivedMessageCache a message cache containing all unread - * messages - * from the server that can be relayed - * after - * initialization - * @param receivedGroupMessageCache a groupMessage cache containing all - * unread - * groupMessages - * from the server that can be relayed - * after - * initialization - * @param receivedMessageStatusChangeCache an event cache containing all - * received messageStatusChangeEvents - * from the server that can be relayed - * after initialization + * @param credentials the login credentials of the + * user + * @param receivedMessageCache a message cache containing all + * unread messages from the server + * that can be relayed after + * initialization + * @param receivedGroupMessageCache a groupMessage cache containing + * all unread groupMessages from + * the server that can be relayed + * after initialization + * @param receivedMessageStatusChangeCache an event cache containing all + * received + * messageStatusChangeEvents from + * the server that can be relayed + * after initialization + * @param receivedGroupMessageStatusChangeCache an event cache containing all + * received + * groupMessageStatusChangeEvents + * from the server that can be + * relayed after initialization * @throws TimeoutException if the server could not be reached * @throws IOException if the login credentials could not be written * @throws InterruptedException if the current thread is interrupted while @@ -131,24 +135,36 @@ public class Client implements Closeable { * Initializes the {@link Receiver} used to process data sent from the server to * this client. * - * @param localDB the local database used to persist - * the current - * {@link IDGenerator} - * @param receivedMessageCache a message cache containing all unread - * messages - * from the server that can be relayed - * after - * initialization - * @param receivedGroupMessageCache a groupMessage cache containing all - * unread - * groupMessages - * from the server that can be relayed - * after - * initialization - * @param receivedMessageStatusChangeCache an event cache containing all - * received messageStatusChangeEvents - * from the server that can be relayed - * after initialization + * @param localDB the local database used to + * persist + * the current + * {@link IDGenerator} + * @param receivedMessageCache a message cache containing all + * unread + * messages + * from the server that can be + * relayed + * after + * initialization + * @param receivedGroupMessageCache a groupMessage cache containing + * all + * unread + * groupMessages + * from the server that can be + * relayed + * after + * initialization + * @param receivedMessageStatusChangeCache an event cache containing all + * received + * messageStatusChangeEvents + * from the server that can be + * relayed + * after initialization + * @param receivedGroupMessageStatusChangeCache an event cache containing all + * received + * groupMessageStatusChangeEvents + * from the server that can be + * relayed after initialization * @throws IOException if no {@link IDGenerator} is present and none could be * requested from the server * @since Envoy Client v0.2-alpha @@ -159,8 +175,8 @@ public class Client implements Closeable { checkOnline(); // Process incoming messages - final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor(); - final ReceivedGroupMessageProcessor receivedGroupMessageProcessor = new ReceivedGroupMessageProcessor(); + final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor(); + final ReceivedGroupMessageProcessor receivedGroupMessageProcessor = new ReceivedGroupMessageProcessor(); final MessageStatusChangeProcessor messageStatusChangeProcessor = new MessageStatusChangeProcessor(); final GroupMessageStatusChangeProcessor groupMessageStatusChangeProcessor = new GroupMessageStatusChangeProcessor(); diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index ccc9380..8b05221 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -29,8 +29,8 @@ import envoy.client.ui.listcell.ContactListCellFactory; import envoy.client.ui.listcell.MessageControl; import envoy.client.ui.listcell.MessageListCellFactory; import envoy.data.*; -import envoy.event.*; import envoy.data.Attachment.AttachmentType; +import envoy.event.*; import envoy.event.contact.ContactOperation; import envoy.exception.EnvoyException; import envoy.util.EnvoyLog; @@ -135,7 +135,7 @@ public final class ChatScene implements Restorable { eventBus.register(GroupMessageStatusChange.class, e -> localDB.getMessage(e.getID()).ifPresent(groupMessage -> { ((GroupMessage) groupMessage).getMemberStatuses().replace(e.getMemberID(), e.get()); - // Update UI id in current chat + // Update UI if in current chat if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh); })); @@ -355,9 +355,8 @@ public final class ChatScene implements Restorable { } /** - * Sends a new message or groupMessage to the server based on the text entered - * in the - * messageTextArea. + * Sends a new {@link Message} or {@link GroupMessage} to the server based on + * the text entered in the {@code messageTextArea} and the given attachment. * * @since Envoy Client v0.1-beta */ diff --git a/src/main/java/envoy/client/ui/controller/LoginScene.java b/src/main/java/envoy/client/ui/controller/LoginScene.java index c59dc4b..897cd08 100644 --- a/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -75,21 +75,29 @@ public final class LoginScene { /** * Loads the login dialog using the FXML file {@code LoginDialog.fxml}. * - * @param client the client used to perform the - * handshake - * @param localDB the local database used for offline - * login - * @param receivedMessageCache the cache storing messages received - * during - * the handshake - * @param receivedGroupMessageCache the cache storing groupMessages - * received during the handshake - * @param receivedMessageStatusChangeCache the cache storing - * messageStatusChangeEvents received - * during handshake - * @param sceneContext the scene context used to initialize - * the chat - * scene + * @param client the client used to perform the + * handshake + * @param localDB the local database used for + * offline + * login + * @param receivedMessageCache the cache storing messages + * received + * during + * the handshake + * @param receivedGroupMessageCache the cache storing groupMessages + * received during the handshake + * @param receivedMessageStatusChangeCache the cache storing + * messageStatusChangeEvents + * received + * during handshake + * @param receivedGroupMessageStatusChangeCache the cache storing + * groupMessageStatusChangeEvents + * received + * during handshake + * @param sceneContext the scene context used to + * initialize + * the chat + * scene * @since Envoy Client v0.1-beta */ public void initializeData(Client client, LocalDB localDB, Cache receivedMessageCache, Cache receivedGroupMessageCache,