diff --git a/pom.xml b/pom.xml
index d036d0d..59bb365 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
com.github.informatik-ag-ngl
envoy-common
- develop-SNAPSHOT
+ f~groups-SNAPSHOT
org.openjfx
diff --git a/src/main/java/envoy/client/data/LocalDB.java b/src/main/java/envoy/client/data/LocalDB.java
index 256e701..a9b0665 100644
--- a/src/main/java/envoy/client/data/LocalDB.java
+++ b/src/main/java/envoy/client/data/LocalDB.java
@@ -3,7 +3,9 @@ package envoy.client.data;
import java.util.*;
import envoy.data.*;
-import envoy.event.*;
+import envoy.event.GroupResizeEvent;
+import envoy.event.MessageStatusChangeEvent;
+import envoy.event.NameChangeEvent;
/**
* Stores information about the current {@link User} and their {@link Chat}s.
@@ -19,7 +21,7 @@ import envoy.event.*;
public abstract class LocalDB {
protected User user;
- protected Map users = new HashMap<>();
+ protected Map users = new HashMap<>();
protected List chats = new ArrayList<>();
protected IDGenerator idGenerator;
protected Cache messageCache = new Cache<>();
@@ -69,12 +71,12 @@ public abstract class LocalDB {
* user names as keys
* @since Envoy Client v0.2-alpha
*/
- public Map getUsers() { return users; }
+ public Map getUsers() { return users; }
/**
* @param users the users to set
*/
- public void setUsers(Map users) { this.users = users; }
+ public void setUsers(Map users) { this.users = users; }
/**
* @return all saved {@link Chat} objects that list the client user as the
@@ -161,7 +163,7 @@ public abstract class LocalDB {
* @since Envoy Client v0.1-beta
*/
public void replaceContactName(NameChangeEvent event) {
- chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == event.getId()).findAny().ifPresent(c -> c.setName(event.get()));
+ chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == event.getID()).findAny().ifPresent(c -> c.setName(event.get()));
}
/**
@@ -180,10 +182,10 @@ public abstract class LocalDB {
.ifPresent(group -> {
switch (event.getOperation()) {
case ADD:
- group.getMemberIDs().add(event.get());
+ group.getContacts().add(event.get());
break;
case REMOVE:
- group.getMemberIDs().remove(event.get());
+ group.getContacts().remove(event.get());
break;
}
});
diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java
index a61d6de..9ae69fb 100644
--- a/src/main/java/envoy/client/net/Client.java
+++ b/src/main/java/envoy/client/net/Client.java
@@ -5,6 +5,7 @@ import java.io.IOException;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.logging.Logger;
import javax.naming.TimeLimitExceededException;
@@ -15,7 +16,8 @@ import envoy.client.data.LocalDB;
import envoy.client.event.SendEvent;
import envoy.data.*;
import envoy.event.*;
-import envoy.event.ContactOperationEvent.Operation;
+import envoy.event.contact.ContactOperationEvent;
+import envoy.event.contact.ContactSearchResult;
import envoy.util.EnvoyLog;
import envoy.util.SerializationUtils;
@@ -40,9 +42,9 @@ public class Client implements Closeable {
private boolean online;
// Asynchronously initialized during handshake
- private volatile User sender;
- private volatile Contacts contacts;
- private volatile boolean rejected;
+ private volatile User sender;
+ private volatile Set extends Contact> contacts;
+ private volatile boolean rejected;
// Configuration and logging
private static final ClientConfig config = ClientConfig.getInstance();
@@ -67,7 +69,6 @@ public class Client implements Closeable {
public void performHandshake(LoginCredentials credentials, Cache receivedMessageCache)
throws TimeLimitExceededException, IOException, InterruptedException {
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
-
// Establish TCP connection
logger.info(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
socket = new Socket(config.getServer(), config.getPort());
@@ -77,8 +78,7 @@ public class Client implements Closeable {
receiver = new Receiver(socket.getInputStream());
// Register user creation processor, contact list processor and message cache
- receiver.registerProcessor(User.class, sender -> this.sender = sender);
- receiver.registerProcessor(Contacts.class, contacts -> this.contacts = contacts);
+ receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); });
receiver.registerProcessor(Message.class, receivedMessageCache);
receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; EventBus.getInstance().dispatch(evt); });
@@ -92,7 +92,7 @@ public class Client implements Closeable {
// Wait for a maximum of five seconds to acquire the sender object
long start = System.currentTimeMillis();
- while (sender == null || contacts == null) {
+ while (sender == null) {
// Quit immediately after handshake rejection
// This method can then be called again
@@ -151,8 +151,9 @@ public class Client implements Closeable {
// Process contact searches
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
- receiver.registerProcessor(Contacts.class,
- contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD)));
+ receiver.registerProcessor(Contact.class,
+ contacts -> EventBus.getInstance()
+ .dispatch(new ContactOperationEvent(contacts.getContacts().iterator().next(), ElementOperation.ADD)));
// Process group size changes
receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); EventBus.getInstance().dispatch(evt); });
@@ -218,10 +219,10 @@ public class Client implements Closeable {
* user names as keys
* @since Envoy Client v0.2-alpha
*/
- public Map getUsers() {
+ public Map getUsers() {
checkOnline();
- Map users = new HashMap<>();
- contacts.getContacts().forEach(u -> users.put(u.getName(), u));
+ Map users = new HashMap<>();
+ contacts.forEach(u -> users.put(u.getName(), u));
return users;
}
@@ -245,10 +246,10 @@ public class Client implements Closeable {
/**
* Sets the client user which is used to send messages.
*
- * @param sender the client user to set
+ * @param clientUser the client user to set
* @since Envoy Client v0.2-alpha
*/
- public void setSender(User sender) { this.sender = sender; }
+ public void setSender(User clientUser) { this.sender = clientUser; }
/**
* @return the {@link Receiver} used by this {@link Client}
@@ -265,11 +266,11 @@ public class Client implements Closeable {
* @return the contacts of this {@link Client}
* @since Envoy Client v0.3-alpha
*/
- public Contacts getContacts() { return contacts; }
+ public Set extends Contact> getContacts() { return contacts; }
/**
* @param contacts the contacts to set
* @since Envoy Client v0.3-alpha
*/
- public void setContacts(Contacts contacts) { this.contacts = contacts; }
+ public void setContacts(Set extends Contact> contacts) { this.contacts = contacts; }
}
diff --git a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java
index 761f7d8..9120662 100644
--- a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java
+++ b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java
@@ -3,6 +3,7 @@ package envoy.client.net;
import java.util.function.Consumer;
import envoy.client.data.LocalDB;
+import envoy.data.User;
import envoy.event.EventBus;
import envoy.event.UserStatusChangeEvent;
@@ -26,7 +27,7 @@ public class UserStatusChangeProcessor implements Consumer u.getID() == evt.getID()).findFirst().get().setStatus(evt.get());
+ localDB.getUsers().values().stream().filter(u -> u.getID() == evt.getID()).map(User.class::cast).findFirst().get().setStatus(evt.get());
EventBus.getInstance().dispatch(evt);
}
}
diff --git a/src/main/java/envoy/client/ui/ChatSceneController.java b/src/main/java/envoy/client/ui/ChatSceneController.java
index 1b68322..1882fba 100644
--- a/src/main/java/envoy/client/ui/ChatSceneController.java
+++ b/src/main/java/envoy/client/ui/ChatSceneController.java
@@ -3,15 +3,16 @@ package envoy.client.ui;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
import envoy.client.data.Chat;
import envoy.client.data.LocalDB;
import envoy.client.event.MessageCreationEvent;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
+import envoy.data.Contact;
import envoy.data.Message;
import envoy.data.MessageBuilder;
-import envoy.data.User;
import envoy.event.EventBus;
import envoy.event.MessageStatusChangeEvent;
import envoy.event.UserStatusChangeEvent;
@@ -26,7 +27,7 @@ import javafx.scene.input.KeyEvent;
* Project: envoy-client
* File: ChatSceneController.java
* Created: 26.03.2020
- *
+ *
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
@@ -39,7 +40,7 @@ public final class ChatSceneController {
private ListView messageList;
@FXML
- private ListView userList;
+ private ListView userList;
@FXML
private Button postButton;
@@ -95,13 +96,13 @@ public final class ChatSceneController {
this.writeProxy = writeProxy;
// TODO: handle offline mode
- userList.setItems(FXCollections.observableList(client.getContacts().getContacts()));
- // userList.getItems().addAll(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()));
+ // userList.setItems(FXCollections.observableList(client.getContacts()));
+ userList.setItems(FXCollections.observableList(localDB.getUser().getContacts().stream().collect(Collectors.toList())));
}
@FXML
private void userListClicked() {
- final User user = userList.getSelectionModel().getSelectedItem();
+ final Contact user = userList.getSelectionModel().getSelectedItem();
if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) {
contactLabel.setText(user.getName());
diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java
index c392281..e007058 100644
--- a/src/main/java/envoy/client/ui/Startup.java
+++ b/src/main/java/envoy/client/ui/Startup.java
@@ -14,6 +14,7 @@ import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
import envoy.client.ui.container.LoginDialog;
import envoy.data.Message;
+import envoy.data.User;
import envoy.data.User.UserStatus;
import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog;
@@ -28,7 +29,7 @@ import javafx.stage.Stage;
* Project: envoy-client
* File: Startup.java
* Created: 26.03.2020
- *
+ *
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
@@ -121,7 +122,12 @@ public final class Startup extends Application {
writeProxy.flushCache();
} else
// Set all contacts to offline mode
- localDB.getUsers().values().stream().filter(u -> u != localDB.getUser()).forEach(u -> u.setStatus(UserStatus.OFFLINE));
+ localDB.getUsers()
+ .values()
+ .stream()
+ .filter(u -> u instanceof User && u != localDB.getUser())
+ .map(User.class::cast)
+ .forEach(u -> u.setStatus(UserStatus.OFFLINE));
}
/**
@@ -164,5 +170,6 @@ public final class Startup extends Application {
}
}
+ @SuppressWarnings("javadoc")
public static void main(String[] args) { launch(args); }
}
diff --git a/src/main/java/envoy/client/ui/UserListCell.java b/src/main/java/envoy/client/ui/UserListCell.java
index f62f98a..cfc1fdf 100644
--- a/src/main/java/envoy/client/ui/UserListCell.java
+++ b/src/main/java/envoy/client/ui/UserListCell.java
@@ -1,5 +1,6 @@
package envoy.client.ui;
+import envoy.data.Contact;
import envoy.data.User;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
@@ -9,22 +10,24 @@ import javafx.scene.layout.VBox;
* Project: envoy-client
* File: UserListCell.java
* Created: 28.03.2020
- *
+ *
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
-public class UserListCell extends ListCell {
+public class UserListCell extends ListCell {
/**
* {@inheritDoc}
*/
@Override
- protected void updateItem(User user, boolean empty) {
- super.updateItem(user, empty);
- if (!empty && user != null) {
- final Label name = new Label(user.getName());
- final Label status = new Label(user.getStatus().toString());
- setGraphic(new VBox(name, status));
+ protected void updateItem(Contact contact, boolean empty) {
+ super.updateItem(contact, empty);
+ if (!empty && contact != null) {
+ final Label name = new Label(contact.getName());
+ if (contact instanceof User) {
+ final Label status = new Label(((User) contact).getStatus().toString());
+ setGraphic(new VBox(name, status));
+ } else setGraphic(new VBox(name));
}
}
}
diff --git a/src/main/java/envoy/client/ui/container/LoginDialog.java b/src/main/java/envoy/client/ui/container/LoginDialog.java
index 0d9f034..b523849 100644
--- a/src/main/java/envoy/client/ui/container/LoginDialog.java
+++ b/src/main/java/envoy/client/ui/container/LoginDialog.java
@@ -65,7 +65,7 @@ public class LoginDialog extends JDialog {
private static final ClientConfig config = ClientConfig.getInstance();
private static final Logger logger = EnvoyLog.getLogger(LoginDialog.class);
- private static final long serialVersionUID = 0L;
+ private static final long serialVersionUID = 0L;
/**
* Displays a dialog enabling the user to enter their user name and password.
@@ -143,7 +143,7 @@ public class LoginDialog extends JDialog {
try {
// Try entering offline mode
localDB.loadUsers();
- User clientUser = localDB.getUsers().get(credentials.getIdentifier());
+ User clientUser = (User) localDB.getUsers().get(credentials.getIdentifier());
if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown");
client.setSender(clientUser);
JOptionPane.showMessageDialog(null,