Browse Source

Add settings to the channel who plugin.

pull/377/head
Greg Holmes 9 years ago
parent
commit
399748c3db

+ 6
- 1
channelwho/plugin.config View File

@@ -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 View File

@@ -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 sendinw 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) {

+ 7
- 8
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java View File

@@ -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,18 @@ 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();}}));
96 94
     }
97 95
 
98 96
     @VisibleForTesting
99
-    @ConfigBinding(key="whoInterval")
97
+    @ConfigBinding(key="whointerval")
100 98
     void handleWhoInterval(final int value) {
101 99
         if (future != null) {
102
-            future.cancel(true);
100
+            future.cancel(false);
103 101
         }
104
-        future = executorService.schedule(this::checkWho, value, TimeUnit.MILLISECONDS);
102
+        future = executorService.scheduleAtFixedRate(this::checkWho, value, value,
103
+                TimeUnit.MILLISECONDS);
105 104
     }
106 105
 
107 106
     @VisibleForTesting

Loading…
Cancel
Save