Просмотр исходного кода

Make events use User.

pull/250/head
Greg Holmes 9 лет назад
Родитель
Сommit
59e3352531

+ 52
- 13
src/com/dmdirc/ServerEventHandler.java Просмотреть файл

@@ -206,8 +206,12 @@ public class ServerEventHandler extends EventHandler implements
206 206
             final String message, final String host) {
207 207
         checkParser(parser);
208 208
 
209
-        final ServerCtcpEvent event = new ServerCtcpEvent(owner, owner.getParser().get()
210
-                .getClient(host), type, message);
209
+        final ClientInfo client = owner.getParser().get().getClient(host);
210
+        final ServerCtcpEvent event = new ServerCtcpEvent(owner,
211
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
212
+                        Optional.ofNullable(client.getUsername()),
213
+                        Optional.ofNullable(client.getHostname()),
214
+                        Optional.ofNullable(client.getRealname())), type, message);
211 215
         final String format = EventUtils.postDisplayable(eventBus, event, "privateCTCP");
212 216
         owner.doNotification(format, owner.getParser().get().getClient(host), type, message);
213 217
         if (!event.isHandled()) {
@@ -220,8 +224,12 @@ public class ServerEventHandler extends EventHandler implements
220 224
             final String message, final String host) {
221 225
         checkParser(parser);
222 226
 
227
+        final ClientInfo client = owner.getParser().get().getClient(host);
223 228
         final ServerCtcprEvent event = new ServerCtcprEvent(owner,
224
-                owner.getParser().get().getClient(host), type, message);
229
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
230
+                        Optional.ofNullable(client.getUsername()),
231
+                        Optional.ofNullable(client.getHostname()),
232
+                        Optional.ofNullable(client.getRealname())), type, message);
225 233
         final String format = EventUtils.postDisplayable(eventBus, event, "privateCTCPreply");
226 234
         owner.doNotification(format, owner.getParser().get().getClient(host), type, message);
227 235
     }
@@ -238,8 +246,12 @@ public class ServerEventHandler extends EventHandler implements
238 246
             final String message, final String host) {
239 247
         checkParser(parser);
240 248
 
241
-        final ServerNoticeEvent event = new ServerNoticeEvent(owner, owner.getParser().get()
242
-                .getClient(host), message);
249
+        final ClientInfo client = owner.getParser().get().getClient(host);
250
+        final ServerNoticeEvent event = new ServerNoticeEvent(owner,
251
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
252
+                        Optional.ofNullable(client.getUsername()),
253
+                        Optional.ofNullable(client.getHostname()),
254
+                        Optional.ofNullable(client.getRealname())), message);
243 255
         final String format = EventUtils.postDisplayable(eventBus, event, "privateNotice");
244 256
         owner.doNotification(format, owner.getParser().get().getClient(host), message);
245 257
     }
@@ -249,8 +261,12 @@ public class ServerEventHandler extends EventHandler implements
249 261
             final String message, final String host) {
250 262
         checkParser(parser);
251 263
 
252
-        final ServerServernoticeEvent event = new ServerServernoticeEvent(owner, owner.getParser()
253
-                .get().getClient(host), message);
264
+        final ClientInfo client = owner.getParser().get().getClient(host);
265
+        final ServerServernoticeEvent event = new ServerServernoticeEvent(owner,
266
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
267
+                        Optional.ofNullable(client.getUsername()),
268
+                        Optional.ofNullable(client.getHostname()),
269
+                        Optional.ofNullable(client.getRealname())), message);
254 270
         final String format = EventUtils.postDisplayable(eventBus, event, "serverNotice");
255 271
         owner.doNotification(format, owner.getParser().get().getClient(host), message);
256 272
     }
@@ -425,7 +441,10 @@ public class ServerEventHandler extends EventHandler implements
425 441
         checkParser(parser);
426 442
 
427 443
         final ServerUsermodesEvent event = new ServerUsermodesEvent(owner,
428
-                owner.getParser().get().getClient(host), modes);
444
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
445
+                        Optional.ofNullable(client.getUsername()),
446
+                        Optional.ofNullable(client.getHostname()),
447
+                        Optional.ofNullable(client.getRealname())), modes);
429 448
         final String format = EventUtils.postDisplayable(eventBus, event, "userModeChanged");
430 449
         owner.doNotification(format, owner.getParser().get().getClient(host), modes);
431 450
     }
@@ -435,7 +454,11 @@ public class ServerEventHandler extends EventHandler implements
435 454
             final ClientInfo client, final String modes) {
436 455
         checkParser(parser);
437 456
 
438
-        final ServerUsermodesEvent event = new ServerUsermodesEvent(owner, client, modes);
457
+        final ServerUsermodesEvent event = new ServerUsermodesEvent(owner,
458
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
459
+                        Optional.ofNullable(client.getUsername()),
460
+                        Optional.ofNullable(client.getHostname()),
461
+                        Optional.ofNullable(client.getRealname())), modes);
439 462
         final String format = EventUtils.postDisplayable(eventBus, event, modes.isEmpty()
440 463
                 || "+".equals(modes) ? "userNoModes" : "userModeDiscovered");
