Integrated WriteProxy into the sending process

This commit is contained in:
2020-02-06 21:28:02 +01:00
parent bf38d2f19f
commit 4afe073e79
3 changed files with 37 additions and 33 deletions

View File

@ -16,6 +16,7 @@ import envoy.client.data.LocalDb;
import envoy.client.event.MessageCreationEvent;
import envoy.client.event.ThemeChangeEvent;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
import envoy.client.ui.list.ComponentList;
import envoy.client.ui.settings.SettingsScreen;
import envoy.client.util.EnvoyLog;
@ -39,8 +40,9 @@ import envoy.event.MessageStatusChangeEvent;
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();
@ -211,7 +213,7 @@ public class ChatWindow extends JFrame {
// Listen to received messages
EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> {
Message message = ((MessageCreationEvent) evt).get();
Message message = ((MessageCreationEvent) evt).get();
Chat chat = localDb.getChats().stream().filter(c -> c.getRecipient().getId() == message.getSenderId()).findFirst().get();
chat.appendMessage(message);
@ -301,8 +303,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);
@ -345,7 +346,7 @@ public class ChatWindow extends JFrame {
private void readCurrentChat() {
try {
currentChat.read(client);
currentChat.read(writeProxy);
messageList.synchronizeModel();
} catch (IOException e) {
e.printStackTrace();
@ -354,24 +355,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();
}
}