|
@@ -22,12 +22,22 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.CoreActionType;
|
|
25
|
+import com.dmdirc.events.ChannelActionEvent;
|
|
26
|
+import com.dmdirc.events.ChannelCtcpEvent;
|
|
27
|
+import com.dmdirc.events.ChannelGotnamesEvent;
|
|
28
|
+import com.dmdirc.events.ChannelGottopicEvent;
|
|
29
|
+import com.dmdirc.events.ChannelJoinEvent;
|
|
30
|
+import com.dmdirc.events.ChannelKickEvent;
|
27
|
31
|
import com.dmdirc.events.ChannelListmodesretrievedEvent;
|
|
32
|
+import com.dmdirc.events.ChannelMessageEvent;
|
|
33
|
+import com.dmdirc.events.ChannelModeNoticeEvent;
|
28
|
34
|
import com.dmdirc.events.ChannelModechangeEvent;
|
29
|
35
|
import com.dmdirc.events.ChannelModesdiscoveredEvent;
|
30
|
36
|
import com.dmdirc.events.ChannelNickchangeEvent;
|
|
37
|
+import com.dmdirc.events.ChannelNoticeEvent;
|
|
38
|
+import com.dmdirc.events.ChannelNotopicEvent;
|
|
39
|
+import com.dmdirc.events.ChannelPartEvent;
|
|
40
|
+import com.dmdirc.events.ChannelQuitEvent;
|
31
|
41
|
import com.dmdirc.events.ChannelTopicChangeEvent;
|
32
|
42
|
import com.dmdirc.events.ChannelUserAwayEvent;
|
33
|
43
|
import com.dmdirc.events.ChannelUserBackEvent;
|
|
@@ -35,7 +45,6 @@ import com.dmdirc.events.ChannelUsermodechangeEvent;
|
35
|
45
|
import com.dmdirc.events.DisplayableEvent;
|
36
|
46
|
import com.dmdirc.events.EventUtils;
|
37
|
47
|
import com.dmdirc.interfaces.Connection;
|
38
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
39
|
48
|
import com.dmdirc.parser.common.AwayState;
|
40
|
49
|
import com.dmdirc.parser.common.CallbackManager;
|
41
|
50
|
import com.dmdirc.parser.interfaces.ChannelClientInfo;
|
|
@@ -65,10 +74,7 @@ import com.google.common.base.Optional;
|
65
|
74
|
import com.google.common.base.Strings;
|
66
|
75
|
import com.google.common.eventbus.EventBus;
|
67
|
76
|
|
68
|
|
-import java.util.ArrayList;
|
69
|
|
-import java.util.Arrays;
|
70
|
77
|
import java.util.Date;
|
71
|
|
-import java.util.List;
|
72
|
78
|
|
73
|
79
|
/**
|
74
|
80
|
* Handles events for channel objects.
|
|
@@ -125,10 +131,10 @@ public class ChannelEventHandler extends EventHandler implements
|
125
|
131
|
final String message, final String host) {
|
126
|
132
|
checkParser(parser);
|
127
|
133
|
|
128
|
|
- final StringBuffer messageType = new StringBuffer(
|
|
134
|
+ final DisplayableEvent event = new ChannelMessageEvent(owner, client, message);
|
|
135
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
129
|
136
|
isMyself(client) ? "channelSelfExternalMessage" : "channelMessage");
|
130
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_MESSAGE, client, message);
|
131
|
|
- owner.doNotification(date, messageType.toString(), client, message);
|
|
137
|
+ owner.doNotification(date, format, client, message);
|
132
|
138
|
}
|
133
|
139
|
|
134
|
140
|
@Override
|
|
@@ -136,7 +142,7 @@ public class ChannelEventHandler extends EventHandler implements
|
136
|
142
|
checkParser(parser);
|
137
|
143
|
|
138
|
144
|
owner.setClients(channel.getChannelClients());
|
139
|
|
- ActionManager.getActionManager().triggerEvent(CoreActionType.CHANNEL_GOTNAMES, null, owner);
|
|
145
|
+ eventBus.post(new ChannelGotnamesEvent(owner));
|
140
|
146
|
}
|
141
|
147
|
|
142
|
148
|
@Override
|
|
@@ -146,27 +152,27 @@ public class ChannelEventHandler extends EventHandler implements
|
146
|
152
|
|
147
|
153
|
if (isJoinTopic) {
|
148
|
154
|
if (Strings.isNullOrEmpty(channel.getTopic())) {
|
149
|
|
- final StringBuffer messageType = new StringBuffer("channelNoTopic");
|
150
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_NOTOPIC);
|
151
|
|
- owner.doNotification(date, messageType.toString());
|
|
155
|
+ final DisplayableEvent event = new ChannelNotopicEvent(owner);
|
|
156
|
+ final String format = EventUtils.postDisplayable(eventBus, event, "channelNoTopic");
|
|
157
|
+ owner.doNotification(date, format);
|
152
|
158
|
} else {
|
153
|
159
|
final Topic newTopic = new Topic(channel.getTopic(), channel.getTopicSetter(),
|
154
|
160
|
channel.getTopicTime());
|
155
|
|
- final StringBuffer messageType = new StringBuffer("channelTopicDiscovered");
|
156
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_GOTTOPIC, newTopic);
|
157
|
|
- owner.doNotification(date, messageType.toString(), newTopic);
|
|
161
|
+ final DisplayableEvent event = new ChannelGottopicEvent(owner, newTopic);
|
|
162
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
163
|
+ "channelTopicDiscovered");
|
|
164
|
+ owner.doNotification(date, format, newTopic);
|
158
|
165
|
}
|
159
|
166
|
} else {
|
160
|
|
- final StringBuffer messageType = new StringBuffer(
|
161
|
|
- Strings.isNullOrEmpty(channel.getTopic())
|
162
|
|
- ? "channelTopicRemoved" : "channelTopicChanged");
|
163
|
167
|
final DisplayableEvent event = new ChannelTopicChangeEvent(owner,
|
164
|
168
|
channel.getChannelClient(channel.getTopicSetter(), true),
|
165
|
169
|
channel.getTopic());
|
166
|
|
- event.setDisplayFormat(messageType.toString());
|
|
170
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
171
|
+ Strings.isNullOrEmpty(channel.getTopic())
|
|
172
|
+ ? "channelTopicRemoved" : "channelTopicChanged");
|
167
|
173
|
eventBus.post(event);
|
168
|
|
- owner.doNotification(date, messageType.toString(),
|
169
|
|
- channel.getChannelClient(channel.getTopicSetter(), true), channel.getTopic());
|
|
174
|
+ owner.doNotification(date, format, channel.getChannelClient(channel.getTopicSetter(),
|
|
175
|
+ true), channel.getTopic());
|
170
|
176
|
}
|
171
|
177
|
|
172
|
178
|
final Optional<Topic> currentTopic = owner.getCurrentTopic();
|
|
@@ -189,9 +195,9 @@ public class ChannelEventHandler extends EventHandler implements
|
189
|
195
|
final ChannelClientInfo client) {
|
190
|
196
|
checkParser(parser);
|
191
|
197
|
|
192
|
|
- final StringBuffer messageType = new StringBuffer("channelJoin");
|
193
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_JOIN, client);
|
194
|
|
- owner.doNotification(date, messageType.toString(), client);
|
|
198
|
+ final DisplayableEvent event = new ChannelJoinEvent(owner, client);
|
|
199
|
+ final String format = EventUtils.postDisplayable(eventBus, event, "channelJoin");
|
|
200
|
+ owner.doNotification(date, format, client);
|
195
|
201
|
owner.addClient(client);
|
196
|
202
|
}
|
197
|
203
|
|
|
@@ -200,13 +206,12 @@ public class ChannelEventHandler extends EventHandler implements
|
200
|
206
|
final ChannelClientInfo client, final String reason) {
|
201
|
207
|
checkParser(parser);
|
202
|
208
|
|
203
|
|
- final StringBuffer messageType = new StringBuffer(
|
|
209
|
+ final DisplayableEvent event = new ChannelPartEvent(owner, client, reason);
|
|
210
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
204
|
211
|
"channel"
|
205
|
212
|
+ (isMyself(client) ? "Self" : "") + "Part"
|
206
|
213
|
+ (reason.isEmpty() ? "" : "Reason"));
|
207
|
|
-
|
208
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_PART, client, reason);
|
209
|
|
- owner.doNotification(date, messageType.toString(), client, reason);
|
|
214
|
+ owner.doNotification(date, format, client, reason);
|
210
|
215
|
owner.removeClient(client);
|
211
|
216
|
}
|
212
|
217
|
|
|
@@ -216,11 +221,10 @@ public class ChannelEventHandler extends EventHandler implements
|
216
|
221
|
final String reason, final String host) {
|
217
|
222
|
checkParser(parser);
|
218
|
223
|
|
219
|
|
- final StringBuffer messageType = new StringBuffer(
|
|
224
|
+ final DisplayableEvent event = new ChannelKickEvent(owner, client, kickedClient, reason);
|
|
225
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
220
|
226
|
"channelKick" + (reason.isEmpty() ? "" : "Reason"));
|
221
|
|
- triggerAction(messageType,
|
222
|
|
- CoreActionType.CHANNEL_KICK, client, kickedClient, reason);
|
223
|
|
- owner.doNotification(date, messageType.toString(), client, kickedClient, reason);
|
|
227
|
+ owner.doNotification(date, format, client, kickedClient, reason);
|
224
|
228
|
owner.removeClient(kickedClient);
|
225
|
229
|
}
|
226
|
230
|
|
|
@@ -229,10 +233,10 @@ public class ChannelEventHandler extends EventHandler implements
|
229
|
233
|
final ChannelClientInfo client, final String reason) {
|
230
|
234
|
checkParser(parser);
|
231
|
235
|
|
232
|
|
- final StringBuffer messageType = new StringBuffer(
|
|
236
|
+ final DisplayableEvent event = new ChannelQuitEvent(owner, client, reason);
|
|
237
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
233
|
238
|
"channelQuit" + (reason.isEmpty() ? "" : "Reason"));
|
234
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_QUIT, client, reason);
|
235
|
|
- owner.doNotification(date, messageType.toString(), client, reason);
|
|
239
|
+ owner.doNotification(date, format, client, reason);
|
236
|
240
|
owner.removeClient(client);
|
237
|
241
|
}
|
238
|
242
|
|
|
@@ -242,10 +246,10 @@ public class ChannelEventHandler extends EventHandler implements
|
242
|
246
|
final String host) {
|
243
|
247
|
checkParser(parser);
|
244
|
248
|
|
245
|
|
- final StringBuffer messageType = new StringBuffer(
|
|
249
|
+ final DisplayableEvent event = new ChannelActionEvent(owner, client, message);
|
|
250
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
246
|
251
|
isMyself(client) ? "channelSelfExternalAction" : "channelAction");
|
247
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_ACTION, client, message);
|
248
|
|
- owner.doNotification(date, messageType.toString(), client, message);
|
|
252
|
+ owner.doNotification(date, format, client, message);
|
249
|
253
|
}
|
250
|
254
|
|
251
|
255
|
@Override
|
|
@@ -253,13 +257,10 @@ public class ChannelEventHandler extends EventHandler implements
|
253
|
257
|
final ChannelInfo channel, final ChannelClientInfo client, final String oldNick) {
|
254
|
258
|
checkParser(parser);
|
255
|
259
|
|
256
|
|
- final StringBuffer messageType = new StringBuffer(
|
257
|
|
- isMyself(client) ? "channelSelfNickChange" : "channelNickChange");
|
258
|
|
-
|
259
|
260
|
final DisplayableEvent event = new ChannelNickchangeEvent(owner, client, oldNick);
|
260
|
|
- event.setDisplayFormat(messageType.toString());
|
261
|
|
- eventBus.post(event);
|
262
|
|
- owner.doNotification(date, messageType.toString(), client, oldNick);
|
|
261
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
262
|
+ isMyself(client) ? "channelSelfNickChange" : "channelNickChange");
|
|
263
|
+ owner.doNotification(date, format, client, oldNick);
|
263
|
264
|
owner.renameClient(oldNick, client.getClient().getNickname());
|
264
|
265
|
}
|
265
|
266
|
|
|
@@ -272,21 +273,16 @@ public class ChannelEventHandler extends EventHandler implements
|
272
|
273
|
if (!owner.getConfigManager().getOptionBool("channel", "splitusermodes")
|
273
|
274
|
|| !owner.getConfigManager().getOptionBool("channel", "hideduplicatemodes")) {
|
274
|
275
|
if (host.isEmpty()) {
|
275
|
|
- final StringBuffer messageType = new StringBuffer(
|
276
|
|
- modes.length() <= 1 ? "channelNoModes" : "channelModeDiscovered");
|
277
|
276
|
final DisplayableEvent event = new ChannelModesdiscoveredEvent(owner,
|
278
|
277
|
modes.length() <= 1 ? "" : modes);
|
279
|
|
- event.setDisplayFormat(host);
|
280
|
|
- eventBus.post(event);
|
281
|
|
- owner.doNotification(date, messageType.toString(),
|
282
|
|
- modes.length() <= 1 ? "" : modes);
|
|
278
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
279
|
+ modes.length() <= 1 ? "channelNoModes" : "channelModeDiscovered");
|
|
280
|
+ owner.doNotification(date, format, modes.length() <= 1 ? "" : modes);
|
283
|
281
|
} else {
|
284
|
|
- final StringBuffer messageType = new StringBuffer(
|
285
|
|
- isMyself(client) ? "channelSelfModeChanged" : "channelModeChanged");
|
286
|
282
|
final DisplayableEvent event = new ChannelModechangeEvent(owner, client, modes);
|
287
|
|
- event.setDisplayFormat(messageType.toString());
|
288
|
|
- eventBus.post(event);
|
289
|
|
- owner.doNotification(date, messageType.toString(), client, modes);
|
|
283
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
284
|
+ isMyself(client) ? "channelSelfModeChanged" : "channelModeChanged");
|
|
285
|
+ owner.doNotification(date, format, client, modes);
|
290
|
286
|
}
|
291
|
287
|
}
|
292
|
288
|
|
|
@@ -306,12 +302,10 @@ public class ChannelEventHandler extends EventHandler implements
|
306
|
302
|
format = "channelSplitUserMode_default";
|
307
|
303
|
}
|
308
|
304
|
|
309
|
|
- final StringBuffer messageType = new StringBuffer(format);
|
310
|
305
|
final DisplayableEvent event = new ChannelUsermodechangeEvent(owner, client,
|
311
|
306
|
targetClient, mode);
|
312
|
|
- event.setDisplayFormat(format);
|
313
|
|
- eventBus.post(event);
|
314
|
|
- owner.doNotification(date, messageType.toString(), client, targetClient, mode);
|
|
307
|
+ final String result = EventUtils.postDisplayable(eventBus, event, format);
|
|
308
|
+ owner.doNotification(date, result, client, targetClient, mode);
|
315
|
309
|
}
|
316
|
310
|
}
|
317
|
311
|
|
|
@@ -321,12 +315,12 @@ public class ChannelEventHandler extends EventHandler implements
|
321
|
315
|
final String type, final String message, final String host) {
|
322
|
316
|
checkParser(parser);
|
323
|
317
|
|
324
|
|
- final StringBuffer messageType = new StringBuffer("channelCTCP");
|
325
|
|
- if (triggerAction(messageType, CoreActionType.CHANNEL_CTCP, client, type, message)) {
|
326
|
|
- owner.getConnection().sendCTCPReply(client.getClient().getNickname(),
|
327
|
|
- type, message);
|
|
318
|
+ final ChannelCtcpEvent event = new ChannelCtcpEvent(owner, client, type, message);
|
|
319
|
+ final String format = EventUtils.postDisplayable(eventBus, event, "channelCTCP");
|
|
320
|
+ if (!event.isHandled()) {
|
|
321
|
+ owner.getConnection().sendCTCPReply(client.getClient().getNickname(), type, message);
|
328
|
322
|
}
|
329
|
|
- owner.doNotification(date, messageType.toString(), client, type, message);
|
|
323
|
+ owner.doNotification(date, format, client, type, message);
|
330
|
324
|
}
|
331
|
325
|
|
332
|
326
|
@Override
|
|
@@ -357,9 +351,9 @@ public class ChannelEventHandler extends EventHandler implements
|
357
|
351
|
final String message, final String host) {
|
358
|
352
|
checkParser(parser);
|
359
|
353
|
|
360
|
|
- final StringBuffer messageType = new StringBuffer("channelNotice");
|
361
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_NOTICE, client, message);
|
362
|
|
- owner.doNotification(date, messageType.toString(), client, message);
|
|
354
|
+ final DisplayableEvent event = new ChannelNoticeEvent(owner, client, message);
|
|
355
|
+ final String format = EventUtils.postDisplayable(eventBus, event, "channelNotice");
|
|
356
|
+ owner.doNotification(date, format, client, message);
|
363
|
357
|
}
|
364
|
358
|
|
365
|
359
|
@Override
|
|
@@ -371,21 +365,16 @@ public class ChannelEventHandler extends EventHandler implements
|
371
|
365
|
if (owner.getConfigManager().getOptionBool("channel", "splitusermodes")
|
372
|
366
|
&& owner.getConfigManager().getOptionBool("channel", "hideduplicatemodes")) {
|
373
|
367
|
if (host.isEmpty()) {
|
374
|
|
- final StringBuffer messageType = new StringBuffer(
|
375
|
|
- modes.length() <= 1 ? "channelNoModes" : "channelModeDiscovered");
|
376
|
368
|
final DisplayableEvent event = new ChannelModesdiscoveredEvent(owner,
|
377
|
369
|
modes.length() <= 1 ? "" : modes);
|
378
|
|
- event.setDisplayFormat(host);
|
379
|
|
- eventBus.post(event);
|
380
|
|
- owner.doNotification(date, messageType.toString(),
|
381
|
|
- modes.length() <= 1 ? "" : modes);
|
|
370
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
371
|
+ modes.length() <= 1 ? "channelNoModes" : "channelModeDiscovered");
|
|
372
|
+ owner.doNotification(date, format, modes.length() <= 1 ? "" : modes);
|
382
|
373
|
} else {
|
383
|
|
- final StringBuffer messageType = new StringBuffer(
|
384
|
|
- isMyself(client) ? "channelSelfModeChanged" : "channelModeChanged");
|
385
|
374
|
final DisplayableEvent event = new ChannelModechangeEvent(owner, client, modes);
|
386
|
|
- event.setDisplayFormat(messageType.toString());
|
387
|
|
- eventBus.post(event);
|
388
|
|
- owner.doNotification(date, messageType.toString(), client, modes);
|
|
375
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
376
|
+ isMyself(client) ? "channelSelfModeChanged" : "channelModeChanged");
|
|
377
|
+ owner.doNotification(date, format, client, modes);
|
389
|
378
|
}
|
390
|
379
|
}
|
391
|
380
|
|
|
@@ -399,11 +388,10 @@ public class ChannelEventHandler extends EventHandler implements
|
399
|
388
|
final String host) {
|
400
|
389
|
checkParser(parser);
|
401
|
390
|
|
402
|
|
- final StringBuffer messageType = new StringBuffer("channelModeNotice");
|
403
|
|
- triggerAction(messageType, CoreActionType.CHANNEL_MODE_NOTICE, client, String.
|
404
|
|
- valueOf(prefix), message);
|
405
|
|
- owner.doNotification(date, messageType.toString(),
|
406
|
|
- client, String.valueOf(prefix), message);
|
|
391
|
+ final DisplayableEvent event = new ChannelModeNoticeEvent(owner, client,
|
|
392
|
+ String.valueOf(prefix), message);
|
|
393
|
+ final String format = EventUtils.postDisplayable(eventBus, event, "channelModeNotice");
|
|
394
|
+ owner.doNotification(date, format, client, String.valueOf(prefix), message);
|
407
|
395
|
}
|
408
|
396
|
|
409
|
397
|
@Override
|
|
@@ -412,18 +400,9 @@ public class ChannelEventHandler extends EventHandler implements
|
412
|
400
|
checkParser(parser);
|
413
|
401
|
|
414
|
402
|
final DisplayableEvent event = new ChannelListmodesretrievedEvent(owner, mode);
|
415
|
|
- event.setDisplayFormat("channelListModeRetrieved");
|
416
|
|
- eventBus.post(event);
|
417
|
|
- owner.doNotification(date, "channelListModeRetrieved", mode);
|
418
|
|
- }
|
419
|
|
-
|
420
|
|
- private boolean triggerAction(final StringBuffer messageType, final ActionType actionType,
|
421
|
|
- final Object... args) {
|
422
|
|
- final List<Object> actionArgs = new ArrayList<>();
|
423
|
|
- actionArgs.add(owner);
|
424
|
|
- actionArgs.addAll(Arrays.asList(args));
|
425
|
|
- return ActionManager.getActionManager().triggerEvent(actionType, messageType,
|
426
|
|
- actionArgs.toArray());
|
|
403
|
+ final String format = EventUtils.postDisplayable(eventBus, event,
|
|
404
|
+ "channelListModeRetrieved");
|
|
405
|
+ owner.doNotification(date, format, mode);
|
427
|
406
|
}
|
428
|
407
|
|
429
|
408
|
}
|