fixed bug using wrong id of message
This commit is contained in:
parent
0704f9a5c3
commit
cba20900ba
@ -3,6 +3,8 @@ package envoy.server.processors;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.EntityExistsException;
|
||||||
|
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.data.MessageBuilder;
|
import envoy.data.MessageBuilder;
|
||||||
@ -29,10 +31,9 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
|
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
|
||||||
message.nextStatus();
|
message.nextStatus();
|
||||||
ConnectionManager connectionManager = ConnectionManager.getInstance();
|
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) {
|
if (recipient instanceof envoy.server.data.User) {
|
||||||
System.out.println("The received message is a direct message.");
|
|
||||||
sendToUser(connectionManager, message, writeProxy);
|
sendToUser(connectionManager, message, writeProxy);
|
||||||
// Sending a messageStatusChangeEvent to the sender
|
// Sending a messageStatusChangeEvent to the sender
|
||||||
try {
|
try {
|
||||||
@ -42,7 +43,6 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("The received message is a group message.");
|
|
||||||
final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
|
final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
|
||||||
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
|
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
|
||||||
members.forEach(user -> {
|
members.forEach(user -> {
|
||||||
@ -59,7 +59,11 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
// copies of the original message. (Not at this location)
|
// 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) {
|
private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {
|
||||||
|
Reference in New Issue
Block a user