Pārlūkot izejas kodu

Explicitly pass event bus in to a few places.

pull/485/head
Chris Smith 7 gadus atpakaļ
vecāks
revīzija
b3f6f2ab3c

+ 7
- 7
channelwho/src/main/java/com/dmdirc/addons/channelwho/ConnectionHandler.java Parādīt failu

22
 
22
 
23
 package com.dmdirc.addons.channelwho;
23
 package com.dmdirc.addons.channelwho;
24
 
24
 
25
+import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.config.ConfigBinder;
26
 import com.dmdirc.config.ConfigBinder;
26
 import com.dmdirc.config.ConfigBinding;
27
 import com.dmdirc.config.ConfigBinding;
27
 import com.dmdirc.events.ChannelUserAwayEvent;
28
 import com.dmdirc.events.ChannelUserAwayEvent;
28
 import com.dmdirc.events.DisplayProperty;
29
 import com.dmdirc.events.DisplayProperty;
29
 import com.dmdirc.events.ServerNumericEvent;
30
 import com.dmdirc.events.ServerNumericEvent;
30
 import com.dmdirc.interfaces.Connection;
31
 import com.dmdirc.interfaces.Connection;
31
-import com.dmdirc.interfaces.ConnectionManager;
32
 import com.dmdirc.interfaces.GroupChat;
32
 import com.dmdirc.interfaces.GroupChat;
33
 import com.dmdirc.interfaces.GroupChatUser;
33
 import com.dmdirc.interfaces.GroupChatUser;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
51
 public class ConnectionHandler {
51
 public class ConnectionHandler {
52
 
52
 
53
     private final Multimap<String, GroupChatUser> users;
53
     private final Multimap<String, GroupChatUser> users;
54
+    private final DMDircMBassador eventBus;
54
     private final Connection connection;
55
     private final Connection connection;
55
     private final String domain;
56
     private final String domain;
56
     private final ScheduledExecutorService executorService;
57
     private final ScheduledExecutorService executorService;
57
-    private final ConnectionManager connectionManager;
58
     private final ConfigBinder configBinder;
58
     private final ConfigBinder configBinder;
59
     private ScheduledFuture<?> future;
59
     private ScheduledFuture<?> future;
60
 
60
 
61
     public ConnectionHandler(
61
     public ConnectionHandler(
62
             final AggregateConfigProvider config,
62
             final AggregateConfigProvider config,
63
             final ScheduledExecutorService executorService,
63
             final ScheduledExecutorService executorService,
64
-            final ConnectionManager connectionManager, final String domain,
64
+            final DMDircMBassador eventBus,
65
+            final String domain,
65
             final Connection connection) {
66
             final Connection connection) {
67
+        this.eventBus = eventBus;
66
         this.connection = connection;
68
         this.connection = connection;
67
         this.domain = domain;
69
         this.domain = domain;
68
         this.executorService = executorService;
70
         this.executorService = executorService;
69
-        this.connectionManager = connectionManager;
70
         configBinder = config.getBinder().withDefaultDomain(domain);
71
         configBinder = config.getBinder().withDefaultDomain(domain);
71
         users = HashMultimap.create();
72
         users = HashMultimap.create();
72
     }
73
     }
125
         if (event.getConnection().equals(connection) && event.getNumeric() == 301) {
126
         if (event.getConnection().equals(connection) && event.getNumeric() == 301) {
126
             final String nickname = event.getArgs()[3];
127
             final String nickname = event.getArgs()[3];
127
             final String reason = event.getArgs()[4];
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 Parādīt failu

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

+ 2
- 3
channelwho/src/test/java/com/dmdirc/addons/channelwho/ConnectionHandlerTest.java Parādīt failu

97
         when(groupChatUser.getNickname()).thenReturn("nickname");
97
         when(groupChatUser.getNickname()).thenReturn("nickname");
98
         when(channelUserAwayEvent.getUser()).thenReturn(groupChatUser);
98
         when(channelUserAwayEvent.getUser()).thenReturn(groupChatUser);
99
         when(channelUserAwayEvent.getChannel()).thenReturn(groupChat);
99
         when(channelUserAwayEvent.getChannel()).thenReturn(groupChat);
100
-        when(groupChat.getEventBus()).thenReturn(eventBus);
101
         when(groupChatUser.getUser()).thenReturn(user);
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
         instance.handleWhoInterval(5);
103
         instance.handleWhoInterval(5);
105
 
104
 
106
         when(serverNumericEvent.getConnection()).thenReturn(connection);
105
         when(serverNumericEvent.getConnection()).thenReturn(connection);

+ 9
- 2
contactlist/src/main/java/com/dmdirc/addons/contactlist/ContactListCommand.java Parādīt failu

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

+ 2
- 2
contactlist/src/main/java/com/dmdirc/addons/contactlist/ContactListListener.java Parādīt failu

49
      *
49
      *
50
      * @param groupChat The group chat to show a contact list for
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
         this.groupChat = groupChat;
53
         this.groupChat = groupChat;
54
-        this.eventBus = groupChat.getEventBus();
54
+        this.eventBus = eventBus;
55
     }
55
     }
56
 
56
 
57
     /**
57
     /**

Notiek ielāde…
Atcelt
Saglabāt