441 464
         owner.doNotification(format, client, modes);
@@ -446,9 +469,13 @@ public class ServerEventHandler extends EventHandler implements
446 469
             final String channel) {
447 470
         checkParser(parser);
448 471
 
472
+        final ClientInfo client = owner.getParser().get().getClient(userHost);
449 473
         owner.addInvite(new Invite(owner, channel, userHost));
450 474
         final ServerInviteReceivedEvent event = new ServerInviteReceivedEvent(owner,
451
-                owner.getParser().get().getClient(userHost), channel);
475
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
476
+                        Optional.ofNullable(client.getUsername()),
477
+                        Optional.ofNullable(client.getHostname()),
478
+                        Optional.ofNullable(client.getRealname())), channel);
452 479
         final String format = EventUtils.postDisplayable(eventBus, event, "inviteReceived");
453 480
         owner.doNotification(format, owner.getParser().get().getClient(userHost), channel);
454 481
     }
@@ -458,8 +485,12 @@ public class ServerEventHandler extends EventHandler implements
458 485
             final String host) {
459 486
         checkParser(parser);
460 487
 
488
+        final ClientInfo client = owner.getParser().get().getClient(host);
461 489
         final ServerWallopsEvent event = new ServerWallopsEvent(owner,
462
-                owner.getParser().get().getClient(host), message);
490
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
491
+                        Optional.ofNullable(client.getUsername()),
492
+                        Optional.ofNullable(client.getHostname()),
493
+                        Optional.ofNullable(client.getRealname())), message);
463 494
         final String format = EventUtils.postDisplayable(eventBus, event, "wallop");
464 495
         owner.doNotification(format, owner.getParser().get().getClient(host), message);
465 496
 
@@ -470,8 +501,12 @@ public class ServerEventHandler extends EventHandler implements
470 501
             final String host) {
471 502
         checkParser(parser);
472 503
 
504
+        final ClientInfo client = owner.getParser().get().getClient(host);
473 505
         final ServerWallusersEvent event = new ServerWallusersEvent(owner,
474
-                owner.getParser().get().getClient(host), message);
506
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
507
+                        Optional.ofNullable(client.getUsername()),
508
+                        Optional.ofNullable(client.getHostname()),
509
+                        Optional.ofNullable(client.getRealname())), message);
475 510
         final String format = EventUtils.postDisplayable(eventBus, event, "walluser");
476 511
         owner.doNotification(format, owner.getParser().get().getClient(host), message);
477 512
     }
@@ -481,8 +516,12 @@ public class ServerEventHandler extends EventHandler implements
481 516
             final String host) {
482 517
         checkParser(parser);
483 518
 
519
+        final ClientInfo client = owner.getParser().get().getClient(host);
484 520
         final ServerWalldesyncEvent event = new ServerWalldesyncEvent(owner,
485
-                owner.getParser().get().getClient(host), message);
521
+                userFactory.getUser(client.getNickname(), owner.getConnection().get(),
522
+                        Optional.ofNullable(client.getUsername()),
523
+                        Optional.ofNullable(client.getHostname()),
524
+                        Optional.ofNullable(client.getRealname())), message);
486 525
         final String format = EventUtils.postDisplayable(eventBus, event, "walldesync");
487 526
         owner.doNotification(format, owner.getParser().get().getClient(host), message);
488 527
     }

+ 8
- 8
src/com/dmdirc/events/ServerCtcpEvent.java Просмотреть файл

@@ -23,36 +23,36 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a CTCP event.
30 30
  */
31 31
 public class ServerCtcpEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String type;
35 35
     private final String content;
36 36
     private boolean handled;
37 37
 
38 38
     public ServerCtcpEvent(final long timestamp, final Connection connection,
39
-            final ClientInfo client, final String type, final String content) {
39
+            final User user, final String type, final String content) {
40 40
         super(timestamp, connection);
41
-        this.client = client;
41
+        this.user = user;
42 42
         this.type = type;
43 43
         this.content = content;
44 44
     }
45 45
 
