UnreadMessagesAmount gets displayed correctly now (despite refresh bug)

This commit is contained in:
DieGurke 2020-07-10 23:25:55 +02:00
parent 1f7e5e5a3a
commit 70da595a49
5 changed files with 20 additions and 5 deletions

View File

@ -114,7 +114,7 @@ public class Chat implements Serializable {
public int getUnreadAmount() { public int getUnreadAmount() {
int unreadMessagesAmount = 0; int unreadMessagesAmount = 0;
for (int i = messages.size() - 1; i >= 0; i--) { for (int i = messages.size() - 1; i >= 0; i--) {
if (messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; if (messages.get(i).getSenderID() == recipient.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++;
else break; else break;
} }
return unreadMessagesAmount; return unreadMessagesAmount;

View File

@ -37,6 +37,16 @@ public class GroupChat extends Chat {
this.sender = sender; this.sender = sender;
} }
@Override
public int getUnreadAmount() {
int unreadMessagesAmount = 0;
for (int i = messages.size() - 1; i >= 0; i--) {
if (messages.get(i).getSenderID() != sender.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++;
else break;
}
return unreadMessagesAmount;
}
@Override @Override
public void read(WriteProxy writeProxy) throws IOException { public void read(WriteProxy writeProxy) throws IOException {
for (int i = messages.size() - 1; i >= 0; --i) { for (int i = messages.size() - 1; i >= 0; --i) {

View File

@ -121,7 +121,8 @@ public final class ChatScene implements Restorable {
logger.log(Level.WARNING, "Could not read current chat: ", e1); logger.log(Level.WARNING, "Could not read current chat: ", e1);
} }
Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); });
} // TODO set lable to getunreadmessages return value }
userList.refresh();
}); });
}); });
@ -236,6 +237,7 @@ public final class ChatScene implements Restorable {
} }
messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled); messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled);
voiceButton.setDisable(!recorder.isSupported()); voiceButton.setDisable(!recorder.isSupported());
userList.refresh();
} }
/** /**

View File

@ -23,7 +23,7 @@ public class ContactControl extends VBox {
* @param contact the contact that should be formatted * @param contact the contact that should be formatted
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public ContactControl(Contact contact) { public ContactControl(Contact contact, int unreadMessagesAmount) {
// Container with contact name // Container with contact name
final var nameLabel = new Label(contact.getName()); final var nameLabel = new Label(contact.getName());
nameLabel.setWrapText(true); nameLabel.setWrapText(true);
@ -37,7 +37,7 @@ public class ContactControl extends VBox {
} else // Member count } else // Member count
getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
final var unreadMessagesLabel = new Label("5"); final var unreadMessagesLabel = new Label("" + unreadMessagesAmount);
getChildren().add(unreadMessagesLabel); getChildren().add(unreadMessagesLabel);
} }
} }

View File

@ -16,6 +16,7 @@ import envoy.client.data.Chat;
public class ContactListCellFactory extends ListCell<Chat> { public class ContactListCellFactory extends ListCell<Chat> {
private final ListView<Chat> listView; private final ListView<Chat> listView;
private Boolean displayUnreadMessagesAmount = false;
/** /**
* @param listView the list view inside which this cell is contained * @param listView the list view inside which this cell is contained
@ -23,6 +24,8 @@ public class ContactListCellFactory extends ListCell<Chat> {
*/ */
public ContactListCellFactory(ListView<Chat> listView) { this.listView = listView; } public ContactListCellFactory(ListView<Chat> listView) { this.listView = listView; }
public void displayUnreadMessagesAmount() { displayUnreadMessagesAmount = true; }
/** /**
* Displays the name of a contact. If the contact is a user, their online status * Displays the name of a contact. If the contact is a user, their online status
* is displayed as well. * is displayed as well.
@ -36,7 +39,7 @@ public class ContactListCellFactory extends ListCell<Chat> {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {
final var control = new ContactControl(chat.getRecipient()); final var control = new ContactControl(chat.getRecipient(), chat.getUnreadAmount());
prefWidthProperty().bind(listView.widthProperty().subtract(40)); prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(control); setGraphic(control);
} }