feat(messages): possibilité de modifier ou supprimer un message

This commit is contained in:
Emi Boucly 2025-02-12 12:44:17 +01:00
parent cbbb95f6d5
commit bf1a52f368
8 changed files with 210 additions and 4 deletions

View file

@ -158,7 +158,7 @@ public class ChatServer {
return contactMap;
}
/** Temporaire : connecte daisy pour test */
/** Temporaire : connecte pour test */
public static void daisyConnect() throws IOException {
ChatClient client = new ChatClient("localhost", 2024, null);
client.sendAuthEvent(new Contact("daisy", null));
@ -282,12 +282,27 @@ public class ChatServer {
doCont(event.getContent());
LOGGER.info("Update de contact");
return true;
} else if (event.getType().equals(Event.POST)) {
doPost(event.getContent());
LOGGER.info("Post edited");
return true;
} else {
LOGGER.warning("Unhandled event type: " + event.getType());
return false;
}
}
private void doPost(JSONObject content) {
database = new DatabaseApi();
database.removePost(Post.fromJson(content));
database.addPost(Post.fromJson(content));
database.close();
postVector.removeIf(post -> post.getId().equals(Post.fromJson(content).getId()));
postVector.add(Post.fromJson(content));
sendEventToAllContacts(new Event(Event.POST, content));
LOGGER.info("didpost");
}
private void doCont(JSONObject content) {
if (user.isConnected()) {
sendEventToAllContacts(new Event("CONT", content));