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 bcf4388..9ea7c80 100644
--- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java
+++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java
@@ -15,6 +15,7 @@ import java.util.logging.Logger;
import javafx.animation.RotateTransition;
import javafx.application.Platform;
import javafx.collections.FXCollections;
+import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.*;
@@ -110,6 +111,9 @@ public final class ChatScene implements Restorable {
@FXML
private ImageView recipientProfilePic;
+ @FXML
+ private TextArea contactSearch;
+
private LocalDB localDB;
private Client client;
private WriteProxy writeProxy;
@@ -128,6 +132,8 @@ public final class ChatScene implements Restorable {
private static final Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20);
private static final int MAX_MESSAGE_LENGTH = 255;
private static final int DEFAULT_ICON_SIZE = 16;
+
+ private FilteredList extends Chat> chats;
/**
* Initializes the appearance of certain visual components.
@@ -239,8 +245,9 @@ public final class ChatScene implements Restorable {
this.localDB = localDB;
this.client = client;
this.writeProxy = writeProxy;
-
- chatList.setItems(FXCollections.observableList(localDB.getChats()));
+
+ chats = new FilteredList<>(FXCollections.observableList(localDB.getChats()));
+ chatList.setItems(chats);
contactLabel.setText(localDB.getUser().getName());
MessageControl.setLocalDB(localDB);
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
@@ -544,8 +551,8 @@ public final class ChatScene implements Restorable {
currentChat.insert(message);
// Moving currentChat to the top
Platform.runLater(() -> {
- chatList.getItems().remove(currentChat);
- chatList.getItems().add(0, currentChat);
+ chats.getSource().remove(currentChat);
+ chats.getSource().add(0, currentChat);
chatList.getSelectionModel().select(0);
localDB.getChats().remove(currentChat);
localDB.getChats().add(0, currentChat);
@@ -616,4 +623,10 @@ public final class ChatScene implements Restorable {
updateRemainingCharsLabel();
postButton.setDisable(messageText.isBlank());
}
+
+ @FXML
+ private void searchContacts() {
+ chats.setPredicate(contactSearch.getText().isBlank() ? c -> true
+ : c -> c.getRecipient().getName().toLowerCase().contains(contactSearch.getText().toLowerCase()));
+ }
}
diff --git a/client/src/main/resources/fxml/ChatScene.fxml b/client/src/main/resources/fxml/ChatScene.fxml
index 65efe79..714b469 100644
--- a/client/src/main/resources/fxml/ChatScene.fxml
+++ b/client/src/main/resources/fxml/ChatScene.fxml
@@ -30,21 +30,37 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+