Added ContactOperationProcessor for the ADD operation
This commit is contained in:
parent
b4a5435b5f
commit
1c8b639014
@ -180,6 +180,15 @@ public class PersistenceManager {
|
|||||||
return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase + "%").getResultList();
|
return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase + "%").getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addContact(long userId, long contactId) {
|
||||||
|
User c1 = getUserById(userId);
|
||||||
|
User c2 = getUserById(contactId);
|
||||||
|
c1.getContacts().add(c2);
|
||||||
|
c2.getContacts().add(c1);
|
||||||
|
updateUser(c1);
|
||||||
|
updateUser(c2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param user the User whose contacts should be retrieved
|
* @param user the User whose contacts should be retrieved
|
||||||
* @return the contacts of this User - currently everyone using Envoy
|
* @return the contacts of this User - currently everyone using Envoy
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package envoy.server.processors;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import envoy.event.ContactOperation;
|
||||||
|
import envoy.event.ContactOperation.Operation;
|
||||||
|
import envoy.server.ConnectionManager;
|
||||||
|
import envoy.server.ObjectProcessor;
|
||||||
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: <strong>envoy-server-standalone</strong><br>
|
||||||
|
* File: <strong>ContactOperationProcessor.java</strong><br>
|
||||||
|
* Created: <strong>08.02.2020</strong><br>
|
||||||
|
*
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
public class ContactOperationProcessor implements ObjectProcessor<ContactOperation> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ContactOperation operation, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
|
if (operation.getOperationType() == Operation.ADD) {
|
||||||
|
long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
||||||
|
System.out.printf("Adding user %s to the contact list of user %d", operation.get(), userId);
|
||||||
|
PersistenceManager.getPersistenceManager().addContact(userId, operation.get().getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ContactOperation> getInputClass() { return ContactOperation.class; }
|
||||||
|
}
|
Reference in New Issue
Block a user