From c6819e637b64e3084b6aca8a0ba648a109e07b3e Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 22 Sep 2020 17:51:33 +0200 Subject: [PATCH 1/2] Fixed bug not updating GroupCreationTab after a new contact was added Fixes #35 --- .../client/ui/controller/ContactSearchTab.java | 7 ++++--- .../client/ui/controller/GroupCreationTab.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java index 7dcefd8..a171489 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java @@ -42,9 +42,10 @@ public class ContactSearchTab implements EventListener { @FXML private ListView userList; - private Alert alert = new Alert(AlertType.CONFIRMATION); private User currentlySelectedUser; + private final Alert alert = new Alert(AlertType.CONFIRMATION); + private static final EventBus eventBus = EventBus.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); @@ -69,7 +70,7 @@ public class ContactSearchTab implements EventListener { } /** - * Disables the clear and search button if no text is present in the search bar. + * If text is present, sends a request to the server. * * @since Envoy Client v0.1-beta */ @@ -102,7 +103,7 @@ public class ContactSearchTab implements EventListener { private void userListClicked() { final var user = userList.getSelectionModel().getSelectedItem(); if (user != null) { - currentlySelectedUser = user; + currentlySelectedUser = user; final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD); // Sends the event to the server eventBus.dispatch(new SendEvent(event)); diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index 5e8d445..d0e1c50 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -4,6 +4,7 @@ import static java.util.function.Predicate.not; import java.util.stream.Collectors; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.layout.HBox; @@ -13,6 +14,7 @@ import envoy.client.event.*; import envoy.client.ui.listcell.*; import envoy.data.*; import envoy.event.GroupCreation; +import envoy.event.contact.ContactOperation; import envoy.util.Bounds; import dev.kske.eventbus.*; @@ -70,6 +72,7 @@ public class GroupCreationTab implements EventListener { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); createButton.setDisable(true); + eventBus.registerListener(this); userList.getItems() .addAll(localDB.getChats() .stream() @@ -199,4 +202,16 @@ public class GroupCreationTab implements EventListener { errorProceedBox.setMinHeight(value); errorProceedBox.setMaxHeight(value); } + + @Event + private void onContactOperation(ContactOperation operation) { + switch (operation.getOperationType()) { + case ADD: + if (operation.get() instanceof User) Platform.runLater(() -> userList.getItems().add((User) operation.get())); + break; + case REMOVE: + Platform.runLater(() -> userList.getItems().removeIf(u -> u.equals(operation.get()))); + break; + } + } } From f0e645c0ae5c5d16dcad28a33b32deb8142366e7 Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 11:22:59 +0200 Subject: [PATCH 2/2] Fix Unread Messages Not Being Displayed for Groups (#49) Fix unread messages not being displayed for groups Fixes #48 Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/49 Reviewed-by: delvh --- .../envoy/client/ui/controller/ChatScene.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index fbec656..4ee5e38 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -222,20 +222,21 @@ public final class ChatScene implements EventListener, Restorable { // The sender of the message is the recipient of the chat // Exceptions: this user is the sender (sync) or group message (group is // recipient) - final var recipientID = message instanceof GroupMessage || message.getSenderID() == localDB.getUser().getID() ? message.getRecipientID() - : message.getSenderID(); + final boolean ownMessage = message.getSenderID() == localDB.getUser().getID(); + final var recipientID = message instanceof GroupMessage || ownMessage ? message.getRecipientID() : message.getSenderID(); + localDB.getChat(recipientID).ifPresent(chat -> { chat.insert(message); + + // Read current chat or increment unread amount if (chat.equals(currentChat)) { try { currentChat.read(writeProxy); - } catch (final IOException e1) { - logger.log(Level.WARNING, "Could not read current chat: ", e1); + } catch (final IOException e) { + logger.log(Level.WARNING, "Could not read current chat: ", e); } Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); }); - // TODO: Increment unread counter for group messages with status < RECEIVED - } else - if (message.getSenderID() != localDB.getUser().getID() && message.getStatus() == MessageStatus.RECEIVED) chat.incrementUnreadAmount(); + } else if (!ownMessage && message.getStatus() != MessageStatus.READ) chat.incrementUnreadAmount(); // Move chat with most recent unread messages to the top Platform.runLater(() -> {