fix(LSTP): LSTP sur un salon renvoyait tous les posts depuis une date sans prendre en compte "select"

This commit is contained in:
Emi Boucly 2025-01-24 09:46:37 +01:00
parent 136054f07e
commit 76764860c9
4 changed files with 48 additions and 30 deletions

View file

@ -91,7 +91,7 @@ public class ChatController implements Initializable {
hostComboBox.setValue("localhost:2024");
hostComboBox.setOnAction(this::statusNameUpdate);
statusLabel.setText("not connected to " + hostComboBox.getValue());
statusLabel.setText("Disconnected");
connectionButton.disableProperty().bind(validatorLogin.containsErrorsProperty());
connectionButton.selectedProperty().addListener(this::handleConnection);
@ -212,9 +212,8 @@ public class ChatController implements Initializable {
if (this.client.isConnected()) {
this.contact.setConnected(false);
}
statusLabel.setText("not connected to " + hostComboBox.getValue());
statusLabel.setText("Disconnected");
}
}
private void clearLists() {
@ -322,6 +321,10 @@ public class ChatController implements Initializable {
contactsListView.getSelectionModel().clearSelection();
}
contact.setCurrentRoom(roomSelected.getRoomName());
roomSelected.getUnreadCount().setUnreadCount(0);
roomsListView.refresh();
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans le salon " + roomSelected);
postsObservableList.clear();
postsObservableList.add(postSys);
@ -377,6 +380,7 @@ public class ChatController implements Initializable {
LOGGER.finest("From: " + content.getString("from"));
LOGGER.finest("To: " + content.getString("to"));
try {
if (!content.getString("to").contains("#")) {
System.out.println("New message to contact!");
if (contactsListView.getSelectionModel().getSelectedItem().getLogin().equals(content.getString("to"))) {
@ -391,30 +395,42 @@ public class ChatController implements Initializable {
postVector.add(Post.fromJson(content));
postsObservableList.add(Post.fromJson(content));
postListView.refresh();
} else {
contactMap.getContact(content.getString("from")).getUnreadCount().incrementUnreadCount();
contactsListView.refresh();
LOGGER.info("New unread message ! from:");
LOGGER.info("New unread message ! from:" + content.getString("from"));
LOGGER.info("%d".formatted(contactsListView.getSelectionModel().getSelectedItem().getUnreadCount().getUnreadCount()));
}
}
} else {
System.out.println("New message to room!");
if (roomsListView.getSelectionModel().getSelectedItem().getRoomName().equals(content.getString("from"))) {
LOGGER.info("New message! to:dm, from:myself");
LOGGER.info("New message to room!");
if (roomsListView.getSelectionModel().getSelectedItem().getRoomName().equals(content.getString("to"))) {
LOGGER.info("New message! to:room, from:myself");
postVector.add(Post.fromJson(content));
postsObservableList.add(Post.fromJson(content));
postListView.refresh();
} else {
roomMap.get(content.getString("from")).getUnreadCount().incrementUnreadCount();
roomMap.get(content.getString("to")).getUnreadCount().incrementUnreadCount();
roomsListView.refresh();
LOGGER.info("New unread message ! from:");
LOGGER.info("New unread message ! from:" + content.getString("from"));
LOGGER.info("%d".formatted(contactsListView.getSelectionModel().getSelectedItem().getUnreadCount().getUnreadCount()));
}
}
} catch (Exception e) {
/*
if (content.getString("to").contains("#")) {
roomMap.get(content.getString("to")).getUnreadCount().incrementUnreadCount();
roomsListView.refresh();
LOGGER.info("New message to room + nothing sel");
} else {
contactMap.getContact(content.getString("from")).getUnreadCount().incrementUnreadCount();
contactsListView.refresh();
LOGGER.info("New message to contact + nothing sel");
}*/
}
}
private void handleContEvent(JSONObject content) {
Contact contact = contactMap.getContact(content.getString("login"));
if (contact != null) {

View file

@ -54,7 +54,7 @@ public class ContactListViewCell extends ListCell<Contact> {
LOGGER.finest("Mise à jour de " + contact);
String unreadCountNotif = (contact.getUnreadCount().getUnreadCount() == 0) ? "" : " (%d)".formatted(contact.getUnreadCount().getUnreadCount());
LOGGER.warning("unread: %s %s".formatted(contact.getLogin(), unreadCountNotif));
LOGGER.finest("unread: %s %s".formatted(contact.getLogin(), unreadCountNotif));
Text loginText = new Text(contact.getLogin() + unreadCountNotif);
loginText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
loginText.setFill(contact.isConnected() ? Color.BLACK : Color.GRAY);

View file

@ -319,11 +319,13 @@ public class ChatServer {
} else if (user.getCurrentRoom().equals(content.getString("select"))) {
System.out.println("#");
for (Post post: postVector.getPostsSince(content.getLong("since"))) {
if (post.getTo().equals(content.getString("select"))) {
sendEventToContact(contactMap.getContact(user.getLogin()), new Event(Event.POST, post.toJsonObject()));
}
}
}
}
}
private void doMessage(JSONObject content) throws JSONException, IllegalStateException {
if (contactMap.getContact(user.getLogin()).isConnected()) {

View file

@ -19,7 +19,7 @@ java.util.logging.SimpleFormatter.format=%1$tF %1$tT.%1$tL | %4$-7s | %2$s | %5$
.level=ALL
# Niveau minimum pour les logs sur la console
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.level=ALL
# Niveau minimum pour les logs dans le fichier
java.util.logging.FileHandler.level=ALL