Bläddra i källkod

Merge pull request #377 from greboid/dev4

Add settings to the channel who plugin.
pull/378/head
Chris Smith 9 år sedan
förälder
incheckning
c18136467f

+ 6
- 1
channelwho/plugin.config Visa fil

@@ -7,6 +7,7 @@ keysections:
7 7
   metadata
8 8
   updates
9 9
   version
10
+  defaults
10 11
 
11 12
 metadata:
12 13
   author=Greg <greg@dmdirc.com>
@@ -19,4 +20,8 @@ updates:
19 20
   id=77
20 21
 
21 22
 version:
22
-  friendly=0.1
23
+  friendly=0.1
24
+
25
+defaults:
26
+  sendwho=false
27
+  whointerval=60000

+ 29
- 0
channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoManager.java Visa fil

@@ -23,10 +23,17 @@
23 23
 package com.dmdirc.addons.channelwho;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.config.prefs.PreferencesCategory;
27
+import com.dmdirc.config.prefs.PreferencesSetting;
28
+import com.dmdirc.config.prefs.PreferencesType;
29
+import com.dmdirc.events.ClientPrefsOpenedEvent;
30
+import com.dmdirc.events.GroupChatPrefsRequestedEvent;
26 31
 import com.dmdirc.events.ServerConnectingEvent;
27 32
 import com.dmdirc.events.ServerDisconnectedEvent;
28 33
 import com.dmdirc.interfaces.Connection;
29 34
 import com.dmdirc.interfaces.ConnectionManager;
35
+import com.dmdirc.plugins.PluginDomain;
36
+import com.dmdirc.util.validators.NumericalValidator;
30 37
 
31 38
 import com.google.common.annotations.VisibleForTesting;
32 39
 
@@ -42,6 +49,7 @@ import net.engio.mbassy.listener.Handler;
42 49
  */
43 50
 public class ChannelWhoManager {
44 51
 
52
+    private final String domain;
45 53
     private final ConnectionHandlerFactory connectionHandlerFactory;
46 54
     private final ConnectionManager connectionManager;
47 55
     private final DMDircMBassador eventBus;
@@ -49,9 +57,11 @@ public class ChannelWhoManager {
49 57
 
50 58
     @Inject
51 59
     public ChannelWhoManager(
60
+            @PluginDomain(ChannelWhoPlugin.class) final String domain,
52 61
             final ConnectionHandlerFactory connectionHandlerFactory,
53 62
             final ConnectionManager connectionManager,
54 63
             final DMDircMBassador eventBus) {
64
+        this.domain = domain;
55 65
         this.connectionHandlerFactory = connectionHandlerFactory;
56 66
         this.connectionManager = connectionManager;
57 67
         this.eventBus = eventBus;
@@ -79,6 +89,25 @@ public class ChannelWhoManager {
79 89
         }
80 90
     }
81 91
 
92
+    @VisibleForTesting
93
+    @Handler
94
+    void handleGroupChatPrefsRequestedEvent(final GroupChatPrefsRequestedEvent event) {
95
+        event.getCategory().addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, domain,
96
+                "sendWho", "Send Who Requests", "Should we send who requests to the channel?",
97
+                event.getConfig(), event.getIdentity()));
98
+    }
99
+
100
+    @VisibleForTesting
101
+    @Handler
102
+    void handlePrefsDialog(final ClientPrefsOpenedEvent event) {
103
+        final PreferencesCategory category = new PreferencesCategory("Channel Who", "Provides " +
104
+                "support for sending WHO requests to channels at regular intervals");
105
+        category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
106
+                new NumericalValidator(0, Integer.MAX_VALUE), domain, "whointerval",
107
+                "Who Interval", "The interval WHO requests will be sent to channels",
108
+                event.getModel().getConfigManager(), event.getModel().getIdentity()));
109
+    }
110
+
82 111
     @VisibleForTesting
83 112
     @Handler
84 113
     void handleServerConnectingEvent(final ServerConnectingEvent event) {

+ 8
- 8
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java Visa fil

@@ -81,7 +81,7 @@ public class ConnectionHandler {
81 81
         executorService.shutdown();
82 82
         connection.getWindowModel().getEventBus().unsubscribe(this);
83 83
         if (future != null) {
84
-            future.cancel(true);
84
+            future.cancel(false);
85 85
         }
86 86
     }
87 87
 
@@ -89,19 +89,19 @@ public class ConnectionHandler {
89 89
     void checkWho() {
90 90
         connectionManager.getConnections().forEach(connection ->
91 91
                 connection.getGroupChatManager().getChannels().forEach(channel -> {
92
-            if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendWho")) {
93
-                channel.requestUsersInfo();
94
-            }
95
-        }));
92
+                    if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendwho")) {
93
+                        channel.requestUsersInfo();
94
+                    }}));
96 95
     }
