Parcourir la source

Merge pull request #485 from csmith/eventbus

Explicitly pass event bus in to a few places.
pull/486/head
Greg Holmes il y a 7 ans
Parent
révision
b6e4e374f8

+ 7
- 7
channelwho/src/main/java/com/dmdirc/addons/channelwho/ConnectionHandler.java Voir le fichier

@@ -22,13 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.channelwho;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.config.ConfigBinder;
26 27
 import com.dmdirc.config.ConfigBinding;
27 28
 import com.dmdirc.events.ChannelUserAwayEvent;
28 29
 import com.dmdirc.events.DisplayProperty;
29 30
 import com.dmdirc.events.ServerNumericEvent;
30 31
 import com.dmdirc.interfaces.Connection;
31
-import com.dmdirc.interfaces.ConnectionManager;
32 32
 import com.dmdirc.interfaces.GroupChat;
33 33
 import com.dmdirc.interfaces.GroupChatUser;
34 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -51,22 +51,23 @@ import net.engio.mbassy.listener.Handler;
51 51
 public class ConnectionHandler {
52 52
 
53 53
     private final Multimap<String, GroupChatUser> users;
54
+    private final DMDircMBassador eventBus;
54 55
     private final Connection connection;
55 56
     private final String domain;
56 57
     private final ScheduledExecutorService executorService;
57
-    private final ConnectionManager connectionManager;
58 58
     private final ConfigBinder configBinder;
59 59
     private ScheduledFuture<?> future;
60 60
 
61 61
     public ConnectionHandler(
62 62
             final AggregateConfigProvider config,
63 63
             final ScheduledExecutorService executorService,
64
-            final ConnectionManager connectionManager, final String domain,
64
+            final DMDircMBassador eventBus,
65
+            final String domain,
65 66
             final Connection connection) {
67
+        this.eventBus = eventBus;
66 68
         this.connection = connection;
67 69
         this.domain = domain;
68 70
         this.executorService = executorService;
69
-        this.connectionManager = connectionManager;
70 71
         configBinder = config.getBinder().withDefaultDomain(domain);
71 72
         users = HashMultimap.create();
72 73
     }
@@ -125,9 +126,8 @@ public class ConnectionHandler {
125 126
         if (event.getConnection().equals(connection) && event.getNumeric() == 301) {
126 127
             final String nickname = event.getArgs()[3];
127 128
             final String reason = event.getArgs()[4];
128
-            users.removeAll(nickname).forEach(u -> u.getGroupChat().getEventBus()
129
-                .publishAsync(new ChannelUserAwayEvent(u.getGroupChat(), u,
130
-                        Optional.ofNullable(reason))));
129
+            users.removeAll(nickname).forEach(u -> eventBus.publishAsync(
130
+                new ChannelUserAwayEvent(u.getGroupChat(), u, Optional.ofNullable(reason))));
131 131
         }
132 132
     }
133 133
 }

+ 5
- 5
channelwho/src/main/java/com/dmdirc/addons/channelwho/ConnectionHandlerFactory.java Voir le fichier

@@ -23,8 +23,8 @@
23 23
 package com.dmdirc.addons.channelwho;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.DMDircMBassador;
26 27
 import com.dmdirc.interfaces.Connection;
27
-import com.dmdirc.interfaces.ConnectionManager;
28 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 29
 import com.dmdirc.plugins.PluginDomain;
30 30
 
