43 lines
1.4 KiB
Java
43 lines
1.4 KiB
Java
package envoy.server.processors;
|
|
|
|
import java.io.IOException;
|
|
|
|
import envoy.event.NameChangeEvent;
|
|
import envoy.server.data.Contact;
|
|
import envoy.server.data.PersistenceManager;
|
|
import envoy.server.data.User;
|
|
import envoy.server.net.ConnectionManager;
|
|
import envoy.server.net.ObjectWriteProxy;
|
|
|
|
/**
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
* File: <strong>NameChangeProcessor.java</strong><br>
|
|
* Created: <strong>26 Mar 2020</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public class NameChangeProcessor implements ObjectProcessor<NameChangeEvent> {
|
|
|
|
@Override
|
|
public void process(NameChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
|
PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
|
ConnectionManager connectionManager = ConnectionManager.getInstance();
|
|
Contact toUpdate = persistenceManager.getContactByID(input.getID());
|
|
toUpdate.setName(input.get());
|
|
persistenceManager.updateContact(toUpdate);
|
|
|
|
// notifying online contacts of this client of his name change
|
|
toUpdate.getContacts().stream().filter(contact -> (contact instanceof User && connectionManager.isOnline(contact.getID()))).forEach(user -> {
|
|
try {
|
|
writeProxy.write(user.getID(), input);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public Class<NameChangeEvent> getInputClass() { return NameChangeEvent.class; }
|
|
}
|