97 96
 
98 97
     @VisibleForTesting
99
-    @ConfigBinding(key="whoInterval")
98
+    @ConfigBinding(key="whointerval")
100 99
     void handleWhoInterval(final int value) {
101 100
         if (future != null) {
102
-            future.cancel(true);
101
+            future.cancel(false);
103 102
         }
104
-        future = executorService.schedule(this::checkWho, value, TimeUnit.MILLISECONDS);
103
+        future = executorService.scheduleAtFixedRate(this::checkWho, value, value,
104
+                TimeUnit.MILLISECONDS);
105 105
     }
106 106
 
107 107
     @VisibleForTesting

+ 2
- 1
channelwho/test/com/dmdirc/addons/channelwho/ChannelWhoManagerTest.java Visa fil

@@ -56,7 +56,8 @@ public class ChannelWhoManagerTest {
56 56
     public void setUp() throws Exception {
57 57
         when(connectionManager.getConnections()).thenReturn(Lists.newArrayList(connection));
58 58
         when(connectionHandlerFactory.get(connection)).thenReturn(connectionHandler);
59
-        instance = new ChannelWhoManager(connectionHandlerFactory, connectionManager, eventBus);
59
+        instance = new ChannelWhoManager("domain", connectionHandlerFactory, connectionManager,
60
+                eventBus);
60 61
         instance.load();
61 62
     }
62 63
 

+ 10
- 10
channelwho/test/com/dmdirc/addons/channelwho/ConnectionHandlerTest.java Visa fil

@@ -81,8 +81,8 @@ public class ConnectionHandlerTest {
81 81
 
82 82
     @Before
83 83
     public void setUp() throws Exception {
84
-        when(scheduledExecutorService.schedule(any(Runnable.class), anyLong(), any()))
85
-                .thenReturn(scheduledFuture);
84
+        when(scheduledExecutorService.scheduleAtFixedRate(any(Runnable.class), anyLong(), anyLong(),
85
+                any())).thenReturn(scheduledFuture);
86 86
         when(windowModel.getEventBus()).thenReturn(eventBus);
87 87
         when(connection.getWindowModel()).thenReturn(windowModel);
88 88
         when(config.getBinder()).thenReturn(configBinder);
@@ -107,7 +107,7 @@ public class ConnectionHandlerTest {
107 107
         instance.load();
108 108
         verify(configBinder).bind(instance, ConnectionHandler.class);
109 109
         verify(eventBus).subscribe(instance);
110
-        verify(scheduledExecutorService).schedule(any(Runnable.class), eq(5l),
110
+        verify(scheduledExecutorService).scheduleAtFixedRate(any(Runnable.class), eq(5l), eq(5l),
111 111
                 eq(TimeUnit.MILLISECONDS));
112 112
     }
113 113
 
@@ -122,26 +122,26 @@ public class ConnectionHandlerTest {
122 122
     @Test
123 123
     public void testHandleWhoInterval() throws Exception {
124 124
         instance.handleWhoInterval(10);
125
-        verify(scheduledFuture).cancel(true);
126
-        verify(scheduledExecutorService).schedule(any(Runnable.class), eq(5l),
125
+        verify(scheduledFuture).cancel(false);
126
+        verify(scheduledExecutorService).scheduleAtFixedRate(any(Runnable.class), eq(5l), eq(5l),
127 127
                 eq(TimeUnit.MILLISECONDS));
128
-        verify(scheduledExecutorService).schedule(any(Runnable.class), eq(10l),
128
+        verify(scheduledExecutorService).scheduleAtFixedRate(any(Runnable.class), eq(10l), eq(10l),
129 129
                 eq(TimeUnit.MILLISECONDS));
130 130
     }
131 131
 
132 132
     @Test
133 133
     public void testCheckWho_True() throws Exception {
134
-        when(config.getOptionBool("domain", "sendWho")).thenReturn(true);
134
+        when(config.getOptionBool("domain", "sendwho")).thenReturn(true);
135 135
         instance.checkWho();
136
-        verify(config).getOptionBool("domain", "sendWho");
136
+        verify(config).getOptionBool("domain", "sendwho");
137 137
         verify(groupChat).requestUsersInfo();
138 138
     }
139 139
 
140 140
     @Test
141 141
     public void testCheckWho_False() throws Exception {
142
-        when(config.getOptionBool("domain", "sendWho")).thenReturn(false);
142
+        when(config.getOptionBool("domain", "sendwho")).thenReturn(false);
143 143
         instance.checkWho();
144
-        verify(config).getOptionBool("domain", "sendWho");
144
+        verify(config).getOptionBool("domain", "sendwho");
145 145
         verify(groupChat, never()).requestUsersInfo();
146 146
     }
147 147
 

Laddar…
Avbryt
Spara