mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 11:43:53 +00:00
feat(Room): compteur de messages non lus fonctionnels sur contacts, salons à réparer
This commit is contained in:
parent
619d90bf0f
commit
136054f07e
7 changed files with 85 additions and 41 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);
|
||||||
|
|
||||||
|
|
@ -340,6 +339,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,24 +372,46 @@ 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());
|
LOGGER.finest("Selected: " + contactsListView.getSelectionModel().getSelectedItem());
|
||||||
if (content.getString("to").equals(contact.getLogin()) ||
|
LOGGER.finest("From: " + content.getString("from"));
|
||||||
content.getString("from").equals(loginTextField.getText())) {
|
LOGGER.finest("To: " + content.getString("to"));
|
||||||
System.out.println("New message! to:dm");
|
|
||||||
|
if (!content.getString("to").contains("#")) {
|
||||||
|
System.out.println("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));
|
postVector.add(Post.fromJson(content));
|
||||||
postsObservableList.add(Post.fromJson(content));
|
postsObservableList.add(Post.fromJson(content));
|
||||||
postListView.refresh();
|
postListView.refresh();
|
||||||
}
|
}
|
||||||
} else if (roomsListView.getSelectionModel().getSelectedItem() != null) {
|
if (contact.getLogin().equals(content.getString("to"))) {
|
||||||
if (content.getString("to").contains("#")) {
|
if (contactsListView.getSelectionModel().getSelectedItem().getLogin().equals(content.getString("from"))) {
|
||||||
if (this.contact.getCurrentRoom().contains(content.getString("to"))) {
|
LOGGER.info("New message! to:dm, from:myself");
|
||||||
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();
|
||||||
|
} else {
|
||||||
|
contactMap.getContact(content.getString("from")).getUnreadCount().incrementUnreadCount();
|
||||||
|
contactsListView.refresh();
|
||||||
|
LOGGER.info("New unread message ! 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");
|
||||||
|
postVector.add(Post.fromJson(content));
|
||||||
|
postsObservableList.add(Post.fromJson(content));
|
||||||
|
postListView.refresh();
|
||||||
|
} else {
|
||||||
|
roomMap.get(content.getString("from")).getUnreadCount().incrementUnreadCount();
|
||||||
|
roomsListView.refresh();
|
||||||
|
LOGGER.info("New unread message ! from:");
|
||||||
|
LOGGER.info("%d".formatted(contactsListView.getSelectionModel().getSelectedItem().getUnreadCount().getUnreadCount()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ 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.warning("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));
|
||||||
loginText.setFill(contact.isConnected() ? Color.BLACK : Color.GRAY);
|
loginText.setFill(contact.isConnected() ? Color.BLACK : Color.GRAY);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
public Contact(String login, java.awt.Image avatar) {
|
|
||||||
/**
|
/**
|
||||||
* Crée un objet Contact
|
* Crée un objet Contact
|
||||||
* @param: String login
|
* @param: String login
|
||||||
* @param: java.awt.Image avatar
|
* @param: java.awt.Image avatar
|
||||||
*/
|
*/
|
||||||
|
public Contact(String login, 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;
|
||||||
}
|
}
|
||||||
public Contact(String login, boolean connected, java.awt.Image avatar) {
|
|
||||||
/**
|
/**
|
||||||
* Crée un objet Contact
|
* Crée un objet Contact
|
||||||
* @param: String login
|
* @param: String login
|
||||||
* @param: boolean connected
|
* @param: boolean connected
|
||||||
* @param: java.awt.Image avatar
|
* @param: java.awt.Image avatar
|
||||||
*/
|
*/
|
||||||
|
public Contact(String login, boolean connected, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact(String login, boolean connected, File banques_avatars) {
|
|
||||||
/**
|
/**
|
||||||
* Crée un objet Contact
|
* Crée un objet Contact
|
||||||
* @param: String login
|
* @param: String login
|
||||||
* @param: boolean connected
|
* @param: boolean connected
|
||||||
* @param: File banques_avatars
|
* @param: File banques_avatars
|
||||||
*/
|
*/
|
||||||
|
public Contact(String login, boolean connected, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue