Browse Source

Merge pull request #466 from csmith/master

Add source checks for eventbus handlers.
pull/467/head
Greg Holmes 8 years ago
parent
commit
1cd834f642

+ 2
- 2
awaycolours/src/com/dmdirc/addons/awaycolours/AwayColoursManager.java View File

75
 
75
 
76
     @Handler
76
     @Handler
77
     public void handleAwayEvent(final ChannelUserAwayEvent event) {
77
     public void handleAwayEvent(final ChannelUserAwayEvent event) {
78
-            event.getUser().setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, colour);
79
-            event.getChannel().refreshClients();
78
+        event.getUser().setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, colour);
79
+        event.getChannel().refreshClients();
80
     }
80
     }
81
 
81
 
82
     @Handler
82
     @Handler

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

87
 
87
 
88
     @VisibleForTesting
88
     @VisibleForTesting
89
     void checkWho() {
89
     void checkWho() {
90
-        connectionManager.getConnections().forEach(
91
-                connection -> connection.getGroupChatManager().getChannels().forEach(channel -> {
92
-                    if (channel.getWindowModel().getConfigManager()
93
-                            .getOptionBool(domain, "sendwho")) {
94
-                        channel.requestUsersInfo();
95
-                    }
96
-                }));
90
+        connection.getGroupChatManager().getChannels().forEach(channel -> {
91
+            if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendwho")) {
92
+                channel.requestUsersInfo();
93
+            }
94
+        });
97
     }
95
     }
98
 
96
 
99
     @VisibleForTesting
97
     @VisibleForTesting
109
     @VisibleForTesting
107
     @VisibleForTesting
110
     @Handler
108
     @Handler
