mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
feat(avatar): Gestion des avatars en base64, corruption lors d'un changement en étant connecté à fix
This commit is contained in:
parent
8c9dfc58f8
commit
cba4d6b81b
4 changed files with 71 additions and 18 deletions
|
|
@ -268,12 +268,23 @@ public class ChatServer {
|
|||
} else if (event.getType().equals(Event.QUIT)) {
|
||||
LOGGER.info("Déconnexion");
|
||||
return false;
|
||||
} else if (event.getType().equals(Event.CONT)) {
|
||||
doCont(event.getContent());
|
||||
LOGGER.info("Update de contact");
|
||||
return true;
|
||||
} else {
|
||||
LOGGER.warning("Unhandled event type: " + event.getType());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void doCont(JSONObject content) {
|
||||
if (user.isConnected()) {
|
||||
sendEventToAllContacts(new Event("CONT", content));
|
||||
contactMap.getContact(content.getString("login")).setAvatar(Contact.base64ToImage(content.getString("avatar")));
|
||||
}
|
||||
}
|
||||
|
||||
private void doJoin(JSONObject content) {
|
||||
if (content.getString("room").isEmpty()) {
|
||||
user.setCurrentRoom(null);
|
||||
|
|
@ -368,11 +379,7 @@ public class ChatServer {
|
|||
private void doListContact(JSONObject content) throws JSONException, IllegalStateException {
|
||||
for (Contact contact: contactMap.values()) {
|
||||
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||
try {
|
||||
send(new Event(Event.CONT, contact.toJsonObject()).toJson());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
sendEventToContact(user, new Event(Event.CONT, contact.toJsonObject()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue