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() {
int unreadMessagesAmount = 0;
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;
}
return unreadMessagesAmount;

View File

@ -37,6 +37,16 @@ public class GroupChat extends Chat {
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
public void read(WriteProxy writeProxy) throws IOException {
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);
}
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);
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
* @since Envoy Client v0.1-beta
*/
public ContactControl(Contact contact) {
public ContactControl(Contact contact, int unreadMessagesAmount) {
// Container with contact name
final var nameLabel = new Label(contact.getName());
nameLabel.setWrapText(true);
@ -37,7 +37,7 @@ public class ContactControl extends VBox {
} else // Member count
getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
final var unreadMessagesLabel = new Label("5");
final var unreadMessagesLabel = new Label("" + unreadMessagesAmount);
getChildren().add(unreadMessagesLabel);
}
}

View File

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