From 3c8a5c7abbf4ada74397064e50c1637e53d14641 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Fri, 3 Jul 2020 16:25:49 +0200
Subject: [PATCH] Implemented GroupMessageStatusChange handling (not with
pending yet)
---
src/main/java/envoy/server/Startup.java | 2 +
.../GroupMessageStatusChangeProcessor.java | 69 +++++++++++++++++++
.../MessageStatusChangeProcessor.java | 3 +
3 files changed, 74 insertions(+)
create mode 100644 src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index 3aaaf64..8991667 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -18,6 +18,7 @@ import envoy.server.processors.ContactOperationProcessor;
import envoy.server.processors.ContactSearchProcessor;
import envoy.server.processors.GroupCreationProcessor;
import envoy.server.processors.GroupMessageProcessor;
+import envoy.server.processors.GroupMessageStatusChangeProcessor;
import envoy.server.processors.IDGeneratorRequestProcessor;
import envoy.server.processors.LoginCredentialProcessor;
import envoy.server.processors.MessageProcessor;
@@ -72,6 +73,7 @@ public class Startup {
new GroupMessageProcessor(),
new GroupCreationProcessor(),
new MessageStatusChangeProcessor(),
+ new GroupMessageStatusChangeProcessor(),
new UserStatusChangeProcessor(),
new IDGeneratorRequestProcessor(),
new ContactSearchProcessor(),
diff --git a/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java
new file mode 100644
index 0000000..1dc37eb
--- /dev/null
+++ b/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java
@@ -0,0 +1,69 @@
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.data.Message.MessageStatus;
+import envoy.event.GroupMessageStatusChange;
+import envoy.event.MessageStatusChange;
+import envoy.exception.EnvoyException;
+import envoy.server.data.GroupMessage;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupMessageStatusChangeProcessor.java
+ * Created: 03.07.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupMessageStatusChangeProcessor implements ObjectProcessor {
+
+ private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ private final ConnectionManager connectionManager = ConnectionManager.getInstance();
+
+ @Override
+ public void process(GroupMessageStatusChange input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ GroupMessage gmsg = (GroupMessage) persistenceManager.getMessageByID(input.getID());
+ if (gmsg.getStatus() == input.get())
+ throw new IOException(new EnvoyException("The groupMessage already has the status " + input.get()));
+
+ gmsg.getMemberMessageStatus().replace(input.getMemberID(), input.get());
+
+ // Notifying the other members about memberStatusChange
+ gmsg.getMemberMessageStatus().keySet().stream().filter(k -> connectionManager.getUserIdBySocketID(socketID) != k).forEach(k -> {
+ if(connectionManager.isOnline(k)) {
+ try {
+ writeProxy.write(connectionManager.getSocketID(k), input);
+ } catch (IOException e) {
+ // TODO Maybe Try Catch block is not necessarily needed but if so write proper
+ // logger statement here.
+ e.printStackTrace();
+ }
+ }
+ });
+
+ if (!gmsg.getMemberMessageStatus().containsValue(MessageStatus.SENT)
+ && !gmsg.getMemberMessageStatus().containsValue(MessageStatus.RECEIVED)) {
+ gmsg.read();
+ // Notifying the other members about messageStatusChange
+ gmsg.getMemberMessageStatus().keySet().forEach(k -> {
+ if (connectionManager.isOnline(k)) {
+ try {
+ writeProxy.write(connectionManager.getSocketID(k), new MessageStatusChange(input.getID(), input.get(), input.getDate()));
+ } catch (IOException e) {
+ // TODO Maybe Try Catch block is not necessarily needed but if so write proper
+ // logger statement here.
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ persistenceManager.updateMessage(gmsg);
+ }
+
+ @Override
+ public Class getInputClass() { return GroupMessageStatusChange.class; }
+}
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index 8801d54..f4e2312 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -3,6 +3,7 @@ package envoy.server.processors;
import java.io.IOException;
import envoy.data.Message.MessageStatus;
+import envoy.event.GroupMessageStatusChange;
import envoy.event.MessageStatusChange;
import envoy.exception.EnvoyException;
import envoy.server.data.PersistenceManager;
@@ -24,6 +25,8 @@ public class MessageStatusChangeProcessor implements ObjectProcessor