@@ -40,23 +40,23 @@ public class ConnectionHandlerFactory {
40 40
 
41 41
     private final AggregateConfigProvider config;
42 42
     private final ScheduledExecutorService executorService;
43
-    private final ConnectionManager connectionManager;
43
+    private final DMDircMBassador eventBus;
44 44
     private final String domain;
45 45
 
46 46
     @Inject
47 47
     public ConnectionHandlerFactory(@GlobalConfig final AggregateConfigProvider config,
48 48
             @Named("channelwho") final ScheduledExecutorService executorService,
49
-            final ConnectionManager connectionManager,
49
+            final DMDircMBassador eventBus,
50 50
             @PluginDomain(ChannelWhoPlugin.class) final String domain) {
51 51
         this.config = config;
52 52
         this.executorService = executorService;
53
-        this.connectionManager = connectionManager;
53
+        this.eventBus = eventBus;
54 54
         this.domain = domain;
55 55
     }
56 56
 
57 57
     public ConnectionHandler get(final Connection connection) {
58 58
         final ConnectionHandler handler = new ConnectionHandler(config, executorService,
59
-                connectionManager, domain, connection);
59
+            eventBus, domain, connection);
60 60
         handler.load();
61 61
         return handler;
62 62
     }

+ 2
- 3
channelwho/src/test/java/com/dmdirc/addons/channelwho/ConnectionHandlerTest.java Voir le fichier

@@ -97,10 +97,9 @@ public class ConnectionHandlerTest {
97 97
         when(groupChatUser.getNickname()).thenReturn("nickname");
98 98
         when(channelUserAwayEvent.getUser()).thenReturn(groupChatUser);
99 99
         when(channelUserAwayEvent.getChannel()).thenReturn(groupChat);
100
-        when(groupChat.getEventBus()).thenReturn(eventBus);
101 100
         when(groupChatUser.getUser()).thenReturn(user);
102
-        instance = new ConnectionHandler(config, scheduledExecutorService, connectionManager,
103
-                "domain", connection);
101
+        instance = new ConnectionHandler(config, scheduledExecutorService, eventBus,
102
+            "domain", connection);
104 103
         instance.handleWhoInterval(5);
105 104
 
106 105
         when(serverNumericEvent.getConnection()).thenReturn(connection);

+ 9
- 2
contactlist/src/main/java/com/dmdirc/addons/contactlist/ContactListCommand.java Voir le fichier

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.contactlist;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.commandparser.BaseCommandInfo;
26 27
 import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.CommandInfo;
@@ -47,14 +48,19 @@ public class ContactListCommand extends Command implements IntelligentCommand {
47 48
             "contactlist - show a contact list for the current channel",
48 49
             CommandType.TYPE_CHANNEL);
49 50
 
51
+    private final DMDircMBassador eventBus;
52
+
50 53
     /**
51 54
      * Creates a new instance of this command.
52 55
      *
53 56
      * @param controller The controller to use for command information.
54 57
      */
55 58
     @Inject
56
-    public ContactListCommand(final CommandController controller) {
59
+    public ContactListCommand(
60
+            final CommandController controller,
61
+            final DMDircMBassador eventBus) {
57 62
         super(controller);
63
+        this.eventBus = eventBus;
58 64
     }
59 65
 
60 66
     @Override
@@ -62,7 +68,8 @@ public class ContactListCommand extends Command implements IntelligentCommand {
62 68
             final CommandArguments args, final CommandContext context) {
63 69
         final ChannelCommandContext chanContext = (ChannelCommandContext) context;
64 70
 
65
-        final ContactListListener listener = new ContactListListener(chanContext.getGroupChat());
71
+        final ContactListListener listener =
72
+                new ContactListListener(chanContext.getGroupChat(), eventBus);
66 73
         listener.addListeners();
67 74
         chanContext.getGroupChat().getUsers().forEach(listener::clientAdded);
68 75
     }

+ 2
- 2
contactlist/src/main/java/com/dmdirc/addons/contactlist/ContactListListener.java Voir le fichier

@@ -49,9 +49,9 @@ public class ContactListListener {
49 49
      *
50 50
      * @param groupChat The group chat to show a contact list for
51 51
      */
52
-    public ContactListListener(final GroupChat groupChat) {
52
+    public ContactListListener(final GroupChat groupChat, final DMDircMBassador eventBus) {
53 53
         this.groupChat = groupChat;
54
-        this.eventBus = groupChat.getEventBus();
54
+        this.eventBus = eventBus;
55 55
     }
56 56
 
57 57
     /**

Chargement…
Annuler
Enregistrer