From 551f83672e22a105b44d741d8c1856d8dd8ca5c0 Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 9 Apr 2020 22:31:20 +0200 Subject: [PATCH] fixed bug using wrong id of message --- .../envoy/server/processors/MessageProcessor.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java index c265ee2..dff28ec 100755 --- a/src/main/java/envoy/server/processors/MessageProcessor.java +++ b/src/main/java/envoy/server/processors/MessageProcessor.java @@ -3,6 +3,8 @@ package envoy.server.processors; import java.io.IOException; import java.util.Date; +import javax.persistence.EntityExistsException; + import envoy.data.Message; import envoy.data.Message.MessageStatus; import envoy.data.MessageBuilder; @@ -29,10 +31,9 @@ public class MessageProcessor implements ObjectProcessor { public void process(Message message, long socketID, ObjectWriteProxy writeProxy) { message.nextStatus(); ConnectionManager connectionManager = ConnectionManager.getInstance(); - Contact recipient = PersistenceManager.getInstance().getContactByID(message.getID()); + Contact recipient = PersistenceManager.getInstance().getContactByID(message.getRecipientID()); if (recipient instanceof envoy.server.data.User) { - System.out.println("The received message is a direct message."); sendToUser(connectionManager, message, writeProxy); // Sending a messageStatusChangeEvent to the sender try { @@ -42,7 +43,6 @@ public class MessageProcessor implements ObjectProcessor { e.printStackTrace(); } } else { - System.out.println("The received message is a group message."); final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts(); final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size()); members.forEach(user -> { @@ -59,7 +59,11 @@ public class MessageProcessor implements ObjectProcessor { // copies of the original message. (Not at this location) }); } - PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message)); + try { + PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message)); + } catch (EntityExistsException e) { + System.err.println("Received a message with an id that already exists"); + } } private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {