mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
Merge branch 'dev-notifs' into 'dev'
feat(notif): gestion des messages non lus See merge request iut_rt/but2/sae302-applicom/bouclyma!7
This commit is contained in:
commit
8c9dfc58f8
8 changed files with 107 additions and 46 deletions
|
|
@ -59,8 +59,8 @@ public class ChatController implements Initializable {
|
|||
public ImageView avatarImageView;
|
||||
public SplitPane exchangeSplitPane;
|
||||
public ListView postListView;
|
||||
public ListView roomsListView;
|
||||
public ListView contactsListView;
|
||||
public ListView<Room> roomsListView;
|
||||
public ListView<Contact> contactsListView;
|
||||
public TextField messageTextField;
|
||||
public Button sendButton;
|
||||
public Label statusLabel;
|
||||
|
|
@ -79,7 +79,6 @@ public class ChatController implements Initializable {
|
|||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
LOGGER.info("Initialisation de l'interface graphique");
|
||||
|
||||
Image image = new Image(Objects.requireNonNull(ChatController.class.getResourceAsStream("anonymous.png")));
|
||||
this.avatarImageView.setImage(image);
|
||||
|
||||
|
|
@ -92,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);
|
||||
|
|
@ -213,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() {
|
||||
|
|
@ -323,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);
|
||||
|
|
@ -340,6 +342,8 @@ public class ChatController implements Initializable {
|
|||
roomsListView.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
contactSelected.getUnreadCount().setUnreadCount(0);
|
||||
|
||||
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans la discussion avec " + contactSelected.getLogin());
|
||||
postsObservableList.clear();
|
||||
postsObservableList.add(postSys);
|
||||
|
|
@ -371,27 +375,61 @@ public class ChatController implements Initializable {
|
|||
}
|
||||
|
||||
private void handlePostEvent(JSONObject content) {
|
||||
if (contactsListView.getSelectionModel().getSelectedItem() != null) {
|
||||
System.out.println(contactsListView.getSelectionModel().getSelectedItem());
|
||||
if (content.getString("to").equals(contact.getLogin()) ||
|
||||
content.getString("from").equals(loginTextField.getText())) {
|
||||
System.out.println("New message! to:dm");
|
||||
|
||||
System.out.println("Selected: " + roomsListView.getSelectionModel().getSelectedItem());
|
||||
System.out.println("From: " + content.getString("from"));
|
||||
System.out.println("To: " + content.getString("to"));
|
||||
|
||||
try {
|
||||
if (!content.getString("to").contains("#")) {
|
||||
LOGGER.info("New message to contact!");
|
||||
if (contactsListView.getSelectionModel().getSelectedItem().getLogin().equals(content.getString("to"))) {
|
||||
LOGGER.info("New message! to:dm, from:" + content.getString("from"));
|
||||
postVector.add(Post.fromJson(content));
|
||||
postsObservableList.add(Post.fromJson(content));
|
||||
postListView.refresh();
|
||||
}
|
||||
} else if (roomsListView.getSelectionModel().getSelectedItem() != null) {
|
||||
if (content.getString("to").contains("#")) {
|
||||
if (this.contact.getCurrentRoom().contains(content.getString("to"))) {
|
||||
System.out.println("New Message! to:room");
|
||||
if (contact.getLogin().equals(content.getString("to"))) {
|
||||
if (contactsListView.getSelectionModel().getSelectedItem().getLogin().equals(content.getString("from"))) {
|
||||
LOGGER.info("New message! to:dm, from:myself");
|
||||
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:" + content.getString("from"));
|
||||
LOGGER.info("%d".formatted(contactsListView.getSelectionModel().getSelectedItem().getUnreadCount().getUnreadCount()));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
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("to")).getUnreadCount().incrementUnreadCount();
|
||||
roomsListView.refresh();
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class ContactListViewCell extends ListCell<Contact> {
|
|||
private void updateContact(Contact contact) {
|
||||
LOGGER.finest("Mise à jour de " + contact);
|
||||
|
||||
String unreadCountNotif = (contact.getUnreadCount() == 0) ? "" : " (%d)".formatted(contact.getUnreadCount());
|
||||
String unreadCountNotif = (contact.getUnreadCount().getUnreadCount() == 0) ? "" : " (%d)".formatted(contact.getUnreadCount().getUnreadCount());
|
||||
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));
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class RoomListViewCell extends ListCell<Room> {
|
|||
private void updateRoom(Room room) {
|
||||
LOGGER.finest("Mise à jour de " + room);
|
||||
|
||||
String unreadCountNotif = (room.getUnreadCount() == 0) ? "" : " (%d)".formatted(room.getUnreadCount());
|
||||
String unreadCountNotif = (room.getUnreadCount().getUnreadCount() == 0) ? "" : " (%d)".formatted(room.getUnreadCount().getUnreadCount());
|
||||
LOGGER.finest("unread: %s %s".formatted(room.getRoomName(), unreadCountNotif));
|
||||
Text roomText = new Text(room.getRoomName() + unreadCountNotif);
|
||||
roomText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
|
||||
|
|
|
|||
|
|
@ -16,25 +16,27 @@ public class Contact {
|
|||
protected java.awt.Image avatar;
|
||||
protected boolean connected;
|
||||
protected String currentRoom;
|
||||
protected UnreadCount unreadCount = new UnreadCount();
|
||||
|
||||
public Contact(String login, java.awt.Image avatar) {
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: java.awt.Image avatar
|
||||
*/
|
||||
public Contact(String login, java.awt.Image avatar) {
|
||||
this.login = login;
|
||||
this.avatar = avatar;
|
||||
this.connected = false;
|
||||
this.currentRoom = null;
|
||||
}
|
||||
public Contact(String login, boolean connected, java.awt.Image avatar) {
|
||||
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: boolean connected
|
||||
* @param: java.awt.Image avatar
|
||||
*/
|
||||
public Contact(String login, boolean connected, java.awt.Image avatar) {
|
||||
this.login = login;
|
||||
this.avatar = avatar;
|
||||
this.connected = connected;
|
||||
|
|
@ -45,13 +47,13 @@ public class Contact {
|
|||
return currentRoom;
|
||||
}
|
||||
|
||||
public Contact(String login, boolean connected, File banques_avatars) {
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: boolean connected
|
||||
* @param: File banques_avatars
|
||||
*/
|
||||
public Contact(String login, boolean connected, File banques_avatars) {
|
||||
this.login = login;
|
||||
try {
|
||||
this.avatar = avatarFromLogin(banques_avatars, login);
|
||||
|
|
@ -99,8 +101,8 @@ public class Contact {
|
|||
return Objects.hashCode(login);
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
return 0;
|
||||
public UnreadCount getUnreadCount() {
|
||||
return unreadCount;
|
||||
}
|
||||
|
||||
public JSONObject toJsonObject() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.Objects;
|
|||
public class Room {
|
||||
protected String roomName;
|
||||
protected HashSet<String> loginSet;
|
||||
protected UnreadCount unreadCount = new UnreadCount();
|
||||
|
||||
|
||||
public String getRoomName() {
|
||||
|
|
@ -57,7 +58,7 @@ public class Room {
|
|||
return this.toJsonObject().toString();
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
return 0;
|
||||
public UnreadCount getUnreadCount() {
|
||||
return this.unreadCount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
chat/src/main/java/rtgre/modeles/UnreadCount.java
Normal file
18
chat/src/main/java/rtgre/modeles/UnreadCount.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package rtgre.modeles;
|
||||
|
||||
public class UnreadCount {
|
||||
private int unreadCount = 0;
|
||||
|
||||
public int incrementUnreadCount() {
|
||||
unreadCount += 1;
|
||||
return unreadCount;
|
||||
}
|
||||
|
||||
public void setUnreadCount(int unreadCount) {
|
||||
this.unreadCount = unreadCount;
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
return unreadCount;
|
||||
}
|
||||
}
|
||||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
|||
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
|
||||
|
||||
# Nom du fichier de logs
|
||||
java.util.logging.FileHandler.pattern=../target/java%u.log
|
||||
java.util.logging.FileHandler.pattern=target/java%u.log
|
||||
|
||||
# Format de logs plus compact sur 1 seule ligne
|
||||
java.util.logging.SimpleFormatter.format=%1$tF %1$tT.%1$tL | %4$-7s | %2$s | %5$s %6$s%n
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue