Fixed contacts initialisation, socket logout error
additionally fixed small spelling mistakes
This commit is contained in:
		@@ -49,14 +49,16 @@ public class ConnectionManager implements ISocketIdListener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void socketCancelled(long socketId) {
 | 
						public void socketCancelled(long socketId) {
 | 
				
			||||||
 | 
							if (!pendingSockets.remove(socketId)) {
 | 
				
			||||||
			// notifying contacts of this users offline-going
 | 
								// notifying contacts of this users offline-going
 | 
				
			||||||
			long	clientId	= getUserIdBySocketId(socketId);
 | 
								long	clientId	= getUserIdBySocketId(socketId);
 | 
				
			||||||
			User	user		= new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName());
 | 
								User	user		= new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName());
 | 
				
			||||||
			UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user));
 | 
								UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// removing the socket
 | 
								// removing the socket
 | 
				
			||||||
		if (!pendingSockets.remove(socketId))
 | 
					 | 
				
			||||||
			sockets.entrySet().stream().filter(e -> e.getValue() == socketId).forEach(e -> sockets.remove(e.getValue()));
 | 
								sockets.entrySet().stream().filter(e -> e.getValue() == socketId).forEach(e -> sockets.remove(e.getValue()));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void socketRegistered(long socketId) { pendingSockets.add(socketId); }
 | 
						public void socketRegistered(long socketId) { pendingSockets.add(socketId); }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -229,11 +229,11 @@ public class PersistenceManager {
 | 
				
			|||||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
						 * @since Envoy Server Standalone v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void updateUserStatus(User user, UserStatus status) {
 | 
						public void updateUserStatus(User user, UserStatus status) {
 | 
				
			||||||
		if (user.getStatus().equals(status)) {
 | 
							if (user.getStatus().equals(status))
 | 
				
			||||||
			System.out.println("Received an UserStatus for User" + user.getId() + "to update that this user already has");
 | 
								System.out.println("Received an UserStatusChangeEvent for user " + user.getId() + " to update that this user already has");
 | 
				
			||||||
			return;
 | 
							else {
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
			user.setStatus(status);
 | 
								user.setStatus(status);
 | 
				
			||||||
			persistenceManager.updateUser(user);
 | 
								persistenceManager.updateUser(user);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -44,19 +44,15 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// Not logged in successfully
 | 
							// Not logged in successfully
 | 
				
			||||||
		if (user == null) return;
 | 
							if (user == null) return;
 | 
				
			||||||
 | 
							ConnectionManager.getInstance().registerUser(user.getId(), socketId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// notifies contacts of this users online-going and updates his status in the
 | 
							// notifies contacts of this users online-going and updates his status in the
 | 
				
			||||||
		// database
 | 
							// database
 | 
				
			||||||
		UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user.toCommonUser()));
 | 
							UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user.toCommonUser()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ConnectionManager.getInstance().registerUser(user.getId(), socketId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Create contacts
 | 
							// Create contacts
 | 
				
			||||||
		List<User>	users		= PersistenceManager.getPersistenceManager()
 | 
							Contacts contacts = new Contacts(user.getId(),
 | 
				
			||||||
			.getContacts(user)
 | 
									user.getContacts().stream().map(envoy.server.data.User::toCommonUser).collect(Collectors.toList()));
 | 
				
			||||||
			.stream()
 | 
					 | 
				
			||||||
			.map(envoy.server.data.User::toCommonUser)
 | 
					 | 
				
			||||||
			.collect(Collectors.toList());
 | 
					 | 
				
			||||||
		Contacts	contacts	= new Contacts(user.getId(), users);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Complete handshake
 | 
							// Complete handshake
 | 
				
			||||||
		System.out.println("Sending user...");
 | 
							System.out.println("Sending user...");
 | 
				
			||||||
@@ -83,6 +79,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
 | 
				
			|||||||
			user.setLastSeen(new Date());
 | 
								user.setLastSeen(new Date());
 | 
				
			||||||
			user.setStatus(User.UserStatus.ONLINE);
 | 
								user.setStatus(User.UserStatus.ONLINE);
 | 
				
			||||||
			user.setPasswordHash(credentials.getPasswordHash());
 | 
								user.setPasswordHash(credentials.getPasswordHash());
 | 
				
			||||||
 | 
								user.setContacts(PersistenceManager.getPersistenceManager().getContacts(user));
 | 
				
			||||||
			persistenceManager.addUser(user);
 | 
								persistenceManager.addUser(user);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			user = persistenceManager.getUserByName(credentials.getName());
 | 
								user = persistenceManager.getUserByName(credentials.getName());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
 | 
				
			|||||||
				if (conMan.isOnline(contact.getId())) writeProxy.write(conMan.getSocketId(contact.getId()), evt);
 | 
									if (conMan.isOnline(contact.getId())) writeProxy.write(conMan.getSocketId(contact.getId()), evt);
 | 
				
			||||||
		} catch (IOException e) {
 | 
							} catch (IOException e) {
 | 
				
			||||||
			e.printStackTrace();
 | 
								e.printStackTrace();
 | 
				
			||||||
			System.err.println("Could not notify online contacts of user" + evt.getId() + "that his status changed");
 | 
								System.err.println("Could not notify online contacts of user " + evt.getId() + " that his status changed");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user