Implemented online contact notification about contact list modification
This commit is contained in:
		| @@ -1,9 +1,10 @@ | ||||
| package envoy.server.processors; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.Arrays; | ||||
|  | ||||
| import envoy.data.Contacts; | ||||
| import envoy.event.ContactOperationEvent; | ||||
| import envoy.event.ContactOperationEvent.Operation; | ||||
| import envoy.server.ConnectionManager; | ||||
| import envoy.server.ObjectProcessor; | ||||
| import envoy.server.database.PersistenceManager; | ||||
| @@ -19,12 +20,25 @@ import envoy.server.net.ObjectWriteProxy; | ||||
|  */ | ||||
| public class ContactOperationProcessor implements ObjectProcessor<ContactOperationEvent> { | ||||
|  | ||||
| 	private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); | ||||
|  | ||||
| 	@Override | ||||
| 	public void process(ContactOperationEvent 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.%n", operation.get(), userId); | ||||
| 			PersistenceManager.getPersistenceManager().addContact(userId, operation.get().getId()); | ||||
| 	public void process(ContactOperationEvent evt, long socketId, ObjectWriteProxy writeProxy) throws IOException { | ||||
| 		switch (evt.getOperationType()) { | ||||
| 			case ADD: | ||||
| 				final long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId); | ||||
| 				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