Fixed contacts initialisation, socket logout error

additionally fixed small spelling mistakes
This commit is contained in:
delvh 2020-02-04 21:09:59 +01:00
parent 6a5680a19f
commit 0c530bc5a8
4 changed files with 19 additions and 20 deletions

View File

@ -49,13 +49,15 @@ public class ConnectionManager implements ISocketIdListener {
@Override @Override
public void socketCancelled(long socketId) { public void socketCancelled(long socketId) {
// notifying contacts of this users offline-going if (!pendingSockets.remove(socketId)) {
long clientId = getUserIdBySocketId(socketId); // notifying contacts of this users offline-going
User user = new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName()); long clientId = getUserIdBySocketId(socketId);
UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user)); User user = new User(clientId, PersistenceManager.getPersistenceManager().getUserById(clientId).getName());
// removing the socket UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user));
if (!pendingSockets.remove(socketId))
// removing the socket
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

View File

@ -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);
persistenceManager.updateUser(user);
} }
user.setStatus(status);
persistenceManager.updateUser(user);
} }
} }

View File

@ -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());

View File

@ -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");
} }
} }