Publish disconnected user info on unsubscribe
This commit is contained in:
parent
33f355b90b
commit
ebd292e6eb
1 changed files with 8 additions and 6 deletions
|
@ -3,6 +3,7 @@ package fr.insa.clavardator.server;
|
||||||
import fr.insa.clavardator.lib.network.TcpConnection;
|
import fr.insa.clavardator.lib.network.TcpConnection;
|
||||||
import fr.insa.clavardator.lib.network.TcpListener;
|
import fr.insa.clavardator.lib.network.TcpListener;
|
||||||
import fr.insa.clavardator.lib.users.UserInformation;
|
import fr.insa.clavardator.lib.users.UserInformation;
|
||||||
|
import fr.insa.clavardator.lib.users.UserState;
|
||||||
import fr.insa.clavardator.lib.util.Log;
|
import fr.insa.clavardator.lib.util.Log;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
|
@ -58,7 +59,7 @@ public class Presence {
|
||||||
user.receive(msg -> Log.w(getClass().getSimpleName(), "Received an unexpected message " + msg),
|
user.receive(msg -> Log.w(getClass().getSimpleName(), "Received an unexpected message " + msg),
|
||||||
e -> {
|
e -> {
|
||||||
if (e instanceof EOFException) {
|
if (e instanceof EOFException) {
|
||||||
unsubscribe(userInformation.id);
|
unsubscribe(userInformation);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,11 +72,12 @@ public class Presence {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsubscribe(String id) {
|
public void unsubscribe(UserInformation userInformation) {
|
||||||
Log.v(getClass().getSimpleName(), "Unsubscribing user " + id);
|
Log.v(getClass().getSimpleName(), "Unsubscribing user " + userInformation.id + "(" + userInformation.getUsername() + ")");
|
||||||
subscribers.get(id).close();
|
subscribers.get(userInformation.id).close();
|
||||||
subscribers.remove(id);
|
subscribers.remove(userInformation.id);
|
||||||
connectedUsers.removeIf(userInformation -> userInformation.id.equals(id));
|
publish(new UserInformation(userInformation.id, userInformation.getUsername(), UserState.DISCONNECTED));
|
||||||
|
connectedUsers.removeIf(ui -> userInformation.id.equals(ui.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
|
Loading…
Reference in a new issue