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
4e385396ad
commit
e285b6d75e
@ -18,23 +18,30 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
*/
|
*/
|
||||||
public class GroupResizeProcessor implements ObjectProcessor<GroupResizeEvent> {
|
public class GroupResizeProcessor implements ObjectProcessor<GroupResizeEvent> {
|
||||||
|
|
||||||
PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
||||||
ConnectionManager connectionManager = ConnectionManager.getInstance();
|
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
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()) {
|
switch (input.getOperation()) {
|
||||||
case ADD:
|
case ADD:
|
||||||
group.getContacts().add(persistenceManager.getUserByID(input.get()));
|
group.getContacts().add(persistenceManager.getUserByID(input.get().getID()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
group.getContacts().remove(persistenceManager.getUserByID(input.get()));
|
group.getContacts().remove(persistenceManager.getUserByID(input.get().getID()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the group in the database
|
||||||
persistenceManager.updateContact(group);
|
persistenceManager.updateContact(group);
|
||||||
writeProxy.write(socketID, group);
|
|
||||||
|
// Send the updated group to all of its members
|
||||||
|
var commonGroup = group.toCommon();
|
||||||
group.getContacts()
|
group.getContacts()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Contact::getID)
|
.map(Contact::getID)
|
||||||
@ -42,7 +49,7 @@ public class GroupResizeProcessor implements ObjectProcessor<GroupResizeEvent> {
|
|||||||
.map(connectionManager::getSocketId)
|
.map(connectionManager::getSocketId)
|
||||||
.forEach(memberSocketID -> {
|
.forEach(memberSocketID -> {
|
||||||
try {
|
try {
|
||||||
writeProxy.write(memberSocketID, group);
|
writeProxy.write(memberSocketID, commonGroup);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user