diff --git a/src/main/java/envoy/server/ConnectionManager.java b/src/main/java/envoy/server/ConnectionManager.java index 2d7aac5..a1b9945 100644 --- a/src/main/java/envoy/server/ConnectionManager.java +++ b/src/main/java/envoy/server/ConnectionManager.java @@ -49,13 +49,15 @@ public class ConnectionManager implements ISocketIdListener { @Override public void socketCancelled(long socketId) { - // notifying contacts of this users offline-going - long clientId = getUserIdBySocketId(socketId); - User user = new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName()); - UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user)); - // removing the socket - if (!pendingSockets.remove(socketId)) + if (!pendingSockets.remove(socketId)) { + // notifying contacts of this users offline-going + long clientId = getUserIdBySocketId(socketId); + User user = new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName()); + UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user)); + + // removing the socket sockets.entrySet().stream().filter(e -> e.getValue() == socketId).forEach(e -> sockets.remove(e.getValue())); + } } @Override diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index e7e2a0e..7f2d715 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -229,11 +229,11 @@ public class PersistenceManager { * @since Envoy Server Standalone v0.1-alpha */ public void updateUserStatus(User user, UserStatus status) { - if (user.getStatus().equals(status)) { - System.out.println("Received an UserStatus for User" + user.getId() + "to update that this user already has"); - return; + if (user.getStatus().equals(status)) + System.out.println("Received an UserStatusChangeEvent for user " + user.getId() + " to update that this user already has"); + else { + user.setStatus(status); + persistenceManager.updateUser(user); } - user.setStatus(status); - persistenceManager.updateUser(user); } } \ No newline at end of file diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index cefdec2..636b218 100644 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -44,19 +44,15 @@ public class LoginCredentialProcessor implements ObjectProcessor users = PersistenceManager.getPersistenceManager() - .getContacts(user) - .stream() - .map(envoy.server.data.User::toCommonUser) - .collect(Collectors.toList()); - Contacts contacts = new Contacts(user.getId(), users); + Contacts contacts = new Contacts(user.getId(), + user.getContacts().stream().map(envoy.server.data.User::toCommonUser).collect(Collectors.toList())); // Complete handshake System.out.println("Sending user..."); @@ -83,6 +79,7 @@ public class LoginCredentialProcessor implements ObjectProcessor