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 ImageView avatarImageView;
|
||||||
public SplitPane exchangeSplitPane;
|
public SplitPane exchangeSplitPane;
|
||||||
public ListView postListView;
|
public ListView postListView;
|
||||||
public ListView roomsListView;
|
public ListView<Room> roomsListView;
|
||||||
public ListView contactsListView;
|
public ListView<Contact> contactsListView;
|
||||||
public TextField messageTextField;
|
public TextField messageTextField;
|
||||||
public Button sendButton;
|
public Button sendButton;
|
||||||
public Label statusLabel;
|
public Label statusLabel;
|
||||||
|
|
@ -79,7 +79,6 @@ public class ChatController implements Initializable {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
LOGGER.info("Initialisation de l'interface graphique");
|
LOGGER.info("Initialisation de l'interface graphique");
|
||||||
|
|
||||||
Image image = new Image(Objects.requireNonNull(ChatController.class.getResourceAsStream("anonymous.png")));
|
Image image = new Image(Objects.requireNonNull(ChatController.class.getResourceAsStream("anonymous.png")));
|
||||||
this.avatarImageView.setImage(image);
|
this.avatarImageView.setImage(image);
|
||||||
|
|
||||||
|
|
@ -92,7 +91,7 @@ public class ChatController implements Initializable {
|
||||||
hostComboBox.setValue("localhost:2024");
|
hostComboBox.setValue("localhost:2024");
|
||||||
hostComboBox.setOnAction(this::statusNameUpdate);
|
hostComboBox.setOnAction(this::statusNameUpdate);
|
||||||
|
|
||||||
statusLabel.setText("not connected to " + hostComboBox.getValue());
|
statusLabel.setText("Disconnected");
|
||||||
|
|
||||||
connectionButton.disableProperty().bind(validatorLogin.containsErrorsProperty());
|
connectionButton.disableProperty().bind(validatorLogin.containsErrorsProperty());
|
||||||
connectionButton.selectedProperty().addListener(this::handleConnection);
|
connectionButton.selectedProperty().addListener(this::handleConnection);
|
||||||
|
|
@ -213,9 +212,8 @@ public class ChatController implements Initializable {
|
||||||
if (this.client.isConnected()) {
|
if (this.client.isConnected()) {
|
||||||
this.contact.setConnected(false);
|
this.contact.setConnected(false);
|
||||||
}
|
}
|
||||||
statusLabel.setText("not connected to " + hostComboBox.getValue());
|
statusLabel.setText("Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearLists() {
|
private void clearLists() {
|
||||||
|
|
@ -323,6 +321,10 @@ public class ChatController implements Initializable {
|
||||||
contactsListView.getSelectionModel().clearSelection();
|
contactsListView.getSelectionModel().clearSelection();
|
||||||
}
|
}
|
||||||
contact.setCurrentRoom(roomSelected.getRoomName());
|
contact.setCurrentRoom(roomSelected.getRoomName());
|
||||||
|
|
||||||
|
roomSelected.getUnreadCount().setUnreadCount(0);
|
||||||
|
roomsListView.refresh();
|
||||||
|
|
||||||
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans le salon " + roomSelected);
|
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans le salon " + roomSelected);
|
||||||
postsObservableList.clear();
|
postsObservableList.clear();
|
||||||
postsObservableList.add(postSys);
|
postsObservableList.add(postSys);
|
||||||
|
|
@ -340,6 +342,8 @@ public class ChatController implements Initializable {
|
||||||
roomsListView.getSelectionModel().clearSelection();
|
roomsListView.getSelectionModel().clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contactSelected.getUnreadCount().setUnreadCount(0);
|
||||||
|
|
||||||
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans la discussion avec " + contactSelected.getLogin());
|
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans la discussion avec " + contactSelected.getLogin());
|
||||||
postsObservableList.clear();
|
postsObservableList.clear();
|
||||||
postsObservableList.add(postSys);
|
postsObservableList.add(postSys);
|
||||||
|
|
@ -371,27 +375,61 @@ public class ChatController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePostEvent(JSONObject content) {
|
private void handlePostEvent(JSONObject content) {
|
||||||
if (contactsListView.getSelectionModel().getSelectedItem() != null) {
|
|
||||||
System.out.println(contactsListView.getSelectionModel().getSelectedItem());
|
System.out.println("Selected: " + roomsListView.getSelectionModel().getSelectedItem());
|
||||||
if (content.getString("to").equals(contact.getLogin()) ||
|
System.out.println("From: " + content.getString("from"));
|
||||||
content.getString("from").equals(loginTextField.getText())) {
|
System.out.println("To: " + content.getString("to"));
|
||||||
System.out.println("New message! to:dm");
|
|
||||||
postVector.add(Post.fromJson(content));
|
try {
|
||||||
postsObservableList.add(Post.fromJson(content));
|
if (!content.getString("to").contains("#")) {
|
||||||
postListView.refresh();
|
LOGGER.info("New message to contact!");
|
||||||
}
|
if (contactsListView.getSelectionModel().getSelectedItem().getLogin().equals(content.getString("to"))) {
|
||||||
} else if (roomsListView.getSelectionModel().getSelectedItem() != null) {
|
LOGGER.info("New message! to:dm, from:" + content.getString("from"));
|
||||||
if (content.getString("to").contains("#")) {
|
|
||||||
if (this.contact.getCurrentRoom().contains(content.getString("to"))) {
|
|
||||||
System.out.println("New Message! to:room");
|
|
||||||
postVector.add(Post.fromJson(content));
|
postVector.add(Post.fromJson(content));
|
||||||
postsObservableList.add(Post.fromJson(content));
|
postsObservableList.add(Post.fromJson(content));
|
||||||
postListView.refresh();
|
postListView.refresh();
|
||||||
}
|
}
|
||||||
|
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) {
|
private void handleContEvent(JSONObject content) {
|
||||||
Contact contact = contactMap.getContact(content.getString("login"));
|
Contact contact = contactMap.getContact(content.getString("login"));
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class ContactListViewCell extends ListCell<Contact> {
|
||||||
private void updateContact(Contact contact) {
|
private void updateContact(Contact contact) {
|
||||||
LOGGER.finest("Mise à jour de " + 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));
|
LOGGER.finest("unread: %s %s".formatted(contact.getLogin(), unreadCountNotif));
|
||||||
Text loginText = new Text(contact.getLogin() + unreadCountNotif);
|
Text loginText = new Text(contact.getLogin() + unreadCountNotif);
|
||||||
loginText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
|
loginText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class RoomListViewCell extends ListCell<Room> {
|
||||||
private void updateRoom(Room room) {
|
private void updateRoom(Room room) {
|
||||||
LOGGER.finest("Mise à jour de " + 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));
|
LOGGER.finest("unread: %s %s".formatted(room.getRoomName(), unreadCountNotif));
|
||||||
Text roomText = new Text(room.getRoomName() + unreadCountNotif);
|
Text roomText = new Text(room.getRoomName() + unreadCountNotif);
|
||||||
roomText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
|
roomText.setFont(Font.font(null, 12)); // FontWeight.BOLD, 14));
|
||||||
|
|
|
||||||
|
|
@ -16,25 +16,27 @@ public class Contact {
|
||||||
protected java.awt.Image avatar;
|
protected java.awt.Image avatar;
|
||||||
protected boolean connected;
|
protected boolean connected;
|
||||||
protected String currentRoom;
|
protected String currentRoom;
|
||||||
|
protected UnreadCount unreadCount = new UnreadCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée un objet Contact
|
||||||
|
* @param: String login
|
||||||
|
* @param: java.awt.Image avatar
|
||||||
|
*/
|
||||||
public Contact(String login, java.awt.Image avatar) {
|
public Contact(String login, java.awt.Image avatar) {
|
||||||
/**
|
|
||||||
* Crée un objet Contact
|
|
||||||
* @param: String login
|
|
||||||
* @param: java.awt.Image avatar
|
|
||||||
*/
|
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.currentRoom = null;
|
this.currentRoom = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
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
|
|
||||||
*/
|
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
this.connected = connected;
|
this.connected = connected;
|
||||||
|
|
@ -45,13 +47,13 @@ public class Contact {
|
||||||
return currentRoom;
|
return currentRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée un objet Contact
|
||||||
|
* @param: String login
|
||||||
|
* @param: boolean connected
|
||||||
|
* @param: File banques_avatars
|
||||||
|
*/
|
||||||
public Contact(String login, boolean connected, File banques_avatars) {
|
public Contact(String login, boolean connected, File banques_avatars) {
|
||||||
/**
|
|
||||||
* Crée un objet Contact
|
|
||||||
* @param: String login
|
|
||||||
* @param: boolean connected
|
|
||||||
* @param: File banques_avatars
|
|
||||||
*/
|
|
||||||
this.login = login;
|
this.login = login;
|
||||||
try {
|
try {
|
||||||
this.avatar = avatarFromLogin(banques_avatars, login);
|
this.avatar = avatarFromLogin(banques_avatars, login);
|
||||||
|
|
@ -99,8 +101,8 @@ public class Contact {
|
||||||
return Objects.hashCode(login);
|
return Objects.hashCode(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnreadCount() {
|
public UnreadCount getUnreadCount() {
|
||||||
return 0;
|
return unreadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject toJsonObject() {
|
public JSONObject toJsonObject() {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import java.util.Objects;
|
||||||
public class Room {
|
public class Room {
|
||||||
protected String roomName;
|
protected String roomName;
|
||||||
protected HashSet<String> loginSet;
|
protected HashSet<String> loginSet;
|
||||||
|
protected UnreadCount unreadCount = new UnreadCount();
|
||||||
|
|
||||||
|
|
||||||
public String getRoomName() {
|
public String getRoomName() {
|
||||||
|
|
@ -57,7 +58,7 @@ public class Room {
|
||||||
return this.toJsonObject().toString();
|
return this.toJsonObject().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnreadCount() {
|
public UnreadCount getUnreadCount() {
|
||||||
return 0;
|
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,7 +319,9 @@ public class ChatServer {
|
||||||
} else if (user.getCurrentRoom().equals(content.getString("select"))) {
|
} else if (user.getCurrentRoom().equals(content.getString("select"))) {
|
||||||
System.out.println("#");
|
System.out.println("#");
|
||||||
for (Post post: postVector.getPostsSince(content.getLong("since"))) {
|
for (Post post: postVector.getPostsSince(content.getLong("since"))) {
|
||||||
sendEventToContact(contactMap.getContact(user.getLogin()), new Event(Event.POST, post.toJsonObject()));
|
if (post.getTo().equals(content.getString("select"))) {
|
||||||
|
sendEventToContact(contactMap.getContact(user.getLogin()), new Event(Event.POST, post.toJsonObject()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
||||||
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
|
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
|
||||||
|
|
||||||
# Nom du fichier de logs
|
# 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
|
# 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
|
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
|
.level=ALL
|
||||||
|
|
||||||
# Niveau minimum pour les logs sur la console
|
# 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
|
# Niveau minimum pour les logs dans le fichier
|
||||||
java.util.logging.FileHandler.level=ALL
|
java.util.logging.FileHandler.level=ALL
|
||||||
Loading…
Add table
Add a link
Reference in a new issue