46
-    public ServerCtcpEvent(final Connection connection, final ClientInfo client, final String type,
46
+    public ServerCtcpEvent(final Connection connection, final User user, final String type,
47 47
             final String content) {
48 48
         super(connection);
49
-        this.client = client;
49
+        this.user = user;
50 50
         this.type = type;
51 51
         this.content = content;
52 52
     }
53 53
 
54
-    public ClientInfo getClient() {
55
-        return client;
54
+    public User getUser() {
55
+        return user;
56 56
     }
57 57
 
58 58
     public String getType() {

+ 8
- 8
src/com/dmdirc/events/ServerCtcprEvent.java Просмотреть файл

@@ -23,35 +23,35 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when sending a CTCP reply.
30 30
  */
31 31
 public class ServerCtcprEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String type;
35 35
     private final String content;
36 36
 
37 37
     public ServerCtcprEvent(final long timestamp, final Connection connection,
38
-            final ClientInfo client, final String type, final String content) {
38
+            final User user, final String type, final String content) {
39 39
         super(timestamp, connection);
40
-        this.client = client;
40
+        this.user = user;
41 41
         this.type = type;
42 42
         this.content = content;
43 43
     }
44 44
 
45
-    public ServerCtcprEvent(final Connection connection, final ClientInfo client, final String type,
45
+    public ServerCtcprEvent(final Connection connection, final User user, final String type,
46 46
             final String content) {
47 47
         super(connection);
48
-        this.client = client;
48
+        this.user = user;
49 49
         this.type = type;
50 50
         this.content = content;
51 51
     }
52 52
 
53
-    public ClientInfo getClient() {
54
-        return client;
53
+    public User getUser() {
54
+        return user;
55 55
     }
56 56
 
57 57
     public String getType() {

+ 8
- 8
src/com/dmdirc/events/ServerInviteReceivedEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when an invite is received.
30 30
  */
31 31
 public class ServerInviteReceivedEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String channel;
35 35
 
36 36
     public ServerInviteReceivedEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String channel) {
37
+            final User user, final String channel) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.channel = channel;
41 41
     }
42 42
 
43
-    public ServerInviteReceivedEvent(final Connection connection, final ClientInfo client,
43
+    public ServerInviteReceivedEvent(final Connection connection, final User user,
44 44
             final String channel) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.channel = channel;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getChannel() {

+ 8
- 8
src/com/dmdirc/events/ServerNoticeEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a notice.
30 30
  */
31 31
 public class ServerNoticeEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerNoticeEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerNoticeEvent(final Connection connection, final ClientInfo client,
43
+    public ServerNoticeEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 8
- 8
src/com/dmdirc/events/ServerServernoticeEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a server notice.
30 30
  */
31 31
 public class ServerServernoticeEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerServernoticeEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerServernoticeEvent(final Connection connection, final ClientInfo client,
43
+    public ServerServernoticeEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 8
- 8
src/com/dmdirc/events/ServerUsermodesEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired in on receipt of user modes.
30 30
  */
31 31
 public class ServerUsermodesEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerUsermodesEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerUsermodesEvent(final Connection connection, final ClientInfo client,
43
+    public ServerUsermodesEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 8
- 8
src/com/dmdirc/events/ServerWalldesyncEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a server walldesync.
30 30
  */
31 31
 public class ServerWalldesyncEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerWalldesyncEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerWalldesyncEvent(final Connection connection, final ClientInfo client,
43
+    public ServerWalldesyncEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 8
- 8
src/com/dmdirc/events/ServerWallopsEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a server wallops.
30 30
  */
31 31
 public class ServerWallopsEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerWallopsEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerWallopsEvent(final Connection connection, final ClientInfo client,
43
+    public ServerWallopsEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 8
- 8
src/com/dmdirc/events/ServerWallusersEvent.java Просмотреть файл

@@ -23,32 +23,32 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.interfaces.Connection;
26
-import com.dmdirc.parser.interfaces.ClientInfo;
26
+import com.dmdirc.interfaces.User;
27 27
 
28 28
 /**
29 29
  * Fired when receiving a server wallusers.
30 30
  */
31 31
 public class ServerWallusersEvent extends ServerDisplayableEvent {
32 32
 
33
-    private final ClientInfo client;
33
+    private final User user;
34 34
     private final String message;
35 35
 
36 36
     public ServerWallusersEvent(final long timestamp, final Connection connection,
37
-            final ClientInfo client, final String message) {
37
+            final User user, final String message) {
38 38
         super(timestamp, connection);
39
-        this.client = client;
39
+        this.user = user;
40 40
         this.message = message;
41 41
     }
42 42
 
43
-    public ServerWallusersEvent(final Connection connection, final ClientInfo client,
43
+    public ServerWallusersEvent(final Connection connection, final User user,
44 44
             final String message) {
45 45
         super(connection);
46
-        this.client = client;
46
+        this.user = user;
47 47
         this.message = message;
48 48
     }
49 49
 
50
-    public ClientInfo getClient() {
51
-        return client;
50
+    public User getUser() {
51
+        return user;
52 52
     }
53 53
 
54 54
     public String getMessage() {

+ 1
- 1
test/com/dmdirc/ServerEventHandlerTest.java Просмотреть файл

@@ -210,7 +210,7 @@ public class ServerEventHandlerTest {
210 210
         final ServerCtcpEvent event = getEvent(ServerCtcpEvent.class);
211 211
         assertEquals("type", event.getType());
212 212
         assertEquals("message", event.getContent());
213
-        assertEquals(clientInfo, event.getClient());
213
+        assertEquals(clientInfo, event.getUser());
214 214
     }
215 215
 
216 216
     @Test

Загрузка…
Отмена
Сохранить