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
This commit is contained in:
Kai S. K. Engelbart 2020-04-09 13:53:06 +02:00
parent 4e385396ad
commit e285b6d75e

View File

@ -18,23 +18,30 @@ import envoy.server.net.ObjectWriteProxy;
*/
public class GroupResizeProcessor implements ObjectProcessor<GroupResizeEvent> {
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<GroupResizeEvent> {
.map(connectionManager::getSocketId)
.forEach(memberSocketID -> {
try {
writeProxy.write(memberSocketID, group);
writeProxy.write(memberSocketID, commonGroup);
} catch (IOException e) {
e.printStackTrace();
}