diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java index fbf39df..7bcc72a 100644 --- a/src/main/java/envoy/server/processors/GroupResizeProcessor.java +++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java @@ -18,23 +18,30 @@ import envoy.server.net.ObjectWriteProxy; */ public class GroupResizeProcessor implements ObjectProcessor { - PersistenceManager persistenceManager = PersistenceManager.getInstance(); - ConnectionManager connectionManager = ConnectionManager.getInstance(); + private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); + private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); @Override public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException { - envoy.server.data.Group group = persistenceManager.getGroupByID(input.getGroupID()); + + // Acquire the group to resize from the database + var group = persistenceManager.getGroupByID(input.getGroupID()); + + // Perform the desired operation switch (input.getOperation()) { case ADD: - group.getContacts().add(persistenceManager.getUserByID(input.get())); + group.getContacts().add(persistenceManager.getUserByID(input.get().getID())); break; - case REMOVE: - group.getContacts().remove(persistenceManager.getUserByID(input.get())); + group.getContacts().remove(persistenceManager.getUserByID(input.get().getID())); break; } + + // Update the group in the database persistenceManager.updateContact(group); - writeProxy.write(socketID, group); + + // Send the updated group to all of its members + var commonGroup = group.toCommon(); group.getContacts() .stream() .map(Contact::getID) @@ -42,7 +49,7 @@ public class GroupResizeProcessor implements ObjectProcessor { .map(connectionManager::getSocketId) .forEach(memberSocketID -> { try { - writeProxy.write(memberSocketID, group); + writeProxy.write(memberSocketID, commonGroup); } catch (IOException e) { e.printStackTrace(); }