111
     void handleAwayEvent(final ChannelUserAwayEvent event) {
109
     void handleAwayEvent(final ChannelUserAwayEvent event) {
112
-        if (!event.getReason().isPresent()) {
110
+        if (event.getChannel().getConnection().equals(connection)
111
+                && !event.getReason().isPresent()) {
113
             event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
112
             event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
114
             final boolean notseen = !users.containsKey(event.getUser().getNickname());
113
             final boolean notseen = !users.containsKey(event.getUser().getNickname());
115
             users.put(event.getUser().getNickname(), event.getUser());
114
             users.put(event.getUser().getNickname(), event.getUser());
123
     @VisibleForTesting
122
     @VisibleForTesting
124
     @Handler
123
     @Handler
125
     void handleServerNumericEvent(final ServerNumericEvent event) {
124
     void handleServerNumericEvent(final ServerNumericEvent event) {
126
-        if (event.getNumeric() == 301) {
125
+        if (event.getConnection().equals(connection) && event.getNumeric() == 301) {
127
             final String nickname = event.getArgs()[3];
126
             final String nickname = event.getArgs()[3];
128
             final String reason = event.getArgs()[4];
127
             final String reason = event.getArgs()[4];
129
             users.removeAll(nickname).forEach(u -> u.getGroupChat().getEventBus()
128
             users.removeAll(nickname).forEach(u -> u.getGroupChat().getEventBus()

+ 15
- 5
contactlist/src/com/dmdirc/addons/contactlist/ContactListListener.java View File

70
 
70
 
71
     @Handler
71
     @Handler
72
     public void handleClientsUpdated(final NickListClientsChangedEvent event) {
72
     public void handleClientsUpdated(final NickListClientsChangedEvent event) {
73
-        event.getUsers().forEach(this::clientAdded);
73
+        if (event.getChannel().equals(groupChat)) {
74
+            event.getUsers().forEach(this::clientAdded);
75
+        }
74
     }
76
     }
75
 
77
 
76
     @Handler
78
     @Handler
77
     public void handleClientAdded(final NickListClientAddedEvent event) {
79
     public void handleClientAdded(final NickListClientAddedEvent event) {
78
-        clientAdded(event.getUser());
80
+        if (event.getChannel().equals(groupChat)) {
81
+            clientAdded(event.getUser());
82
+        }
79
     }
83
     }
80
 
84
 
81
     @Handler
85
     @Handler
82
     public void handleUserAway(final ChannelUserAwayEvent event) {
86
     public void handleUserAway(final ChannelUserAwayEvent event) {
83
-        clientAdded(event.getUser());
87
+        if (event.getChannel().equals(groupChat)) {
88
+            clientAdded(event.getUser());
89
+        }
84
     }
90
     }
85
 
91
 
86
     @Handler
92
     @Handler
87
     public void handleUserBack(final ChannelUserBackEvent event) {
93
     public void handleUserBack(final ChannelUserBackEvent event) {
88
-        clientAdded(event.getUser());
94
+        if (event.getChannel().equals(groupChat)) {
95
+            clientAdded(event.getUser());
96
+        }
89
     }
97
     }
90
 
98
 
91
     @Handler
99
     @Handler
92
     public void windowClosing(final FrameClosingEvent event) {
100
     public void windowClosing(final FrameClosingEvent event) {
93
-        removeListeners();
101
+        if (event.getSource().equals(groupChat.getWindowModel())) {
102
+            removeListeners();
103
+        }
94
     }
104
     }
95
 
105
 
96
     void clientAdded(final GroupChatUser client) {
106
     void clientAdded(final GroupChatUser client) {

+ 6
- 6
debug/src/com/dmdirc/addons/debug/RawWindow.java View File

29
 import com.dmdirc.parser.events.DataOutEvent;
29
 import com.dmdirc.parser.events.DataOutEvent;
30
 import com.dmdirc.parser.interfaces.Parser;
30
 import com.dmdirc.parser.interfaces.Parser;
31
 import com.dmdirc.ui.core.components.WindowComponent;
31
 import com.dmdirc.ui.core.components.WindowComponent;
32
-import com.dmdirc.ui.input.TabCompleterFactory;
33
 import com.dmdirc.ui.messages.BackBufferFactory;
32
 import com.dmdirc.ui.messages.BackBufferFactory;
34
 
33
 
35
 import java.util.Arrays;
34
 import java.util.Arrays;
44
 
43
 
45
     private final Connection connection;
44
     private final Connection connection;
46
 
45
 
47
-    public RawWindow(
48
-            final Connection connection,
49
-            final TabCompleterFactory tabCompleterFactory,
50
-            final BackBufferFactory backBufferFactory) {
46
+    public RawWindow(final Connection connection, final BackBufferFactory backBufferFactory) {
51
         super("raw", "Raw", "(Raw log)",
47
         super("raw", "Raw", "(Raw log)",
52
                 connection.getWindowModel().getConfigManager(),
48
                 connection.getWindowModel().getConfigManager(),
53
                 backBufferFactory,
49
                 backBufferFactory,
75
 
71
 
76
     @Handler
72
     @Handler
77
     public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
73
     public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
78
-        connection.getParser().map(Parser::getCallbackManager).ifPresent(c -> c.subscribe(this));
74
+        if (connectingEvent.getConnection().equals(connection)) {
75
+            connection.getParser()
76
+                    .map(Parser::getCallbackManager)
77
+                    .ifPresent(c -> c.subscribe(this));
78
+        }
79
     }
79
     }
80
 
80
 
81
     @Handler
81
     @Handler

+ 1
- 2
debug/src/com/dmdirc/addons/debug/RawWindowFactory.java View File

58
     }
58
     }
59
 
59
 
60
     public RawWindow getRawWindow(final Connection connection) {
60
     public RawWindow getRawWindow(final Connection connection) {
61
-        final RawWindow rawWindow = new RawWindow(connection,
62
-                tabCompleterFactory,  backBufferFactory);
61
+        final RawWindow rawWindow = new RawWindow(connection, backBufferFactory);
63
         rawWindow.setInputModel(
62
         rawWindow.setInputModel(
64
                 new DefaultInputModel(
63
                 new DefaultInputModel(
65
                         connection::sendLine,
64
                         connection::sendLine,

+ 3
- 1
debug/src/com/dmdirc/addons/debug/commands/EventBusViewer.java View File

124
 
124
 
125
         @Handler
125
         @Handler
126
         public void handleFrameClosing(final FrameClosingEvent event) {
126
         public void handleFrameClosing(final FrameClosingEvent event) {
127
-            eventBus.unsubscribe(this);
127
+            if (event.getSource().equals(target)) {
128
+                eventBus.unsubscribe(this);
129
+            }
128
         }
130
         }
129
 
131
 
130
         @Handler
132
         @Handler

+ 8
- 11
identd/src/com/dmdirc/addons/identd/IdentdManager.java View File

77
      * Called when the plugin is loaded.
77
      * Called when the plugin is loaded.
78
      */
78
      */
79
     public void onLoad() {
79
     public void onLoad() {
80
-        // Add action hooks
81
         eventBus.subscribe(this);
80
         eventBus.subscribe(this);
82
 
81
 
83
         if (config.getOptionBool(domain, "advanced.alwaysOn")) {
82
         if (config.getOptionBool(domain, "advanced.alwaysOn")) {
97
     @Handler
96
     @Handler
98
     public void handleServerConnecting(final ServerConnectingEvent event) {
97
     public void handleServerConnecting(final ServerConnectingEvent event) {
99
         synchronized (connections) {
98
         synchronized (connections) {
100
-                if (connections.isEmpty()) {
101
-                    server.startServer();
102
-                }
103
-                connections.add(event.getConnection());
99
+            if (connections.isEmpty()) {
100
+                server.startServer();
104
             }
101
             }
102
+            connections.add(event.getConnection());
103
+        }
105
     }
104
     }
106
 
105
 
107
     @Handler
106
     @Handler
116
 
115
 
117
     private void handleServerRemoved(final Connection connection) {
116
     private void handleServerRemoved(final Connection connection) {
118
         synchronized (connections) {
117
         synchronized (connections) {
119
-                connections.remove(connection);
118
+            connections.remove(connection);
120
 
119
 
121
-                if (connections.isEmpty() && !config.getOptionBool(domain, "advanced.alwaysOn")) {
122
-                    server.stopServer();
123
-                }
120
+            if (connections.isEmpty() && !config.getOptionBool(domain, "advanced.alwaysOn")) {
121
+                server.stopServer();
124
             }
122
             }
123
+        }
125
     }
124
     }
126
 
125
 
127
-
128
-
129
     @Handler
126
     @Handler
130
     public void showConfig(final ClientPrefsOpenedEvent event) {
127
     public void showConfig(final ClientPrefsOpenedEvent event) {
131
         final PreferencesDialogModel manager = event.getModel();
128
         final PreferencesDialogModel manager = event.getModel();

+ 9
- 3
jpq/src/com/dmdirc/addons/jpq/GroupChatHandler.java View File

77
     @VisibleForTesting
77
     @VisibleForTesting
78
     @Handler
78
     @Handler
79
     void handleJoin(final ChannelJoinEvent event) {
79
     void handleJoin(final ChannelJoinEvent event) {
80
-        hideEvent(event);
80
+        if (event.getChannel().equals(groupChat)) {
81
+            hideEvent(event);
82
+        }
81
     }
83
     }
82
 
84
 
83
     @SuppressWarnings("TypeMayBeWeakened")
85
     @SuppressWarnings("TypeMayBeWeakened")
84
     @VisibleForTesting
86
     @VisibleForTesting
85
     @Handler
87
     @Handler
86
     void handlePart(final ChannelPartEvent event) {
88
     void handlePart(final ChannelPartEvent event) {
87
-        hideEvent(event);
89
+        if (event.getChannel().equals(groupChat)) {
90
+            hideEvent(event);
91
+        }
88
     }
92
     }
89
 
93
 
90
     @SuppressWarnings("TypeMayBeWeakened")
94
     @SuppressWarnings("TypeMayBeWeakened")
91
     @VisibleForTesting
95
     @VisibleForTesting
92
     @Handler
96
     @Handler
93
     void handleQuit(final ChannelQuitEvent event) {
97
     void handleQuit(final ChannelQuitEvent event) {
94
-        hideEvent(event);
98
+        if (event.getChannel().equals(groupChat)) {
99
+            hideEvent(event);
100
+        }
95
     }
101
     }
96
 
102
 
97
     private void hideEvent(final DisplayableEvent event) {
103
     private void hideEvent(final DisplayableEvent event) {

+ 4
- 4
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugManager.java View File

134
 
134
 
135
     @Handler
135
     @Handler
136
     public void handleServerDisconnected(final ServerDisconnectedEvent event) {
136
     public void handleServerDisconnected(final ServerDisconnectedEvent event) {
137
-            final Parser parser = event.getConnection().getParser().get();
138
-            if (registeredParsers.containsKey(parser)) {
139
-                removeParser(parser, false);
140
-            }
137
+        final Parser parser = event.getConnection().getParser().get();
138
+        if (registeredParsers.containsKey(parser)) {
139
+            removeParser(parser, false);
140
+        }
141
     }
141
     }
142
 
142
 
143
     @Handler
143
     @Handler

+ 13
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/components/NickList.java View File

224
 
224
 
225
     @Handler(invocation = EdtHandlerInvocation.class)
225
     @Handler(invocation = EdtHandlerInvocation.class)
226
     public void handleClientsChanged(final NickListClientsChangedEvent event) {
226
     public void handleClientsChanged(final NickListClientsChangedEvent event) {
227
-        nicklistModel.replace(event.getUsers());
227
+        if (event.getChannel().getWindowModel().equals(frame.getContainer())) {
228
+            nicklistModel.replace(event.getUsers());
229
+        }
228
     }
230
     }
229
 
231
 
230
     @Handler(invocation = EdtHandlerInvocation.class)
232
     @Handler(invocation = EdtHandlerInvocation.class)
231
     public void handleNickListUpdated(final NickListUpdatedEvent event) {
233
     public void handleNickListUpdated(final NickListUpdatedEvent event) {
232
-        nicklistModel.sort();
233
-        repaint();
234
+        if (event.getChannel().getWindowModel().equals(frame.getContainer())) {
235
+            nicklistModel.sort();
236
+            repaint();
237
+        }
234
     }
238
     }
235
 
239
 
236
     @Handler(invocation = EdtHandlerInvocation.class)
240
     @Handler(invocation = EdtHandlerInvocation.class)
237
     public void handleClientAdded(final NickListClientAddedEvent event) {
241
     public void handleClientAdded(final NickListClientAddedEvent event) {
238
-        nicklistModel.add(event.getUser());
242
+        if (event.getChannel().getWindowModel().equals(frame.getContainer())) {
243
+            nicklistModel.add(event.getUser());
244
+        }
239
     }
245
     }
240
 
246
 
241
     @Handler(invocation = EdtHandlerInvocation.class)
247
     @Handler(invocation = EdtHandlerInvocation.class)
242
     public void handleClientRemoved(final NickListClientRemovedEvent event) {
248
     public void handleClientRemoved(final NickListClientRemovedEvent event) {
243
-        nicklistModel.remove(event.getUser());
249
+        if (event.getChannel().getWindowModel().equals(frame.getContainer())) {
250
+            nicklistModel.remove(event.getUser());
251
+        }
244
     }
252
     }
245
 
253
 
246
 }
254
 }

+ 6
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/components/TopicBar.java View File

228
 
228
 
229
     @Handler(invocation = EdtHandlerInvocation.class)
229
     @Handler(invocation = EdtHandlerInvocation.class)
230
     public void handleTopicChanged(final ChannelTopicChangeEvent event) {
230
     public void handleTopicChanged(final ChannelTopicChangeEvent event) {
231
-        topicChanged(event.getChannel(), event.getTopic());
231
+        if (event.getChannel().equals(channel)) {
232
+            topicChanged(event.getChannel(), event.getTopic());
233
+        }
232
     }
234
     }
233
 
235
 
234
     @Handler(invocation = EdtHandlerInvocation.class)
236
     @Handler(invocation = EdtHandlerInvocation.class)
235
     public void handleTopicUnset(final ChannelTopicUnsetEvent event) {
237
     public void handleTopicUnset(final ChannelTopicUnsetEvent event) {
236
-        topicChanged(event.getChannel(), null);
238
+        if (event.getChannel().equals(channel)) {
239
+            topicChanged(event.getChannel(), null);
240
+        }
237
     }
241
     }
238
 
242
 
239
     private void topicChanged(final GroupChat channel, final Topic topic) {
243
     private void topicChanged(final GroupChat channel, final Topic topic) {

+ 6
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/ChannelFrame.java View File

224
     @Override
224
     @Override
225
     @Handler(invocation = EdtHandlerInvocation.class)
225
     @Handler(invocation = EdtHandlerInvocation.class)
226
     public void windowClosing(final FrameClosingEvent event) {
226
     public void windowClosing(final FrameClosingEvent event) {
227
-        saveSplitPanePosition();
228
-        topicBar.close();
229
-        dialogProvider.dispose(groupChat);
230
-        super.windowClosing(event);
227
+        if (event.getSource().equals(getContainer())) {
228
+            saveSplitPanePosition();
229
+            topicBar.close();
230
+            dialogProvider.dispose(groupChat);
231
+            super.windowClosing(event);
232
+        }
231
     }
233
     }
232
 
234
 
233
     @Override
235
     @Override

+ 16
- 10
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/ServerFrame.java View File

142
 
142
 
143
     @Handler(invocation = EdtHandlerInvocation.class)
143
     @Handler(invocation = EdtHandlerInvocation.class)
144
     public void handleCertProblem(final ServerCertificateProblemEncounteredEvent event) {
144
     public void handleCertProblem(final ServerCertificateProblemEncounteredEvent event) {
145
-        if (sslDialog != null) {
146
-            sslDialog.dispose();
147
-        }
145
+        if (event.getConnection().equals(connection)) {
146
+            if (sslDialog != null) {
147
+                sslDialog.dispose();
148
+            }
148
 
149
 
149
-        sslDialog = sslDialogFactory.create(event);
150
-        sslDialog.display();
150
+            sslDialog = sslDialogFactory.create(event);
151
+            sslDialog.display();
152
+        }
151
     }
153
     }
152
 
154
 
153
     @Handler(invocation = EdtHandlerInvocation.class)
155
     @Handler(invocation = EdtHandlerInvocation.class)
154
     public void handleCertProblemResolved(final ServerCertificateProblemResolvedEvent event) {
156
     public void handleCertProblemResolved(final ServerCertificateProblemResolvedEvent event) {
155
-        if (sslDialog != null) {
156
-            sslDialog.dispose();
157
+        if (event.getConnection().equals(connection)) {
158
+            if (sslDialog != null) {
159
+                sslDialog.dispose();
160
+            }
157
         }
161
         }
158
     }
162
     }
159
 
163
 
160
     @Override
164
     @Override
161
     @Handler(invocation = EdtHandlerInvocation.class)
165
     @Handler(invocation = EdtHandlerInvocation.class)
162
     public void windowClosing(final FrameClosingEvent event) {
166
     public void windowClosing(final FrameClosingEvent event) {
163
-        connection.getWindowModel().getEventBus().unsubscribe(this);
164
-        dialogProvider.dispose(connection);
165
-        super.windowClosing(event);
167
+        if (event.getSource().equals(frameParent)) {
168
+            connection.getWindowModel().getEventBus().unsubscribe(this);
169
+            dialogProvider.dispose(connection);
170
+            super.windowClosing(event);
171
+        }
166
     }
172
     }
167
 
173
 
168
     @Override
174
     @Override

+ 0
- 2
windowflashing/src/com/dmdirc/addons/windowflashing/WindowFlashingManager.java View File

176
         }
176
         }
177
     }
177
     }
178
 
178
 
179
-
180
-
181
     @Handler
179
     @Handler
182
     public void showConfig(final ClientPrefsOpenedEvent event) {
180
     public void showConfig(final ClientPrefsOpenedEvent event) {
183
         final PreferencesDialogModel manager = event.getModel();
181
         final PreferencesDialogModel manager = event.getModel();

Loading…
Cancel
Save