fixes #129 - contacts are now sent as a part of the user
(if they were not already)... Additionally renamed some methods named `...Id()` to `...ID()`
This commit is contained in:
		@@ -43,7 +43,10 @@ public class Startup {
 | 
				
			|||||||
		processors.add(new ContactOperationProcessor());
 | 
							processors.add(new ContactOperationProcessor());
 | 
				
			||||||
		Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
 | 
							Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		initializeCurrentMessageId();
 | 
							// Initialize the current message ID
 | 
				
			||||||
 | 
							PersistenceManager persistenceManager = PersistenceManager.getInstance();
 | 
				
			||||||
 | 
							if (persistenceManager.getConfigItemByID("currentMessageId") == null)
 | 
				
			||||||
 | 
								persistenceManager.addConfigItem(new ConfigItem("currentMessageId", "0"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		server.start();
 | 
							server.start();
 | 
				
			||||||
		server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
 | 
							server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
 | 
				
			||||||
@@ -53,9 +56,4 @@ public class Startup {
 | 
				
			|||||||
		System.out.println("Stopped");
 | 
							System.out.println("Stopped");
 | 
				
			||||||
		System.exit(0);
 | 
							System.exit(0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static void initializeCurrentMessageId() {
 | 
					 | 
				
			||||||
		PersistenceManager persMan = PersistenceManager.getInstance();
 | 
					 | 
				
			||||||
		if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,7 @@ package envoy.server.data;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.persistence.CascadeType;
 | 
					import javax.persistence.*;
 | 
				
			||||||
import javax.persistence.Entity;
 | 
					 | 
				
			||||||
import javax.persistence.GeneratedValue;
 | 
					 | 
				
			||||||
import javax.persistence.GenerationType;
 | 
					 | 
				
			||||||
import javax.persistence.Id;
 | 
					 | 
				
			||||||
import javax.persistence.Inheritance;
 | 
					 | 
				
			||||||
import javax.persistence.InheritanceType;
 | 
					 | 
				
			||||||
import javax.persistence.ManyToMany;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This class acts as a superclass for all contacts, being {@link User}s and
 | 
					 * This class acts as a superclass for all contacts, being {@link User}s and
 | 
				
			||||||
@@ -32,7 +25,7 @@ public abstract class Contact {
 | 
				
			|||||||
	protected long		id;
 | 
						protected long		id;
 | 
				
			||||||
	protected String	name;
 | 
						protected String	name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL)
 | 
						@ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
 | 
				
			||||||
	protected Set<Contact> contacts;
 | 
						protected Set<Contact> contacts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -81,4 +74,10 @@ public abstract class Contact {
 | 
				
			|||||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
						 * @since Envoy Server Standalone v0.1-beta
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void setContacts(Set<Contact> contacts) { this.contacts = contacts; }
 | 
						public void setContacts(Set<Contact> contacts) { this.contacts = contacts; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * {@inheritDoc}
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public String toString() { return String.format("%s[id=%d,name=%s, contacts=%s]", getClass().getSimpleName(), id, name, contacts); }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,7 @@ import envoy.data.User;
 | 
				
			|||||||
@Entity
 | 
					@Entity
 | 
				
			||||||
@Table(name = "groups")
 | 
					@Table(name = "groups")
 | 
				
			||||||
@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
 | 
					@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
 | 
				
			||||||
public class Group extends Contact {
 | 
					public final class Group extends Contact {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * {@inheritDoc}
 | 
						 * {@inheritDoc}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -74,15 +74,15 @@ public class Message {
 | 
				
			|||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Message(envoy.data.Message message) {
 | 
						public Message(envoy.data.Message message) {
 | 
				
			||||||
		PersistenceManager persMan = PersistenceManager.getInstance();
 | 
							PersistenceManager persistenceManager = PersistenceManager.getInstance();
 | 
				
			||||||
		id				= message.getID();
 | 
							id				= message.getID();
 | 
				
			||||||
		status			= message.getStatus();
 | 
							status			= message.getStatus();
 | 
				
			||||||
		text			= message.getText();
 | 
							text			= message.getText();
 | 
				
			||||||
		creationDate	= message.getCreationDate();
 | 
							creationDate	= message.getCreationDate();
 | 
				
			||||||
		receivedDate	= message.getReceivedDate();
 | 
							receivedDate	= message.getReceivedDate();
 | 
				
			||||||
		readDate		= message.getReadDate();
 | 
							readDate		= message.getReadDate();
 | 
				
			||||||
		sender			= persMan.getUserById(message.getSenderID());
 | 
							sender			= persistenceManager.getUserByID(message.getSenderID());
 | 
				
			||||||
		recipient		= persMan.getUserById(message.getRecipientID());
 | 
							recipient		= persistenceManager.getUserByID(message.getRecipientID());
 | 
				
			||||||
		forwarded		= message.isForwarded();
 | 
							forwarded		= message.isForwarded();
 | 
				
			||||||
		// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
 | 
							// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,7 @@ public class PersistenceManager {
 | 
				
			|||||||
			ConnectionManager.getInstance()
 | 
								ConnectionManager.getInstance()
 | 
				
			||||||
				.getOnlineUsers()
 | 
									.getOnlineUsers()
 | 
				
			||||||
				.stream()
 | 
									.stream()
 | 
				
			||||||
				.map(this::getUserById)
 | 
									.map(this::getUserByID)
 | 
				
			||||||
				.forEach(user -> { user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); entityManager.merge(user); });
 | 
									.forEach(user -> { user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); entityManager.merge(user); });
 | 
				
			||||||
			transaction.commit();
 | 
								transaction.commit();
 | 
				
			||||||
		}));
 | 
							}));
 | 
				
			||||||
@@ -120,7 +120,7 @@ public class PersistenceManager {
 | 
				
			|||||||
	 * @return the user with the specified id
 | 
						 * @return the user with the specified id
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public User getUserById(long id) { return entityManager.find(User.class, id); }
 | 
						public User getUserByID(long id) { return entityManager.find(User.class, id); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Searches for a {@link Group} with a specific ID.
 | 
						 * Searches for a {@link Group} with a specific ID.
 | 
				
			||||||
@@ -129,7 +129,7 @@ public class PersistenceManager {
 | 
				
			|||||||
	 * @return the group with the specific id
 | 
						 * @return the group with the specific id
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
						 * @since Envoy Server Standalone v0.1-beta
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Group getGroupById(long id) { return entityManager.find(Group.class, id); }
 | 
						public Group getGroupByID(long id) { return entityManager.find(Group.class, id); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Searches for a {@link Contact} with a specific ID.
 | 
						 * Searches for a {@link Contact} with a specific ID.
 | 
				
			||||||
@@ -138,7 +138,7 @@ public class PersistenceManager {
 | 
				
			|||||||
	 * @return the contact with the specific id
 | 
						 * @return the contact with the specific id
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
						 * @since Envoy Server Standalone v0.1-beta
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Contact getContactById(long id) { return entityManager.find(Contact.class, id); }
 | 
						public Contact getContactByID(long id) { return entityManager.find(Contact.class, id); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Searched for a {@link User} with a specific name.
 | 
						 * Searched for a {@link User} with a specific name.
 | 
				
			||||||
@@ -180,14 +180,14 @@ public class PersistenceManager {
 | 
				
			|||||||
	 * @return the message with the specified id
 | 
						 * @return the message with the specified id
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Message getMessageById(long id) { return entityManager.find(Message.class, id); }
 | 
						public Message getMessageByID(long id) { return entityManager.find(Message.class, id); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @param key the name of this {@link ConfigItem}
 | 
						 * @param key the name of this {@link ConfigItem}
 | 
				
			||||||
	 * @return the {@link ConfigItem} with the given name
 | 
						 * @return the {@link ConfigItem} with the given name
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public ConfigItem getConfigItemById(String key) { return entityManager.find(ConfigItem.class, key); }
 | 
						public ConfigItem getConfigItemByID(String key) { return entityManager.find(ConfigItem.class, key); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns all messages received while being offline or the ones that have
 | 
						 * Returns all messages received while being offline or the ones that have
 | 
				
			||||||
@@ -217,7 +217,7 @@ public class PersistenceManager {
 | 
				
			|||||||
	public List<User> searchUsers(String searchPhrase, long userId) {
 | 
						public List<User> searchUsers(String searchPhrase, long userId) {
 | 
				
			||||||
		return entityManager.createNamedQuery("searchUsers")
 | 
							return entityManager.createNamedQuery("searchUsers")
 | 
				
			||||||
			.setParameter("searchPhrase", searchPhrase + "%")
 | 
								.setParameter("searchPhrase", searchPhrase + "%")
 | 
				
			||||||
			.setParameter("context", getUserById(userId))
 | 
								.setParameter("context", getUserByID(userId))
 | 
				
			||||||
			.getResultList();
 | 
								.getResultList();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -231,8 +231,8 @@ public class PersistenceManager {
 | 
				
			|||||||
	public void addUserContact(long userId1, long userId2) {
 | 
						public void addUserContact(long userId1, long userId2) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get users by ID
 | 
							// Get users by ID
 | 
				
			||||||
		Contact	u1	= getContactById(userId1);
 | 
							Contact	u1	= getContactByID(userId1);
 | 
				
			||||||
		Contact	u2	= getContactById(userId2);
 | 
							Contact	u2	= getContactByID(userId2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Add users to each others contact lists
 | 
							// Add users to each others contact lists
 | 
				
			||||||
		u1.getContacts().add(u2);
 | 
							u1.getContacts().add(u2);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ import javax.persistence.*;
 | 
				
			|||||||
		name = "searchUsers"
 | 
							name = "searchUsers"
 | 
				
			||||||
	) }
 | 
						) }
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
public class User extends Contact {
 | 
					public final class User extends Contact {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private byte[] passwordHash;
 | 
						private byte[] passwordHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,7 +49,7 @@ public class ConnectionManager implements ISocketIdListener {
 | 
				
			|||||||
	public void socketCancelled(long socketID) {
 | 
						public void socketCancelled(long socketID) {
 | 
				
			||||||
		if (!pendingSockets.remove(socketID)) {
 | 
							if (!pendingSockets.remove(socketID)) {
 | 
				
			||||||
			// Notify contacts of this users offline-going
 | 
								// Notify contacts of this users offline-going
 | 
				
			||||||
			envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketID));
 | 
								envoy.server.data.User user = PersistenceManager.getInstance().getUserByID(getUserIdBySocketId(socketID));
 | 
				
			||||||
			user.setStatus(UserStatus.OFFLINE);
 | 
								user.setStatus(UserStatus.OFFLINE);
 | 
				
			||||||
			user.setLastSeen(new Date());
 | 
								user.setLastSeen(new Date());
 | 
				
			||||||
			UserStatusChangeProcessor.updateUserStatus(user);
 | 
								UserStatusChangeProcessor.updateUserStatus(user);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ public class ContactOperationProcessor implements ObjectProcessor<ContactOperati
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				// Notify the contact if online
 | 
									// Notify the contact if online
 | 
				
			||||||
				if (ConnectionManager.getInstance().isOnline(contactId)) writeProxy.write(connectionManager.getSocketId(contactId),
 | 
									if (ConnectionManager.getInstance().isOnline(contactId)) writeProxy.write(connectionManager.getSocketId(contactId),
 | 
				
			||||||
						Arrays.asList(PersistenceManager.getInstance().getUserById(userID).toCommon()));
 | 
											Arrays.asList(PersistenceManager.getInstance().getUserByID(userID).toCommon()));
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				System.err.printf("Received %s with an unsupported operation.%n", evt);
 | 
									System.err.printf("Received %s with an unsupported operation.%n", evt);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,8 +25,8 @@ public class GroupCreationProcessor implements ObjectProcessor<GroupCreationEven
 | 
				
			|||||||
	public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
						public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
				
			||||||
		envoy.server.data.Group group = new envoy.server.data.Group();
 | 
							envoy.server.data.Group group = new envoy.server.data.Group();
 | 
				
			||||||
		group.setName(input.get());
 | 
							group.setName(input.get());
 | 
				
			||||||
		input.getInitialMemberIDs().stream().map(persistenceManager::getUserById).forEach(group.getContacts()::add);
 | 
							input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add);
 | 
				
			||||||
		group.getContacts().add(persistenceManager.getUserById(connectionManager.getUserIdBySocketId(socketID)));
 | 
							group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
 | 
				
			||||||
		persistenceManager.addContact(group);
 | 
							persistenceManager.addContact(group);
 | 
				
			||||||
		writeProxy.write(socketID, group);
 | 
							writeProxy.write(socketID, group);
 | 
				
			||||||
		group.getContacts()
 | 
							group.getContacts()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,14 +23,14 @@ public class GroupResizeProcessor implements ObjectProcessor<GroupResizeEvent> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
						public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
				
			||||||
		envoy.server.data.Group group = persistenceManager.getGroupById(input.getGroupID());
 | 
							envoy.server.data.Group group = persistenceManager.getGroupByID(input.getGroupID());
 | 
				
			||||||
		switch (input.getOperation()) {
 | 
							switch (input.getOperation()) {
 | 
				
			||||||
			case ADD:
 | 
								case ADD:
 | 
				
			||||||
				group.getContacts().add(persistenceManager.getUserById(input.get().getID()));
 | 
									group.getContacts().add(persistenceManager.getUserByID(input.get()));
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case REMOVE:
 | 
								case REMOVE:
 | 
				
			||||||
				group.getContacts().remove(persistenceManager.getUserById(input.get().getID()));
 | 
									group.getContacts().remove(persistenceManager.getUserByID(input.get()));
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		persistenceManager.updateContact(group);
 | 
							persistenceManager.updateContact(group);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor<IDGeneratorR
 | 
				
			|||||||
	 * @since Envoy Server Standalone v0.1-beta
 | 
						 * @since Envoy Server Standalone v0.1-beta
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static IDGenerator createIDGenerator(long range) {
 | 
						public static IDGenerator createIDGenerator(long range) {
 | 
				
			||||||
		ConfigItem	currentID	= PersistenceManager.getInstance().getConfigItemById("currentMessageId");
 | 
							ConfigItem	currentID	= PersistenceManager.getInstance().getConfigItemByID("currentMessageId");
 | 
				
			||||||
		IDGenerator	generator	= new IDGenerator(Integer.parseInt(currentID.getValue()), range);
 | 
							IDGenerator	generator	= new IDGenerator(Integer.parseInt(currentID.getValue()), range);
 | 
				
			||||||
		currentID.setValue(String.valueOf(Integer.parseInt(currentID.getValue()) + range));
 | 
							currentID.setValue(String.valueOf(Integer.parseInt(currentID.getValue()) + range));
 | 
				
			||||||
		PersistenceManager.getInstance().updateConfigItem(currentID);
 | 
							PersistenceManager.getInstance().updateConfigItem(currentID);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,7 @@
 | 
				
			|||||||
package envoy.server.processors;
 | 
					package envoy.server.processors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.Arrays;
 | 
					import java.util.*;
 | 
				
			||||||
import java.util.Date;
 | 
					 | 
				
			||||||
import java.util.HashSet;
 | 
					 | 
				
			||||||
import java.util.InputMismatchException;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.persistence.NoResultException;
 | 
					import javax.persistence.NoResultException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,18 +51,12 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
 | 
				
			|||||||
		user.setStatus(UserStatus.ONLINE);
 | 
							user.setStatus(UserStatus.ONLINE);
 | 
				
			||||||
		UserStatusChangeProcessor.updateUserStatus(user);
 | 
							UserStatusChangeProcessor.updateUserStatus(user);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Create contacts
 | 
					 | 
				
			||||||
		var contacts = user.getContacts().stream().map(envoy.server.data.Contact::toCommon).collect(Collectors.toList());
 | 
					 | 
				
			||||||
		contacts.add(user.toCommon());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Complete handshake
 | 
							// Complete handshake
 | 
				
			||||||
		System.out.println("Sending user...");
 | 
							System.out.println("Sending user...");
 | 
				
			||||||
		writeProxy.write(socketID, user.toCommon());
 | 
							writeProxy.write(socketID, user.toCommon());
 | 
				
			||||||
		System.out.println("Sending contacts...");
 | 
					 | 
				
			||||||
		writeProxy.write(socketID, contacts);
 | 
					 | 
				
			||||||
		System.out.println("Acquiring pending messages for the client...");
 | 
							System.out.println("Acquiring pending messages for the client...");
 | 
				
			||||||
		List<Message> pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
 | 
							List<Message> pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
 | 
				
			||||||
		for (Message msg : pendingMessages) {
 | 
							for (Message msg : pendingMessages)
 | 
				
			||||||
			if (msg.getStatus() == MessageStatus.SENT) {
 | 
								if (msg.getStatus() == MessageStatus.SENT) {
 | 
				
			||||||
				System.out.println("Sending message " + msg.toCommonMessage());
 | 
									System.out.println("Sending message " + msg.toCommonMessage());
 | 
				
			||||||
				writeProxy.write(socketID, msg.toCommonMessage());
 | 
									writeProxy.write(socketID, msg.toCommonMessage());
 | 
				
			||||||
@@ -80,7 +69,6 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
 | 
				
			|||||||
				writeProxy.write(socketID, evt);
 | 
									writeProxy.write(socketID, evt);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
 | 
						public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ public class MessageProcessor implements ObjectProcessor<Message> {
 | 
				
			|||||||
	public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
 | 
						public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
 | 
				
			||||||
		message.nextStatus();
 | 
							message.nextStatus();
 | 
				
			||||||
		ConnectionManager	connectionManager	= ConnectionManager.getInstance();
 | 
							ConnectionManager	connectionManager	= ConnectionManager.getInstance();
 | 
				
			||||||
		Contact				recipient			= PersistenceManager.getInstance().getContactById(message.getID());
 | 
							Contact				recipient			= PersistenceManager.getInstance().getContactByID(message.getID());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (recipient instanceof envoy.server.data.User) {
 | 
							if (recipient instanceof envoy.server.data.User) {
 | 
				
			||||||
			System.out.println("The received message is a direct message.");
 | 
								System.out.println("The received message is a direct message.");
 | 
				
			||||||
@@ -43,7 +43,7 @@ public class MessageProcessor implements ObjectProcessor<Message> {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			System.out.println("The received message is a group message.");
 | 
								System.out.println("The received message is a group message.");
 | 
				
			||||||
			final var	members		= PersistenceManager.getInstance().getGroupById(message.getRecipientID()).getContacts();
 | 
								final var	members		= PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
 | 
				
			||||||
			final var	generator	= IDGeneratorRequestProcessor.createIDGenerator(members.size());
 | 
								final var	generator	= IDGeneratorRequestProcessor.createIDGenerator(members.size());
 | 
				
			||||||
			members.forEach(user -> {
 | 
								members.forEach(user -> {
 | 
				
			||||||
				envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
 | 
									envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
 | 
				
			|||||||
		// Any other status than READ is not supposed to be sent to the server
 | 
							// Any other status than READ is not supposed to be sent to the server
 | 
				
			||||||
		if (input.get() != MessageStatus.READ) throw new IOException(new EnvoyException("Message " + input + " has an invalid status"));
 | 
							if (input.get() != MessageStatus.READ) throw new IOException(new EnvoyException("Message " + input + " has an invalid status"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		envoy.server.data.Message msg = persistenceManager.getMessageById(input.getID());
 | 
							envoy.server.data.Message msg = persistenceManager.getMessageByID(input.getID());
 | 
				
			||||||
		msg.setStatus(input.get());
 | 
							msg.setStatus(input.get());
 | 
				
			||||||
		msg.setReadDate(input.getDate());
 | 
							msg.setReadDate(input.getDate());
 | 
				
			||||||
		persistenceManager.updateMessage(msg);
 | 
							persistenceManager.updateMessage(msg);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ public class NameChangeProcessor implements ObjectProcessor<NameChangeEvent> {
 | 
				
			|||||||
	public void process(NameChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
						public void process(NameChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
				
			||||||
		PersistenceManager	persistenceManager	= PersistenceManager.getInstance();
 | 
							PersistenceManager	persistenceManager	= PersistenceManager.getInstance();
 | 
				
			||||||
		ConnectionManager	connectionManager	= ConnectionManager.getInstance();
 | 
							ConnectionManager	connectionManager	= ConnectionManager.getInstance();
 | 
				
			||||||
		Contact				toUpdate			= persistenceManager.getContactById(input.getID());
 | 
							Contact				toUpdate			= persistenceManager.getContactByID(input.getID());
 | 
				
			||||||
		toUpdate.setName(input.get());
 | 
							toUpdate.setName(input.get());
 | 
				
			||||||
		persistenceManager.updateContact(toUpdate);
 | 
							persistenceManager.updateContact(toUpdate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void process(UserStatusChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
						public void process(UserStatusChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
 | 
				
			||||||
		// new status should not equal old status
 | 
							// new status should not equal old status
 | 
				
			||||||
		if (input.get().equals(persistenceManager.getUserById(input.getID()).getStatus())) {
 | 
							if (input.get().equals(persistenceManager.getUserByID(input.getID()).getStatus())) {
 | 
				
			||||||
			System.out.println("Received an unnecessary UserStatusChangeEvent");
 | 
								System.out.println("Received an unnecessary UserStatusChangeEvent");
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -58,7 +58,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
 | 
				
			|||||||
	 * @param evt the {@link UserStatusChangeEvent}
 | 
						 * @param evt the {@link UserStatusChangeEvent}
 | 
				
			||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static void updateUserStatus(UserStatusChangeEvent evt) { updateUserStatus(persistenceManager.getUserById(evt.getID())); }
 | 
						public static void updateUserStatus(UserStatusChangeEvent evt) { updateUserStatus(persistenceManager.getUserByID(evt.getID())); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * notifies active contacts of this {@link User} that his {@link UserStatus} has
 | 
						 * notifies active contacts of this {@link User} that his {@link UserStatus} has
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user