fixed bug using wrong id of message

This commit is contained in:
delvh 2020-04-09 22:31:20 +02:00
parent 97545fc285
commit 551f83672e

View File

@ -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<Message> {
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<Message> {
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<Message> {
// 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) {