From 577ee6364d02dd7f13899a7278bff0c5a40c1901 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Tue, 11 Feb 2020 18:15:15 +0100 Subject: [PATCH] Implemented contact list update --- .../java/envoy/client/event/SendEvent.java | 23 +++++++++++++++++++ src/main/java/envoy/client/net/Client.java | 14 +++++++++++ src/main/java/envoy/client/ui/ChatWindow.java | 6 ----- .../client/ui/ContactsSearchRenderer.java | 7 +++++- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 src/main/java/envoy/client/event/SendEvent.java diff --git a/src/main/java/envoy/client/event/SendEvent.java b/src/main/java/envoy/client/event/SendEvent.java new file mode 100644 index 0000000..2d95fc8 --- /dev/null +++ b/src/main/java/envoy/client/event/SendEvent.java @@ -0,0 +1,23 @@ +package envoy.client.event; + +import envoy.event.Event; + +/** + * Project: envoy-client
+ * File: SendEvent.java
+ * Created: 11.02.2020
+ * + * @author: Maximilian Käfer + * + * @since Envoy v0.3-alpha + */ +public class SendEvent extends Event> { + + private static final long serialVersionUID = 8372746924138839060L; + + /** + * @param value the event to send to the server + */ + public SendEvent(Event value) { super(value); } + +} diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 550b7f2..b9985c1 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -12,9 +12,11 @@ import javax.naming.TimeLimitExceededException; import envoy.client.data.Cache; import envoy.client.data.Config; import envoy.client.data.LocalDb; +import envoy.client.event.SendEvent; import envoy.client.util.EnvoyLog; import envoy.data.*; import envoy.event.*; +import envoy.event.ContactOperationEvent.Operation; import envoy.util.SerializationUtils; /** @@ -116,6 +118,18 @@ 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))); + + // Send event + EventBus.getInstance().register(SendEvent.class, evt -> { + try { + sendEvent(((SendEvent) evt).get()); + } catch (IOException e) { + e.printStackTrace(); + } + }); + // Request a generator if none is present or the existing one is consumed if (!localDb.hasIdGenerator() || !localDb.getIdGenerator().hasNext()) requestIdGenerator(); } diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 5a0898f..a278325 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -411,12 +411,6 @@ public class ChatWindow extends JFrame { EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> { - try { - client.sendEvent(evt); - } catch (IOException e) { - e.printStackTrace(); - } - User contact = (User) evt.get(); // Clearing the search field and the searchResultList diff --git a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java index c469475..078e289 100644 --- a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java +++ b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java @@ -7,6 +7,7 @@ import java.awt.Font; import javax.swing.*; import envoy.client.Settings; +import envoy.client.event.SendEvent; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListCellRenderer; import envoy.data.User; @@ -61,7 +62,11 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer { add.setBackground(list.getBackground()); add.setForeground(list.getForeground()); - add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD)); }); + add.addActionListener(evt -> { + ContactOperationEvent contactsOperationEvent = new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD); + EventBus.getInstance().dispatch(contactsOperationEvent); + EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent)); + }); panel.add(add);