Browse Source

Merge pull request #343 from csmith/channelwho

Add framework for channel who plugin.
pull/345/head
Greg Holmes 9 years ago
parent
commit
7b1afe73ee

+ 39
- 1
channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoManager.java View File

@@ -22,22 +22,60 @@
22 22
 
23 23
 package com.dmdirc.addons.channelwho;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.events.ServerConnectingEvent;
27
+import com.dmdirc.events.ServerDisconnectedEvent;
28
+import com.dmdirc.interfaces.Connection;
29
+import com.dmdirc.interfaces.ConnectionManager;
25 30
 import com.dmdirc.plugins.PluginDomain;
26 31
 
27 32
 import javax.inject.Inject;
28 33
 
34
+import net.engio.mbassy.listener.Handler;
35
+
29 36
 /**
30 37
  * Provides channel who support in DMDirc.
31 38
  */
32 39
 public class ChannelWhoManager {
33 40
 
41
+    private final ConnectionManager connectionManager;
42
+    private final DMDircMBassador eventBus;
43
+
34 44
     @Inject
35
-    public ChannelWhoManager(@PluginDomain(ChannelWhoPlugin.class) final String domain) {
45
+    public ChannelWhoManager(
46
+            @PluginDomain(ChannelWhoPlugin.class) final String domain,
47
+            final ConnectionManager connectionManager,
48
+            final DMDircMBassador eventBus) {
49
+        this.connectionManager = connectionManager;
50
+        this.eventBus = eventBus;
36 51
     }
37 52
 
38 53
     public void load() {
54
+        eventBus.subscribe(this);
55
+        connectionManager.getConnections().forEach(this::addConnectionHandler);
39 56
     }
40 57
 
41 58
     public void unload() {
59
+        connectionManager.getConnections().forEach(this::removeConnectionHandler);
60
+        eventBus.unsubscribe(this);
61
+    }
62
+
63
+    private void addConnectionHandler(final Connection connection) {
64
+        // TODO: Create a handler class which will monitor settings + handle timers.
65
+    }
66
+
67
+    private void removeConnectionHandler(final Connection connection) {
68
+        // TODO: Remove handlers
42 69
     }
70
+
71
+    @Handler
72
+    private void handleServerConnectingEvent(final ServerConnectingEvent event) {
73
+        addConnectionHandler(event.getConnection());
74
+    }
75
+
76
+    @Handler
77
+    private void handleServerDisconnectedEvent(final ServerDisconnectedEvent event) {
78
+        removeConnectionHandler(event.getConnection());
79
+    }
80
+
43 81
 }

+ 1
- 1
channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoPlugin.java View File

@@ -38,7 +38,7 @@ public class ChannelWhoPlugin extends BasePlugin {
38 38
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39 39
         super.load(pluginInfo, graph);
40 40
 
41
-        setObjectGraph(graph.plus(new ChannelWhoManager(pluginInfo.getDomain())));
41
+        setObjectGraph(graph.plus(new ChannelWhoModule(pluginInfo.getDomain())));
42 42
         manager = getObjectGraph().get(ChannelWhoManager.class);
43 43
     }
44 44
 

+ 8
- 1
channelwho/test/com/dmdirc/addons/channelwho/ChannelWhoManagerTest.java View File

@@ -22,19 +22,26 @@
22 22
 
23 23
 package com.dmdirc.addons.channelwho;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.interfaces.ConnectionManager;
27
+
25 28
 import org.junit.Before;
26 29
 import org.junit.Test;
27 30
 import org.junit.runner.RunWith;
31
+import org.mockito.Mock;
28 32
 import org.mockito.runners.MockitoJUnitRunner;
29 33
 
30 34
 @RunWith(MockitoJUnitRunner.class)
31 35
 public class ChannelWhoManagerTest {
32 36
 
37
+    @Mock private ConnectionManager connectionManager;
38
+    @Mock private DMDircMBassador eventBus;
39
+
33 40
     private ChannelWhoManager instance;
34 41
 
35 42
     @Before
36 43
     public void setUp() throws Exception {
37
-        instance = new ChannelWhoManager("test");
44
+        instance = new ChannelWhoManager("test", connectionManager, eventBus);
38 45
     }
39 46
 
40 47
     @Test

Loading…
Cancel
Save