From f9017d221613574ba2d494e7fb56e2d92b39465d Mon Sep 17 00:00:00 2001
From: mjunior <francisco.junior.mario@gmail.com>
Date: Sun, 27 Oct 2019 10:42:03 +0200
Subject: [PATCH] Refactored internal CDI events fired by ActiveUser

---
 .../java/org/emerjoin/hi/web/ActiveUser.java  | 14 +++++-----
 .../web/events/sse/AbstractChannelEvent.java  | 25 ------------------
 .../hi/web/events/sse/ChannelJoinEvent.java   | 12 ---------
 .../hi/web/events/sse/ChannelQuitEvent.java   | 11 --------
 .../hi/web/events/sse/JoinChannel.java        | 14 ++++++++++
 .../hi/web/events/sse/QuitChannel.java        | 13 ++++++++++
 .../web/events/sse/UserSubscriptionEvent.java | 26 +++++++++++++++++++
 7 files changed, 61 insertions(+), 54 deletions(-)
 delete mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/AbstractChannelEvent.java
 delete mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelJoinEvent.java
 delete mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelQuitEvent.java
 create mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/JoinChannel.java
 create mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/QuitChannel.java
 create mode 100644 Web/src/main/java/org/emerjoin/hi/web/events/sse/UserSubscriptionEvent.java

diff --git a/Web/src/main/java/org/emerjoin/hi/web/ActiveUser.java b/Web/src/main/java/org/emerjoin/hi/web/ActiveUser.java
index b63aba3..836d640 100644
--- a/Web/src/main/java/org/emerjoin/hi/web/ActiveUser.java
+++ b/Web/src/main/java/org/emerjoin/hi/web/ActiveUser.java
@@ -1,8 +1,8 @@
 package org.emerjoin.hi.web;
 
-import org.emerjoin.hi.web.events.sse.AbstractChannelEvent;
-import org.emerjoin.hi.web.events.sse.ChannelJoinEvent;
-import org.emerjoin.hi.web.events.sse.ChannelQuitEvent;
+import org.emerjoin.hi.web.events.sse.UserSubscriptionEvent;
+import org.emerjoin.hi.web.events.sse.JoinChannel;
+import org.emerjoin.hi.web.events.sse.QuitChannel;
 import org.emerjoin.hi.web.security.SecureTokenUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,7 +32,7 @@ public class ActiveUser implements Serializable {
     private static final SecureTokenUtil csrfTokeUtil = new SecureTokenUtil();
 
     @Inject
-    private transient Event<AbstractChannelEvent> channelEvent;
+    private transient Event<UserSubscriptionEvent> channelEvent;
 
     @PostConstruct
     public void init(){
@@ -90,14 +90,16 @@ public void subscribe(String webEventChannel) {
         if (webEventChannel == null || webEventChannel.isEmpty())
             throw new IllegalArgumentException("webEventChannel must not be null nor empty");
         this.webEventSubscriptions.add(webEventChannel);
-        channelEvent.fire(new ChannelJoinEvent(uniqueId, webEventChannel));
+        channelEvent.fire(new JoinChannel(this,
+                webEventChannel));
     }
 
     public void unsubscribe(String webEventChannel){
         if(webEventChannel==null||webEventChannel.isEmpty())
             throw new IllegalArgumentException("webEventChannel must not be null nor empty");
         if(this.webEventSubscriptions.remove(webEventChannel))
-            channelEvent.fire(new ChannelQuitEvent(uniqueId,webEventChannel));
+            channelEvent.fire(new QuitChannel(this,
+                    webEventChannel));
     }
 
     public boolean isSubscribedTo(String webEventChannel){
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/AbstractChannelEvent.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/AbstractChannelEvent.java
deleted file mode 100644
index 0fd097f..0000000
--- a/Web/src/main/java/org/emerjoin/hi/web/events/sse/AbstractChannelEvent.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.emerjoin.hi.web.events.sse;
-
-import org.emerjoin.hi.web.events.HiEvent;
-
-/**
- * @author Mario Junior.
- */
-public abstract class AbstractChannelEvent extends HiEvent {
-
-    private String userId;
-    private String channel;
-
-    public AbstractChannelEvent(String userId, String channel){
-        this.userId = userId;
-        this.channel = channel;
-    }
-
-    public String getUserId() {
-        return userId;
-    }
-
-    public String getChannel() {
-        return channel;
-    }
-}
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelJoinEvent.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelJoinEvent.java
deleted file mode 100644
index ec82856..0000000
--- a/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelJoinEvent.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.emerjoin.hi.web.events.sse;
-
-/**
- * @author Mario Junior.
- */
-public class ChannelJoinEvent extends AbstractChannelEvent {
-
-    public ChannelJoinEvent(String userId, String channel) {
-        super(userId, channel);
-    }
-
-}
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelQuitEvent.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelQuitEvent.java
deleted file mode 100644
index 63f6a12..0000000
--- a/Web/src/main/java/org/emerjoin/hi/web/events/sse/ChannelQuitEvent.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.emerjoin.hi.web.events.sse;
-
-/**
- * @author Mario Junior.
- */
-public class ChannelQuitEvent extends AbstractChannelEvent {
-
-    public ChannelQuitEvent(String userId, String channel) {
-        super(userId, channel);
-    }
-}
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/JoinChannel.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/JoinChannel.java
new file mode 100644
index 0000000..051ff58
--- /dev/null
+++ b/Web/src/main/java/org/emerjoin/hi/web/events/sse/JoinChannel.java
@@ -0,0 +1,14 @@
+package org.emerjoin.hi.web.events.sse;
+
+import org.emerjoin.hi.web.ActiveUser;
+
+/**
+ * @author Mario Junior.
+ */
+public class JoinChannel extends UserSubscriptionEvent {
+
+    public JoinChannel(ActiveUser user, String channel) {
+        super(user, channel);
+    }
+
+}
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/QuitChannel.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/QuitChannel.java
new file mode 100644
index 0000000..d3f0606
--- /dev/null
+++ b/Web/src/main/java/org/emerjoin/hi/web/events/sse/QuitChannel.java
@@ -0,0 +1,13 @@
+package org.emerjoin.hi.web.events.sse;
+
+import org.emerjoin.hi.web.ActiveUser;
+
+/**
+ * @author Mario Junior.
+ */
+public class QuitChannel extends UserSubscriptionEvent {
+
+    public QuitChannel(ActiveUser user, String channel) {
+        super(user, channel);
+    }
+}
diff --git a/Web/src/main/java/org/emerjoin/hi/web/events/sse/UserSubscriptionEvent.java b/Web/src/main/java/org/emerjoin/hi/web/events/sse/UserSubscriptionEvent.java
new file mode 100644
index 0000000..8ad80e2
--- /dev/null
+++ b/Web/src/main/java/org/emerjoin/hi/web/events/sse/UserSubscriptionEvent.java
@@ -0,0 +1,26 @@
+package org.emerjoin.hi.web.events.sse;
+
+import org.emerjoin.hi.web.ActiveUser;
+import org.emerjoin.hi.web.events.HiEvent;
+
+/**
+ * @author Mario Junior.
+ */
+public abstract class UserSubscriptionEvent extends HiEvent {
+
+    private ActiveUser user;
+    private String channel;
+
+    public UserSubscriptionEvent(ActiveUser user, String channel){
+        this.user = user;
+        this.channel = channel;
+    }
+
+    public ActiveUser getUser() {
+        return user;
+    }
+
+    public String getChannel() {
+        return channel;
+    }
+}