Fixed contacts initialisation, socket logout error
additionally fixed small spelling mistakes
This commit is contained in:
parent
f11ed4a585
commit
5fcbf59349
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -44,19 +44,15 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
|
||||
// Not logged in successfully
|
||||
if (user == null) return;
|
||||
ConnectionManager.getInstance().registerUser(user.getId(), socketId);
|
||||
|
||||
// notifies contacts of this users online-going and updates his status in the
|
||||
// database
|
||||
UserStatusChangeProcessor.updateUserStatus(new UserStatusChangeEvent(user.toCommonUser()));
|
||||
|
||||
ConnectionManager.getInstance().registerUser(user.getId(), socketId);
|
||||
|
||||
// Create contacts
|
||||
List<User> 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<LoginCredential
|
||||
user.setLastSeen(new Date());
|
||||
user.setStatus(User.UserStatus.ONLINE);
|
||||
user.setPasswordHash(credentials.getPasswordHash());
|
||||
user.setContacts(PersistenceManager.getPersistenceManager().getContacts(user));
|
||||
persistenceManager.addUser(user);
|
||||
} else {
|
||||
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);
|
||||
} catch (IOException e) {
|
||||
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