Merge branch 'develop' into f/contacts

This commit is contained in:
2020-02-11 10:06:06 +01:00
committed by GitHub
15 changed files with 461 additions and 157 deletions

View File

@ -17,6 +17,7 @@ import envoy.client.data.Chat;
import envoy.client.data.LocalDb;
import envoy.client.event.*;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListModel;
import envoy.client.ui.settings.SettingsScreen;
@ -41,8 +42,9 @@ import envoy.event.ContactOperationEvent.Operation;
public class ChatWindow extends JFrame {
// User specific objects
private Client client;
private LocalDb localDb;
private Client client;
private WriteProxy writeProxy;
private LocalDb localDb;
// GUI components
private JPanel contentPane = new JPanel();
@ -359,6 +361,9 @@ public class ChatWindow extends JFrame {
// Listen to theme changes
EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get()));
// Listen to user status changes
EventBus.getInstance().register(UserStatusChangeEvent.class, (evt) -> { userList.revalidate(); userList.repaint(); });
// Listen to received messages
EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> {
Message message = ((MessageCreationEvent) evt).get();
@ -498,8 +503,7 @@ public class ChatWindow extends JFrame {
.build();
// Send message
// TODO: Store offline messages
client.sendMessage(message);
writeProxy.writeMessage(message);
// Add message to PersistentLocalDb and update UI
currentChat.appendMessage(message);
@ -544,7 +548,7 @@ public class ChatWindow extends JFrame {
private void readCurrentChat() {
try {
currentChat.read(client);
currentChat.read(writeProxy);
messageList.synchronizeModel();
} catch (IOException e) {
e.printStackTrace();
@ -571,24 +575,23 @@ public class ChatWindow extends JFrame {
}
/**
* Sets the {@link Client} used by this {@link ChatWindow}.
* Initializes the components responsible server communication and
* persistence.<br>
* <br>
* This will trigger the display of the contact list.
*
* @param client the {@link Client} used to send and receive messages
* @since Envoy v0.2-alpha
* @param client the client used to send and receive messages
* @param localDb the local database used to manage stored messages
* and users
* @param writeProxy the write proxy used to send messages and status change
* events to the server or cache them inside the local
* database
* @since Envoy v0.3-alpha
*/
public void setClient(Client client) { this.client = client; }
/**
* Sets the {@link LocalDb} used by this {@link ChatWindow}. After
* invoking this
* method, users and chats will be loaded from the database into the GUI.
*
* @param localDb the {@link LocalDb} used to manage stored messages
* and users
* @since Envoy v0.2-alpha
*/
public void setLocalDB(LocalDb localDb) {
this.localDb = localDb;
public void initContent(Client client, LocalDb localDb, WriteProxy writeProxy) {
this.client = client;
this.localDb = localDb;
this.writeProxy = writeProxy;
loadUsersAndChats();
}
}