diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java
index 9f9dad7..f7f38a6 100644
--- a/src/main/java/envoy/client/net/Client.java
+++ b/src/main/java/envoy/client/net/Client.java
@@ -139,6 +139,9 @@ public class Client implements Closeable {
final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor();
final MessageStatusChangeEventProcessor messageStatusChangeEventProcessor = new MessageStatusChangeEventProcessor();
+ // TODO: Define a cache
+ receiver.registerProcessor(GroupMessage.class, new ReceivedGroupMessageProcessor());
+
receiver.registerProcessor(Message.class, receivedMessageProcessor);
// Relay cached unread messages
diff --git a/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java b/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java
new file mode 100644
index 0000000..877d0f0
--- /dev/null
+++ b/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java
@@ -0,0 +1,33 @@
+package envoy.client.net;
+
+import java.util.function.Consumer;
+import java.util.logging.Logger;
+
+import envoy.client.event.MessageCreationEvent;
+import envoy.data.GroupMessage;
+import envoy.data.Message.MessageStatus;
+import envoy.event.EventBus;
+import envoy.util.EnvoyLog;
+
+/**
+ * Project: envoy-client
+ * File: ReceivedGroupMessageProcessor.java
+ * Created: 13.06.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Client v0.1-beta
+ */
+public class ReceivedGroupMessageProcessor implements Consumer {
+
+ private static final Logger logger = EnvoyLog.getLogger(ReceivedGroupMessageProcessor.class);
+
+ @Override
+ public void accept(GroupMessage groupMessage) {
+ if (groupMessage.getStatus() == MessageStatus.WAITING || groupMessage.getStatus() == MessageStatus.READ)
+ logger.warning("The groupMessage has the unexpected status " + groupMessage.getStatus());
+
+ // Dispatch event
+ EventBus.getInstance().dispatch(new MessageCreationEvent(groupMessage));
+ }
+
+}
diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java
index cc6b018..48347e7 100644
--- a/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -88,13 +88,23 @@ public final class ChatScene {
// Listen to received messages
eventBus.register(MessageCreationEvent.class, e -> {
final var message = e.get();
- localDB.getChat(message.getSenderID()).ifPresent(chat -> {
- chat.getMessages().add(message);
+ if (message.getClass().equals(Message.class)) {
+ localDB.getChat(message.getSenderID()).ifPresent(chat -> {
+ chat.getMessages().add(message);
// Update UI if in current chat
if (chat == currentChat)
Platform.runLater(messageList::refresh);
- });
+ });
+ } else {
+ localDB.getChat(message.getRecipientID()).ifPresent(chat -> {
+ chat.getMessages().add(message);
+
+ // Update UI if in current chat
+ if (chat == currentChat)
+ Platform.runLater(messageList::refresh);
+ });
+ }
});
// Listen to message status changes