|
@@ -3,6 +3,7 @@ package fr.insa.clavardator.server;
|
3
|
3
|
import fr.insa.clavardator.lib.network.TcpConnection;
|
4
|
4
|
import fr.insa.clavardator.lib.network.TcpListener;
|
5
|
5
|
import fr.insa.clavardator.lib.users.UserInformation;
|
|
6
|
+import fr.insa.clavardator.lib.users.UserState;
|
6
|
7
|
import fr.insa.clavardator.lib.util.Log;
|
7
|
8
|
|
8
|
9
|
import java.io.EOFException;
|
|
@@ -58,7 +59,7 @@ public class Presence {
|
58
|
59
|
user.receive(msg -> Log.w(getClass().getSimpleName(), "Received an unexpected message " + msg),
|
59
|
60
|
e -> {
|
60
|
61
|
if (e instanceof EOFException) {
|
61
|
|
- unsubscribe(userInformation.id);
|
|
62
|
+ unsubscribe(userInformation);
|
62
|
63
|
}
|
63
|
64
|
});
|
64
|
65
|
} else {
|
|
@@ -71,11 +72,12 @@ public class Presence {
|
71
|
72
|
});
|
72
|
73
|
}
|
73
|
74
|
|
74
|
|
- public void unsubscribe(String id) {
|
75
|
|
- Log.v(getClass().getSimpleName(), "Unsubscribing user " + id);
|
76
|
|
- subscribers.get(id).close();
|
77
|
|
- subscribers.remove(id);
|
78
|
|
- connectedUsers.removeIf(userInformation -> userInformation.id.equals(id));
|
|
75
|
+ public void unsubscribe(UserInformation userInformation) {
|
|
76
|
+ Log.v(getClass().getSimpleName(), "Unsubscribing user " + userInformation.id + "(" + userInformation.getUsername() + ")");
|
|
77
|
+ subscribers.get(userInformation.id).close();
|
|
78
|
+ subscribers.remove(userInformation.id);
|
|
79
|
+ publish(new UserInformation(userInformation.id, userInformation.getUsername(), UserState.DISCONNECTED));
|
|
80
|
+ connectedUsers.removeIf(ui -> userInformation.id.equals(ui.id));
|
79
|
81
|
}
|
80
|
82
|
|
81
|
83
|
public void stop() {
|