Implemented online contact notification about contact list modification
This commit is contained in:
parent
4909a65464
commit
2b1adad1ec
@ -1,9 +1,10 @@
|
|||||||
package envoy.server.processors;
|
package envoy.server.processors;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import envoy.data.Contacts;
|
||||||
import envoy.event.ContactOperationEvent;
|
import envoy.event.ContactOperationEvent;
|
||||||
import envoy.event.ContactOperationEvent.Operation;
|
|
||||||
import envoy.server.ConnectionManager;
|
import envoy.server.ConnectionManager;
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
@ -19,12 +20,25 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
*/
|
*/
|
||||||
public class ContactOperationProcessor implements ObjectProcessor<ContactOperationEvent> {
|
public class ContactOperationProcessor implements ObjectProcessor<ContactOperationEvent> {
|
||||||
|
|
||||||
|
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(ContactOperationEvent operation, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(ContactOperationEvent evt, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
if (operation.getOperationType() == Operation.ADD) {
|
switch (evt.getOperationType()) {
|
||||||
long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
case ADD:
|
||||||
System.out.printf("Adding user %s to the contact list of user %d.%n", operation.get(), userId);
|
final long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
||||||
PersistenceManager.getPersistenceManager().addContact(userId, operation.get().getId());
|
final long contactId = evt.get().getId();
|
||||||
|
|
||||||
|
System.out.printf("Adding user %s to the contact list of user %d.%n", evt.get(), userId);
|
||||||
|
PersistenceManager.getPersistenceManager().addContact(userId, contactId);
|
||||||
|
|
||||||
|
// Notify the contact
|
||||||
|
// TODO: cache notification for offline mode
|
||||||
|
if (ConnectionManager.getInstance().isOnline(contactId)) writeProxy.write(connectionManager.getSocketId(contactId),
|
||||||
|
new Contacts(Arrays.asList(PersistenceManager.getPersistenceManager().getUserById(userId).toCommonUser())));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.err.printf("Received %s with an unsupported operation.%n", evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user