restored compatibility with envoy common (and envoy server standalone)
This commit is contained in:
parent
9460b224b9
commit
ba67af613d
2
pom.xml
2
pom.xml
@ -28,7 +28,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.informatik-ag-ngl</groupId>
|
<groupId>com.github.informatik-ag-ngl</groupId>
|
||||||
<artifactId>envoy-common</artifactId>
|
<artifactId>envoy-common</artifactId>
|
||||||
<version>develop-SNAPSHOT</version>
|
<version>f~groups-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
|
@ -3,7 +3,9 @@ package envoy.client.data;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import envoy.data.*;
|
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.
|
* Stores information about the current {@link User} and their {@link Chat}s.
|
||||||
@ -19,7 +21,7 @@ import envoy.event.*;
|
|||||||
public abstract class LocalDB {
|
public abstract class LocalDB {
|
||||||
|
|
||||||
protected User user;
|
protected User user;
|
||||||
protected Map<String, User> users = new HashMap<>();
|
protected Map<String, Contact> users = new HashMap<>();
|
||||||
protected List<Chat> chats = new ArrayList<>();
|
protected List<Chat> chats = new ArrayList<>();
|
||||||
protected IDGenerator idGenerator;
|
protected IDGenerator idGenerator;
|
||||||
protected Cache<Message> messageCache = new Cache<>();
|
protected Cache<Message> messageCache = new Cache<>();
|
||||||
@ -69,12 +71,12 @@ public abstract class LocalDB {
|
|||||||
* user names as keys
|
* user names as keys
|
||||||
* @since Envoy Client v0.2-alpha
|
* @since Envoy Client v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public Map<String, User> getUsers() { return users; }
|
public Map<String, Contact> getUsers() { return users; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param users the users to set
|
* @param users the users to set
|
||||||
*/
|
*/
|
||||||
public void setUsers(Map<String, User> users) { this.users = users; }
|
public void setUsers(Map<String, Contact> users) { this.users = users; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all saved {@link Chat} objects that list the client user as the
|
* @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
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public void replaceContactName(NameChangeEvent event) {
|
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 -> {
|
.ifPresent(group -> {
|
||||||
switch (event.getOperation()) {
|
switch (event.getOperation()) {
|
||||||
case ADD:
|
case ADD:
|
||||||
group.getMemberIDs().add(event.get());
|
group.getContacts().add(event.get());
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
group.getMemberIDs().remove(event.get());
|
group.getContacts().remove(event.get());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.naming.TimeLimitExceededException;
|
import javax.naming.TimeLimitExceededException;
|
||||||
@ -15,7 +16,8 @@ import envoy.client.data.LocalDB;
|
|||||||
import envoy.client.event.SendEvent;
|
import envoy.client.event.SendEvent;
|
||||||
import envoy.data.*;
|
import envoy.data.*;
|
||||||
import envoy.event.*;
|
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.EnvoyLog;
|
||||||
import envoy.util.SerializationUtils;
|
import envoy.util.SerializationUtils;
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ public class Client implements Closeable {
|
|||||||
|
|
||||||
// Asynchronously initialized during handshake
|
// Asynchronously initialized during handshake
|
||||||
private volatile User sender;
|
private volatile User sender;
|
||||||
private volatile Contacts contacts;
|
private volatile Set<? extends Contact> contacts;
|
||||||
private volatile boolean rejected;
|
private volatile boolean rejected;
|
||||||
|
|
||||||
// Configuration and logging
|
// Configuration and logging
|
||||||
@ -67,7 +69,6 @@ public class Client implements Closeable {
|
|||||||
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache)
|
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache)
|
||||||
throws TimeLimitExceededException, IOException, InterruptedException {
|
throws TimeLimitExceededException, IOException, InterruptedException {
|
||||||
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
||||||
|
|
||||||
// Establish TCP connection
|
// Establish TCP connection
|
||||||
logger.info(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
|
logger.info(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
|
||||||
socket = new Socket(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());
|
receiver = new Receiver(socket.getInputStream());
|
||||||
|
|
||||||
// Register user creation processor, contact list processor and message cache
|
// Register user creation processor, contact list processor and message cache
|
||||||
receiver.registerProcessor(User.class, sender -> this.sender = sender);
|
receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); });
|
||||||
receiver.registerProcessor(Contacts.class, contacts -> this.contacts = contacts);
|
|
||||||
receiver.registerProcessor(Message.class, receivedMessageCache);
|
receiver.registerProcessor(Message.class, receivedMessageCache);
|
||||||
receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; EventBus.getInstance().dispatch(evt); });
|
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
|
// Wait for a maximum of five seconds to acquire the sender object
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (sender == null || contacts == null) {
|
while (sender == null) {
|
||||||
|
|
||||||
// Quit immediately after handshake rejection
|
// Quit immediately after handshake rejection
|
||||||
// This method can then be called again
|
// This method can then be called again
|
||||||
@ -151,8 +151,9 @@ public class Client implements Closeable {
|
|||||||
// Process contact searches
|
// Process contact searches
|
||||||
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
|
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
|
||||||
|
|
||||||
receiver.registerProcessor(Contacts.class,
|
receiver.registerProcessor(Contact.class,
|
||||||
contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD)));
|
contacts -> EventBus.getInstance()
|
||||||
|
.dispatch(new ContactOperationEvent(contacts.getContacts().iterator().next(), ElementOperation.ADD)));
|
||||||
|
|
||||||
// Process group size changes
|
// Process group size changes
|
||||||
receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); EventBus.getInstance().dispatch(evt); });
|
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
|
* user names as keys
|
||||||
* @since Envoy Client v0.2-alpha
|
* @since Envoy Client v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public Map<String, User> getUsers() {
|
public Map<String, Contact> getUsers() {
|
||||||
checkOnline();
|
checkOnline();
|
||||||
Map<String, User> users = new HashMap<>();
|
Map<String, Contact> users = new HashMap<>();
|
||||||
contacts.getContacts().forEach(u -> users.put(u.getName(), u));
|
contacts.forEach(u -> users.put(u.getName(), u));
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,10 +246,10 @@ public class Client implements Closeable {
|
|||||||
/**
|
/**
|
||||||
* Sets the client user which is used to send messages.
|
* 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
|
* @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}
|
* @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}
|
* @return the contacts of this {@link Client}
|
||||||
* @since Envoy Client v0.3-alpha
|
* @since Envoy Client v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public Contacts getContacts() { return contacts; }
|
public Set<? extends Contact> getContacts() { return contacts; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param contacts the contacts to set
|
* @param contacts the contacts to set
|
||||||
* @since Envoy Client v0.3-alpha
|
* @since Envoy Client v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public void setContacts(Contacts contacts) { this.contacts = contacts; }
|
public void setContacts(Set<? extends Contact> contacts) { this.contacts = contacts; }
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package envoy.client.net;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import envoy.client.data.LocalDB;
|
import envoy.client.data.LocalDB;
|
||||||
|
import envoy.data.User;
|
||||||
import envoy.event.EventBus;
|
import envoy.event.EventBus;
|
||||||
import envoy.event.UserStatusChangeEvent;
|
import envoy.event.UserStatusChangeEvent;
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(UserStatusChangeEvent evt) {
|
public void accept(UserStatusChangeEvent evt) {
|
||||||
localDB.getUsers().values().stream().filter(u -> 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);
|
EventBus.getInstance().dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,16 @@ package envoy.client.ui;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import envoy.client.data.Chat;
|
import envoy.client.data.Chat;
|
||||||
import envoy.client.data.LocalDB;
|
import envoy.client.data.LocalDB;
|
||||||
import envoy.client.event.MessageCreationEvent;
|
import envoy.client.event.MessageCreationEvent;
|
||||||
import envoy.client.net.Client;
|
import envoy.client.net.Client;
|
||||||
import envoy.client.net.WriteProxy;
|
import envoy.client.net.WriteProxy;
|
||||||
|
import envoy.data.Contact;
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.MessageBuilder;
|
import envoy.data.MessageBuilder;
|
||||||
import envoy.data.User;
|
|
||||||
import envoy.event.EventBus;
|
import envoy.event.EventBus;
|
||||||
import envoy.event.MessageStatusChangeEvent;
|
import envoy.event.MessageStatusChangeEvent;
|
||||||
import envoy.event.UserStatusChangeEvent;
|
import envoy.event.UserStatusChangeEvent;
|
||||||
@ -39,7 +40,7 @@ public final class ChatSceneController {
|
|||||||
private ListView<Message> messageList;
|
private ListView<Message> messageList;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<User> userList;
|
private ListView<Contact> userList;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button postButton;
|
private Button postButton;
|
||||||
@ -95,13 +96,13 @@ public final class ChatSceneController {
|
|||||||
this.writeProxy = writeProxy;
|
this.writeProxy = writeProxy;
|
||||||
|
|
||||||
// TODO: handle offline mode
|
// TODO: handle offline mode
|
||||||
userList.setItems(FXCollections.observableList(client.getContacts().getContacts()));
|
// userList.setItems(FXCollections.observableList(client.getContacts()));
|
||||||
// userList.getItems().addAll(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()));
|
userList.setItems(FXCollections.observableList(localDB.getUser().getContacts().stream().collect(Collectors.toList())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void userListClicked() {
|
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())) {
|
if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) {
|
||||||
contactLabel.setText(user.getName());
|
contactLabel.setText(user.getName());
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import envoy.client.net.Client;
|
|||||||
import envoy.client.net.WriteProxy;
|
import envoy.client.net.WriteProxy;
|
||||||
import envoy.client.ui.container.LoginDialog;
|
import envoy.client.ui.container.LoginDialog;
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
|
import envoy.data.User;
|
||||||
import envoy.data.User.UserStatus;
|
import envoy.data.User.UserStatus;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
import envoy.util.EnvoyLog;
|
import envoy.util.EnvoyLog;
|
||||||
@ -121,7 +122,12 @@ public final class Startup extends Application {
|
|||||||
writeProxy.flushCache();
|
writeProxy.flushCache();
|
||||||
} else
|
} else
|
||||||
// Set all contacts to offline mode
|
// 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); }
|
public static void main(String[] args) { launch(args); }
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import envoy.data.Contact;
|
||||||
import envoy.data.User;
|
import envoy.data.User;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
@ -13,18 +14,20 @@ import javafx.scene.layout.VBox;
|
|||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public class UserListCell extends ListCell<User> {
|
public class UserListCell extends ListCell<Contact> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void updateItem(User user, boolean empty) {
|
protected void updateItem(Contact contact, boolean empty) {
|
||||||
super.updateItem(user, empty);
|
super.updateItem(contact, empty);
|
||||||
if (!empty && user != null) {
|
if (!empty && contact != null) {
|
||||||
final Label name = new Label(user.getName());
|
final Label name = new Label(contact.getName());
|
||||||
final Label status = new Label(user.getStatus().toString());
|
if (contact instanceof User) {
|
||||||
|
final Label status = new Label(((User) contact).getStatus().toString());
|
||||||
setGraphic(new VBox(name, status));
|
setGraphic(new VBox(name, status));
|
||||||
|
} else setGraphic(new VBox(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ public class LoginDialog extends JDialog {
|
|||||||
try {
|
try {
|
||||||
// Try entering offline mode
|
// Try entering offline mode
|
||||||
localDB.loadUsers();
|
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");
|
if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown");
|
||||||
client.setSender(clientUser);
|
client.setSender(clientUser);
|
||||||
JOptionPane.showMessageDialog(null,
|
JOptionPane.showMessageDialog(null,
|
||||||
|
Reference in New Issue
Block a user