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:
parent
c6f0bff957
commit
98632f97bb
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user