Skip to content

Commit

Permalink
Add settings to the channel who plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Holmes committed Jan 19, 2015
1 parent 7666ab9 commit 399748c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
7 changes: 6 additions & 1 deletion channelwho/plugin.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ keysections:
metadata
updates
version
defaults

metadata:
author=Greg <greg@dmdirc.com>
Expand All @@ -19,4 +20,8 @@ updates:
id=77

version:
friendly=0.1
friendly=0.1

defaults:
sendwho=false
whointerval=60000
29 changes: 29 additions & 0 deletions channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@
package com.dmdirc.addons.channelwho;

import com.dmdirc.DMDircMBassador;
import com.dmdirc.config.prefs.PreferencesCategory;
import com.dmdirc.config.prefs.PreferencesSetting;
import com.dmdirc.config.prefs.PreferencesType;
import com.dmdirc.events.ClientPrefsOpenedEvent;
import com.dmdirc.events.GroupChatPrefsRequestedEvent;
import com.dmdirc.events.ServerConnectingEvent;
import com.dmdirc.events.ServerDisconnectedEvent;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.interfaces.ConnectionManager;
import com.dmdirc.plugins.PluginDomain;
import com.dmdirc.util.validators.NumericalValidator;

import com.google.common.annotations.VisibleForTesting;

Expand All @@ -42,16 +49,19 @@
*/
public class ChannelWhoManager {

private final String domain;
private final ConnectionHandlerFactory connectionHandlerFactory;
private final ConnectionManager connectionManager;
private final DMDircMBassador eventBus;
private final Map<Connection, ConnectionHandler> connectionHandlers;

@Inject
public ChannelWhoManager(
@PluginDomain(ChannelWhoPlugin.class) final String domain,
final ConnectionHandlerFactory connectionHandlerFactory,
final ConnectionManager connectionManager,
final DMDircMBassador eventBus) {
this.domain = domain;
this.connectionHandlerFactory = connectionHandlerFactory;
this.connectionManager = connectionManager;
this.eventBus = eventBus;
Expand Down Expand Up @@ -79,6 +89,25 @@ private void removeConnectionHandler(final Connection connection) {
}
}

@VisibleForTesting
@Handler
void handleGroupChatPrefsRequestedEvent(final GroupChatPrefsRequestedEvent event) {
event.getCategory().addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, domain,
"sendWho", "Send Who Requests", "Should we send who requests to the channel?",
event.getConfig(), event.getIdentity()));
}

@VisibleForTesting
@Handler
void handlePrefsDialog(final ClientPrefsOpenedEvent event) {
final PreferencesCategory category = new PreferencesCategory("Channel Who", "Provides " +
"support for sendinw WHO requests to channels at regular intervals");
category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
new NumericalValidator(0, Integer.MAX_VALUE), domain, "whointerval",
"Who Interval", "The interval WHO requests will be sent to channels",
event.getModel().getConfigManager(), event.getModel().getIdentity()));
}

@VisibleForTesting
@Handler
void handleServerConnectingEvent(final ServerConnectingEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,26 @@ public void unload() {
executorService.shutdown();
connection.getWindowModel().getEventBus().unsubscribe(this);
if (future != null) {
future.cancel(true);
future.cancel(false);
}
}

@VisibleForTesting
void checkWho() {
connectionManager.getConnections().forEach(connection ->
connection.getGroupChatManager().getChannels().forEach(channel -> {
if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendWho")) {
channel.requestUsersInfo();
}
}));
if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendwho")) {
channel.requestUsersInfo();}}));
}

@VisibleForTesting
@ConfigBinding(key="whoInterval")
@ConfigBinding(key="whointerval")
void handleWhoInterval(final int value) {
if (future != null) {
future.cancel(true);
future.cancel(false);
}
future = executorService.schedule(this::checkWho, value, TimeUnit.MILLISECONDS);
future = executorService.scheduleAtFixedRate(this::checkWho, value, value,
TimeUnit.MILLISECONDS);
}

@VisibleForTesting
Expand Down

0 comments on commit 399748c

Please sign in to comment.