From e285b6d75e5e52f65f6c60034d406792e7c2af42 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 9 Apr 2020 13:53:06 +0200 Subject: [PATCH] Fixed several errors in GroupResizeProcessor * a common user was passed to the persistence manager instead of its ID * a server group was sent to its members instead of the common group --- .../processors/GroupResizeProcessor.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) 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(); }