2020-04-06 22:55:27 +02:00
|
|
|
package envoy.server.processors;
|
|
|
|
|
2020-08-22 18:14:26 +02:00
|
|
|
import static envoy.server.Startup.config;
|
|
|
|
|
2020-06-09 21:05:30 +02:00
|
|
|
import java.util.HashSet;
|
2020-04-06 22:55:27 +02:00
|
|
|
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.event.*;
|
2020-10-19 18:17:51 +02:00
|
|
|
|
2020-10-14 23:41:24 +02:00
|
|
|
import envoy.server.data.PersistenceManager;
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.server.net.*;
|
2020-04-06 22:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Maximilian Käfer
|
|
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
|
|
*/
|
2020-08-22 13:37:07 +02:00
|
|
|
public final class GroupCreationProcessor implements ObjectProcessor<GroupCreation> {
|
2020-04-06 22:55:27 +02:00
|
|
|
|
|
|
|
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
|
|
|
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
|
|
|
|
|
|
|
@Override
|
2020-07-06 11:40:13 +02:00
|
|
|
public void process(GroupCreation groupCreation, long socketID, ObjectWriteProxy writeProxy) {
|
2020-08-22 18:14:26 +02:00
|
|
|
// Don't allow the creation of groups if manually disabled
|
2020-10-11 23:04:25 +02:00
|
|
|
if (!config.isGroupSupportEnabled()) {
|
|
|
|
writeProxy.write(socketID, new GroupCreationResult());
|
|
|
|
return;
|
|
|
|
}
|
2020-08-22 18:14:26 +02:00
|
|
|
final envoy.server.data.Group group = new envoy.server.data.Group();
|
2020-06-20 09:57:54 +02:00
|
|
|
group.setName(groupCreation.get());
|
2020-06-09 21:05:30 +02:00
|
|
|
group.setContacts(new HashSet<>());
|
2020-04-06 22:55:27 +02:00
|
|
|
persistenceManager.addContact(group);
|
2020-10-14 23:41:24 +02:00
|
|
|
groupCreation.getInitialMemberIDs()
|
2020-04-06 22:55:27 +02:00
|
|
|
.stream()
|
2020-10-14 23:41:24 +02:00
|
|
|
.map(persistenceManager::getUserByID)
|
|
|
|
.forEach(member -> persistenceManager.addContactBidirectional(member, group));
|
2020-10-19 18:17:51 +02:00
|
|
|
persistenceManager.addContactBidirectional(
|
|
|
|
persistenceManager.getUserByID(connectionManager.getUserIDBySocketID(socketID)), group);
|
|
|
|
writeProxy.writeToOnlineContacts(group.getContacts(),
|
|
|
|
new GroupCreationResult(group.toCommon()));
|
2020-04-06 22:55:27 +02:00
|
|
|
}
|
|
|
|
}
|