From ead2eab5a018c8be4fe0640ec5d000ce604ef71a Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 15:27:26 +0100 Subject: [PATCH 1/4] Added the UserStatusChangeProcessor and its implementation this commit serves as solution to the merge conflict between f/user_status_change_processor and develop --- src/main/java/envoy/client/net/Client.java | 21 ++++++++-- .../client/net/UserStatusChangeProcessor.java | 40 +++++++++++++++++++ src/main/java/envoy/client/ui/ChatWindow.java | 4 ++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/main/java/envoy/client/net/UserStatusChangeProcessor.java diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index d742f1b..9c52992 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -14,9 +14,7 @@ import envoy.client.data.Config; import envoy.client.data.LocalDb; import envoy.client.util.EnvoyLog; import envoy.data.*; -import envoy.event.Event; -import envoy.event.IdGeneratorRequest; -import envoy.event.MessageStatusChangeEvent; +import envoy.event.*; import envoy.util.SerializationUtils; /** @@ -100,6 +98,8 @@ public class Client implements Closeable { receiver.removeAllProcessors(); // Register processors for message and status handling + + // Process incoming messages final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor(); receiver.registerProcessor(Message.class, receivedMessageProcessor); @@ -109,6 +109,9 @@ public class Client implements Closeable { // Process message status changes receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor()); + // Process user status changes + receiver.registerProcessor(UserStatusChangeEvent.class, new UserStatusChangeProcessor(this)); + // Process message ID generation receiver.registerProcessor(IdGenerator.class, localDb::setIdGenerator); @@ -207,4 +210,16 @@ public class Client implements Closeable { * @since Envoy v0.2-alpha */ public boolean isOnline() { return online; } + + /** + * @return the contacts of this {@link Client} + * @since Envoy v0.3-alpha + */ + public Contacts getContacts() { return contacts; } + + /** + * @param contacts the contacts to set + * @since Envoy v0.3-alpha + */ + public void setContacts(Contacts contacts) { this.contacts = contacts; } } \ No newline at end of file diff --git a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java new file mode 100644 index 0000000..4f98358 --- /dev/null +++ b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java @@ -0,0 +1,40 @@ +package envoy.client.net; + +import java.util.List; +import java.util.function.Consumer; +import java.util.logging.Logger; + +import envoy.client.util.EnvoyLog; +import envoy.data.User; +import envoy.event.EventBus; +import envoy.event.UserStatusChangeEvent; + +/** + * Project: envoy-client
+ * File: UserStatusChangeProcessor.java
+ * Created: 2 Feb 2020
+ * + * @author Leon Hofmeister + * @since Envoy v0.3-alpha + */ +public class UserStatusChangeProcessor implements Consumer { + + private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class.getSimpleName()); + private Client client; + + /** + * @param client the {@link Client} who receives an + * {@link UserStatusChangeEvent} + * @since Envoy v0.3-alpha + */ + public UserStatusChangeProcessor(Client client) { this.client = client; } + + @Override + public void accept(UserStatusChangeEvent evt) { + logger.info("Received " + evt); + List contacts = client.getContacts().getContacts(); + contacts.stream().filter((user) -> user.getId() == evt.getId()).findFirst().get().setStatus(evt.get()); + EventBus.getInstance().dispatch(evt); + } + +} \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 7d537bf..8a7723e 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -26,6 +26,7 @@ import envoy.data.MessageBuilder; import envoy.data.User; import envoy.event.EventBus; import envoy.event.MessageStatusChangeEvent; +import envoy.event.UserStatusChangeEvent; /** * Project: envoy-client
@@ -211,6 +212,9 @@ public class ChatWindow extends JFrame { // Listen to theme changes EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get())); + // Listen to UserStatus 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(); From 778e76faa7dc81f7fcb119ca1417ac4e8c515aa4 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 15:41:17 +0100 Subject: [PATCH 2/4] added newline at the end of Client file --- src/main/java/envoy/client/net/Client.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 9c52992..6199b3b 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -222,4 +222,4 @@ public class Client implements Closeable { * @since Envoy v0.3-alpha */ public void setContacts(Contacts contacts) { this.contacts = contacts; } -} \ No newline at end of file +} From f9ce464aaadb27bfb74f247087bf86f3f333f7f0 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 15:43:33 +0100 Subject: [PATCH 3/4] added newline at the end of UserStatusChangeProcessor file --- src/main/java/envoy/client/net/UserStatusChangeProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java index 4f98358..280c834 100644 --- a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java +++ b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java @@ -37,4 +37,4 @@ public class UserStatusChangeProcessor implements Consumer Date: Fri, 7 Feb 2020 15:57:41 +0100 Subject: [PATCH 4/4] Redesigned UserStatusChangeProcessor to please @CyB3RC0nN0R s wishes --- .../envoy/client/net/UserStatusChangeProcessor.java | 11 ++++------- src/main/java/envoy/client/ui/ChatWindow.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java index 280c834..744e6e8 100644 --- a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java +++ b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java @@ -1,11 +1,9 @@ package envoy.client.net; -import java.util.List; import java.util.function.Consumer; import java.util.logging.Logger; import envoy.client.util.EnvoyLog; -import envoy.data.User; import envoy.event.EventBus; import envoy.event.UserStatusChangeEvent; @@ -19,8 +17,9 @@ import envoy.event.UserStatusChangeEvent; */ public class UserStatusChangeProcessor implements Consumer { - private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class.getSimpleName()); - private Client client; + private Client client; + + private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class.getSimpleName()); /** * @param client the {@link Client} who receives an @@ -32,9 +31,7 @@ public class UserStatusChangeProcessor implements Consumer contacts = client.getContacts().getContacts(); - contacts.stream().filter((user) -> user.getId() == evt.getId()).findFirst().get().setStatus(evt.get()); + client.getContacts().getContacts().stream().filter((user) -> user.getId() == evt.getId()).findFirst().get().setStatus(evt.get()); EventBus.getInstance().dispatch(evt); } - } diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 8a7723e..0e12611 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -212,7 +212,7 @@ public class ChatWindow extends JFrame { // Listen to theme changes EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get())); - // Listen to UserStatus changes + // Listen to user status changes EventBus.getInstance().register(UserStatusChangeEvent.class, (evt) -> { userList.revalidate(); userList.repaint(); }); // Listen to received messages