+ * Provides the list of messages that the recipient receives. + *
* Saves the Messages in the corresponding chat at that Point.
*
* @param recipient the user who receives the messages
+ * @param sender the user who is logged in as sender on this instance of
+ * envoy.client
* @since Envoy Client v0.1-alpha
*/
- public Chat(Contact recipient) { this.recipient = recipient; }
+ public Chat(Contact recipient, Contact sender) {
+ this.recipient = recipient;
+ this.sender = sender;
+ }
@Override
public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); }
@@ -78,10 +87,22 @@ public final class Chat implements Serializable {
public void read(WriteProxy writeProxy) throws IOException {
for (int i = messages.size() - 1; i >= 0; --i) {
final Message m = messages.get(i);
- if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break;
- else {
- m.setStatus(MessageStatus.READ);
- writeProxy.writeMessageStatusChange(new MessageStatusChange(m));
+ if(m.getClass().equals(GroupMessage.class)) {
+ GroupMessage g = (GroupMessage) m;
+ if (g.getSenderID() != sender.getID()) {
+ if (g.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break;
+ else {
+ g.getMemberStatuses().replace(sender.getID(), MessageStatus.READ);
+ writeProxy.writeMessageStatusChange(
+ new GroupMessageStatusChange(g.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID()));
+ }
+ }
+ }else {
+ if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break;
+ else {
+ m.setStatus(MessageStatus.READ);
+ writeProxy.writeMessageStatusChange(new MessageStatusChange(m));
+ }
}
}
}
diff --git a/src/main/java/envoy/client/data/LocalDB.java b/src/main/java/envoy/client/data/LocalDB.java
index d8993f5..315b27d 100644
--- a/src/main/java/envoy/client/data/LocalDB.java
+++ b/src/main/java/envoy/client/data/LocalDB.java
@@ -82,7 +82,7 @@ public abstract class LocalDB {
getChat(contact.getID()).ifPresent(chat -> { ((User) chat.getRecipient()).setStatus(((User) contact).getStatus()); });
// Create missing chats
- user.getContacts().stream().filter(u -> !u.equals(user) && getChat(u.getID()).isEmpty()).map(Chat::new).forEach(chats::add);
+ user.getContacts().stream().filter(u -> !u.equals(user) && getChat(u.getID()).isEmpty()).map(u -> new Chat(u, user)).forEach(chats::add);
}
/**
diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java
index a092234..c3aa608 100644
--- a/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -146,7 +146,7 @@ public final class ChatScene {
switch (e.getOperationType()) {
case ADD:
localDB.getUsers().put(contact.getName(), contact);
- localDB.getChats().add(new Chat(contact));
+ localDB.getChats().add(new Chat(contact, client.getSender()));
Platform.runLater(() -> userList.getItems().add(contact));
break;
case REMOVE:
From 96fc06a8e5112ee54ebb8a2873a29217d3c0e905 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Sat, 4 Jul 2020 15:43:46 +0200
Subject: [PATCH 5/9] Implemented GroupMessageStatusChangeProcessor and a Cache
for those
---
src/main/java/envoy/client/net/Client.java | 17 +++++++----
.../GroupMessageStatusChangeProcessor.java | 29 +++++++++++++++++++
src/main/java/envoy/client/ui/Startup.java | 6 +++-
.../envoy/client/ui/controller/ChatScene.java | 12 +++++---
.../client/ui/controller/LoginScene.java | 22 ++++++++++----
5 files changed, 69 insertions(+), 17 deletions(-)
create mode 100644 src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java
diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java
index cf41d93..fb4f114 100644
--- a/src/main/java/envoy/client/net/Client.java
+++ b/src/main/java/envoy/client/net/Client.java
@@ -75,7 +75,8 @@ public class Client implements Closeable {
* waiting for the handshake response
*/
public void performHandshake(LoginCredentials credentials, Cache
* Project: envoy-client
+ * File: GroupMessageStatusChangePocessor.java
+ * Created: 03.07.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Client v0.1-beta
+ */
+public class GroupMessageStatusChangeProcessor implements Consumer
+ * File: GroupChat.java
+ * Created: 05.07.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Client v0.1-beta
+ */
+public class GroupChat extends Chat {
+
+ private final User sender;
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param sender the user sending the messages
+ * @param recipient the user who receives the messages
+ * @since Envoy Client v0.1-beta
+ */
+ public GroupChat(User sender, Contact recipient) {
+ super(recipient);
+ this.sender = sender;
+ }
+
+ @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;
+ else {
+ g.getMemberStatuses().replace(sender.getID(), MessageStatus.READ);
+ writeProxy
+ .writeMessageStatusChange(new GroupMessageStatusChange(g.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID()));
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/envoy/client/data/LocalDB.java b/src/main/java/envoy/client/data/LocalDB.java
index 315b27d..7899510 100644
--- a/src/main/java/envoy/client/data/LocalDB.java
+++ b/src/main/java/envoy/client/data/LocalDB.java
@@ -82,7 +82,11 @@ public abstract class LocalDB {
getChat(contact.getID()).ifPresent(chat -> { ((User) chat.getRecipient()).setStatus(((User) contact).getStatus()); });
// Create missing chats
- user.getContacts().stream().filter(u -> !u.equals(user) && getChat(u.getID()).isEmpty()).map(u -> new Chat(u, user)).forEach(chats::add);
+ user.getContacts()
+ .stream()
+ .filter(c -> !c.equals(user) && getChat(c.getID()).isEmpty())
+ .map(c -> c instanceof User ? new Chat(c) : new GroupChat(user, c))
+ .forEach(chats::add);
}
/**
diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java
index d89a28c..68449b4 100644
--- a/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -17,9 +17,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
-import envoy.client.data.Chat;
-import envoy.client.data.LocalDB;
-import envoy.client.data.Settings;
+import envoy.client.data.*;
import envoy.client.event.MessageCreationEvent;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
@@ -143,7 +141,7 @@ public final class ChatScene implements Restorable {
switch (e.getOperationType()) {
case ADD:
localDB.getUsers().put(contact.getName(), contact);
- localDB.getChats().add(new Chat(contact, client.getSender()));
+ localDB.getChats().add(contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact));
Platform.runLater(() -> userList.getItems().add(contact));
break;
case REMOVE:
From a8443e6a50db9ee520b6e59080e9bbbe00eb731d 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 9/9] 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.
+ *
* 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