ソースを参照

More GroupChatUser changes.

pull/305/head
Greg Holmes 9年前
コミット
fc23f90e2e

+ 9
- 9
src/com/dmdirc/ChannelEventHandler.java ファイルの表示

@@ -184,10 +184,9 @@ public class ChannelEventHandler extends EventHandler implements
184 184
                 format = EventUtils.postDisplayable(eventBus, event,
185 185
                         "channelTopicRemoved");
186 186
             } else {
187
-                event = new ChannelTopicUnsetEvent(owner,
188
-                        channel.getChannelClient(channel.getTopicSetter(), true));
189
-                format = EventUtils.postDisplayable(eventBus, event,
190
-                        "channelTopicChanged");
187
+                event = new ChannelTopicUnsetEvent(owner, owner.getUser(owner.getConnection().get()
188
+                        .getUser(channel.getTopicSetter())).orElse(null));
189
+                format = EventUtils.postDisplayable(eventBus, event, "channelTopicChanged");
191 190
             }
192 191
             owner.doNotification(date, format, channel.getChannelClient(channel.getTopicSetter(),
193 192
                     true), channel.getTopic());
@@ -325,8 +324,8 @@ public class ChannelEventHandler extends EventHandler implements
325 324
                 format = "channelSplitUserMode_default";
326 325
             }
327 326
 
328
-            final ChannelUsermodechangeEvent event = new ChannelUsermodechangeEvent(owner, client,
329
-                    targetClient, mode);
327
+            final ChannelUsermodechangeEvent event = new ChannelUsermodechangeEvent(owner,
328
+                    owner.getUserFromClient(client), owner.getUserFromClient(targetClient), mode);
330 329
             final String result = EventUtils.postDisplayable(eventBus, event, format);
331 330
             owner.doNotification(date, result, client, targetClient, mode);
332 331
         }
@@ -338,7 +337,8 @@ public class ChannelEventHandler extends EventHandler implements
338 337
             final String type, final String message, final String host) {
339 338
         checkParser(parser);
340 339
 
341
-        final ChannelCtcpEvent event = new ChannelCtcpEvent(owner, client, type, message);
340
+        final ChannelCtcpEvent event = new ChannelCtcpEvent(owner, owner.getUserFromClient(client),
341
+                type, message);
342 342
         final String format = EventUtils.postDisplayable(eventBus, event, "channelCTCP");
343 343
         if (!event.isHandled()) {
344 344
             getConnection().sendCTCPReply(client.getClient().getNickname(), type, message);
@@ -414,8 +414,8 @@ public class ChannelEventHandler extends EventHandler implements
414 414
             final String host) {
415 415
         checkParser(parser);
416 416
 
417
-        final ChannelModeNoticeEvent event = new ChannelModeNoticeEvent(owner, client,
418
-                String.valueOf(prefix), message);
417
+        final ChannelModeNoticeEvent event = new ChannelModeNoticeEvent(owner,
418
+                owner.getUserFromClient(client), String.valueOf(prefix), message);
419 419
         final String format = EventUtils.postDisplayable(eventBus, event, "channelModeNotice");
420 420
         owner.doNotification(date, format, client, String.valueOf(prefix), message);
421 421
     }

+ 10
- 5
src/com/dmdirc/commandparser/commands/channel/Ban.java ファイルの表示

@@ -33,10 +33,12 @@ import com.dmdirc.commandparser.commands.IntelligentCommand;
33 33
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35 35
 import com.dmdirc.interfaces.CommandController;
36
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
36
+import com.dmdirc.interfaces.GroupChatUser;
37 37
 import com.dmdirc.ui.input.AdditionalTabTargets;
38 38
 import com.dmdirc.ui.input.TabCompletionType;
39 39
 
40
+import java.util.Optional;
41
+
40 42
 import javax.annotation.Nonnull;
41 43
 import javax.inject.Inject;
42 44
 
@@ -66,15 +68,18 @@ public class Ban extends Command implements IntelligentCommand {
66 68
         final Channel channel = ((ChannelCommandContext) context).getChannel();
67 69
 
68 70
         if (args.getArguments().length == 0) {
69
-            showUsage(origin, args.isSilent(), "ban", "<user|host>");
71
+            showUsage(origin, args.isSilent(), INFO.getName(), INFO.getHelp());
70 72
             return;
71 73
         }
72 74
 
73 75
         String host = args.getArguments()[0];
74
-        final ChannelClientInfo user = channel.getChannelInfo().getChannelClient(host);
75
-        if (user != null && !user.getClient().getHostname().isEmpty()) {
76
+
77
+        final Optional<GroupChatUser> user
78
+                = channel.getUser(channel.getConnection().get().getUser(host));
79
+        final String hostname = user.flatMap(GroupChatUser::getHostname).orElse("");
80
+        if (!hostname.isEmpty()) {
76 81
             // TODO: Customisable ban masks, somehow.
77
-            host = "*!*@" + user.getClient().getHostname();
82
+            host = "*!*@" + hostname;
78 83
         }
79 84
 
80 85
         channel.getChannelInfo().alterMode(true, 'b', host);

+ 5
- 5
src/com/dmdirc/events/ChannelCtcpEvent.java ファイルの表示

@@ -23,27 +23,27 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired on receiving a channel CTCP request.
30 30
  */
31 31
 public class ChannelCtcpEvent extends ChannelDisplayableEvent {
32 32
 
33
-    private final ChannelClientInfo client;
33
+    private final GroupChatUser client;
34 34
     private final String type;
35 35
     private final String message;
36 36
     private boolean handled;
37 37
 
38 38
     public ChannelCtcpEvent(final long timestamp, final Channel channel,
39
-            final ChannelClientInfo client, final String type, final String message) {
39
+            final GroupChatUser client, final String type, final String message) {
40 40
         super(timestamp, channel);
41 41
         this.client = client;
42 42
         this.type = type;
43 43
         this.message = message;
44 44
     }
45 45
 
46
-    public ChannelCtcpEvent(final Channel channel, final ChannelClientInfo client,
46
+    public ChannelCtcpEvent(final Channel channel, final GroupChatUser client,
47 47
             final String type, final String message) {
48 48
         super(channel);
49 49
         this.client = client;
@@ -51,7 +51,7 @@ public class ChannelCtcpEvent extends ChannelDisplayableEvent {
51 51
         this.message = message;
52 52
     }
53 53
 
54
-    public ChannelClientInfo getClient() {
54
+    public GroupChatUser getClient() {
55 55
         return client;
56 56
     }
57 57
 

+ 5
- 5
src/com/dmdirc/events/ChannelModeNoticeEvent.java ファイルの表示

@@ -23,26 +23,26 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired when a channel mode is received.
30 30
  */
31 31
 public class ChannelModeNoticeEvent extends ChannelDisplayableEvent {
32 32
 
33
-    private final ChannelClientInfo client;
33
+    private final GroupChatUser client;
34 34
     private final String prefix;
35 35
     private final String message;
36 36
 
37 37
     public ChannelModeNoticeEvent(final long timestamp, final Channel channel,
38
-            final ChannelClientInfo client, final String prefix, final String message) {
38
+            final GroupChatUser client, final String prefix, final String message) {
39 39
         super(timestamp, channel);
40 40
         this.client = client;
41 41
         this.prefix = prefix;
42 42
         this.message = message;
43 43
     }
44 44
 
45
-    public ChannelModeNoticeEvent(final Channel channel, final ChannelClientInfo client,
45
+    public ChannelModeNoticeEvent(final Channel channel, final GroupChatUser client,
46 46
             final String prefix, final String message) {
47 47
         super(channel);
48 48
         this.client = client;
@@ -50,7 +50,7 @@ public class ChannelModeNoticeEvent extends ChannelDisplayableEvent {
50 50
         this.message = message;
51 51
     }
52 52
 
53
-    public ChannelClientInfo getClient() {
53
+    public GroupChatUser getClient() {
54 54
         return client;
55 55
     }
56 56
 

+ 5
- 5
src/com/dmdirc/events/ChannelTopicUnsetEvent.java ファイルの表示

@@ -23,27 +23,27 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired when a topic is cleared.
30 30
  */
31 31
 public class ChannelTopicUnsetEvent extends ChannelDisplayableEvent {
32 32
 
33
-    private final ChannelClientInfo client;
33
+    private final GroupChatUser client;
34 34
 
35 35
     public ChannelTopicUnsetEvent(final long timestamp, final Channel channel,
36
-            final ChannelClientInfo client) {
36
+            final GroupChatUser client) {
37 37
         super(timestamp, channel);
38 38
         this.client = client;
39 39
     }
40 40
 
41
-    public ChannelTopicUnsetEvent(final Channel channel, final ChannelClientInfo client) {
41
+    public ChannelTopicUnsetEvent(final Channel channel, final GroupChatUser client) {
42 42
         super(channel);
43 43
         this.client = client;
44 44
     }
45 45
 
46
-    public ChannelClientInfo getClient() {
46
+    public GroupChatUser getClient() {
47 47
         return client;
48 48
     }
49 49
 

+ 7
- 7
src/com/dmdirc/events/ChannelUsermodechangeEvent.java ファイルの表示

@@ -23,19 +23,19 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired when a channel user mode change occurs.
30 30
  */
31 31
 public class ChannelUsermodechangeEvent extends ChannelDisplayableEvent {
32 32
 
33
-    private final ChannelClientInfo user;
34
-    private final ChannelClientInfo victim;
33
+    private final GroupChatUser user;
34
+    private final GroupChatUser victim;
35 35
     private final String modes;
36 36
 
37 37
     public ChannelUsermodechangeEvent(final long timestamp, final Channel channel,
38
-            final ChannelClientInfo user, final ChannelClientInfo victim, final String modes) {
38
+            final GroupChatUser user, final GroupChatUser victim, final String modes) {
39 39
         super(timestamp, channel);
40 40
         this.user = user;
41 41
         this.victim = victim;
@@ -43,18 +43,18 @@ public class ChannelUsermodechangeEvent extends ChannelDisplayableEvent {
43 43
     }
44 44
 
45 45
     public ChannelUsermodechangeEvent(final Channel channel,
46
-            final ChannelClientInfo user, final ChannelClientInfo victim, final String modes) {
46
+            final GroupChatUser user, final GroupChatUser victim, final String modes) {
47 47
         super(channel);
48 48
         this.user = user;
49 49
         this.victim = victim;
50 50
         this.modes = modes;
51 51
     }
52 52
 
53
-    public ChannelClientInfo getUser() {
53
+    public GroupChatUser getUser() {
54 54
         return user;
55 55
     }
56 56
 
57
-    public ChannelClientInfo getVictim() {
57
+    public GroupChatUser getVictim() {
58 58
         return victim;
59 59
     }
60 60
 

+ 25
- 27
test/com/dmdirc/commandparser/commands/channel/BanTest.java ファイルの表示

@@ -27,9 +27,10 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.commandparser.CommandArguments;
28 28
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
29 29
 import com.dmdirc.interfaces.CommandController;
30
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
30
+import com.dmdirc.interfaces.Connection;
31
+import com.dmdirc.interfaces.GroupChatUser;
32
+import com.dmdirc.interfaces.User;
31 33
 import com.dmdirc.parser.interfaces.ChannelInfo;
32
-import com.dmdirc.parser.interfaces.ClientInfo;
33 34
 
34 35
 import java.util.Optional;
35 36
 
@@ -39,16 +40,34 @@ import org.junit.runner.RunWith;
39 40
 import org.mockito.Mock;
40 41
 import org.mockito.runners.MockitoJUnitRunner;
41 42
 
42
-import static org.mockito.Mockito.*;
43
+import static org.mockito.Mockito.anyChar;
44
+import static org.mockito.Mockito.anyString;
45
+import static org.mockito.Mockito.eq;
46
+import static org.mockito.Mockito.verify;
47
+import static org.mockito.Mockito.when;
43 48
 
44 49
 @RunWith(MockitoJUnitRunner.class)
45 50
 public class BanTest {
46 51
 
52
+    @Mock private Connection connection;
53
+    @Mock private User user1;
54
+    @Mock private User user2;
55
+    @Mock private GroupChatUser groupChatUser;
56
+    @Mock private Channel channel;
47 57
     @Mock private CommandController controller;
58
+    @Mock private FrameContainer container;
59
+    @Mock private ChannelInfo channelInfo;
48 60
     private Ban command;
49 61
 
50 62
     @Before
51 63
     public void setup() {
64
+        when(channel.getChannelInfo()).thenReturn(channelInfo);
65
+        when(channel.getConnection()).thenReturn(Optional.of(connection));
66
+        when(connection.getUser("user")).thenReturn(user1);
67
+        when(connection.getUser("*!*@my.host.name")).thenReturn(user2);
68
+        when(groupChatUser.getHostname()).thenReturn(Optional.of("HOSTNAME"));
69
+        when(channel.getUser(user1)).thenReturn(Optional.of(groupChatUser));
70
+        when(channel.getUser(user2)).thenReturn(Optional.empty());
52 71
         when(controller.getCommandChar()).thenReturn('/');
53 72
         when(controller.getSilenceChar()).thenReturn('.');
54 73
         command = new Ban(controller);
@@ -56,46 +75,25 @@ public class BanTest {
56 75
 
57 76
     @Test
58 77
     public void testUsage() {
59
-        final FrameContainer tiw = mock(FrameContainer.class);
60
-        final Channel channel = mock(Channel.class);
61
-        command.execute(tiw, new CommandArguments(controller, "/ban"),
78
+        command.execute(container, new CommandArguments(controller, "/ban"),
62 79
                 new ChannelCommandContext(null, Ban.INFO, channel));
63 80
 
64
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
81
+        verify(container).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
65 82
     }
66 83
 
67 84
     /** Tests that the ban command uses the correct hostname if given a user. */
68 85
     @Test
69 86
     public void testKnownUser() {
70
-        final FrameContainer container = mock(FrameContainer.class);
71
-        final ChannelInfo channelInfo = mock(ChannelInfo.class);
72
-        final ChannelClientInfo ccInfo = mock(ChannelClientInfo.class);
73
-        final ClientInfo clientInfo = mock(ClientInfo.class);
74
-        final Channel channel = mock(Channel.class);
75
-
76
-        when(channel.getChannelInfo()).thenReturn(channelInfo);
77
-        when(channelInfo.getChannelClient("user")).thenReturn(ccInfo);
78
-        when(ccInfo.getClient()).thenReturn(clientInfo);
79
-        when(clientInfo.getHostname()).thenReturn("my.host.name");
80
-        when(container.getConnection()).thenReturn(Optional.empty());
81
-
82 87
         command.execute(container, new CommandArguments(controller, "/ban user"),
83 88
                 new ChannelCommandContext(null, Ban.INFO, channel));
84 89
 
85
-        verify(channelInfo).alterMode(true, 'b', "*!*@my.host.name");
90
+        verify(channelInfo).alterMode(true, 'b', "*!*@HOSTNAME");
86 91
         verify(channelInfo).flushModes();
87 92
     }
88 93
 
89 94
     /** Tests that the ban command works if given a mask not a username. */
90 95
     @Test
91 96
     public void testHostmask() {
92
-        final FrameContainer container = mock(FrameContainer.class);
93
-        final ChannelInfo channelInfo = mock(ChannelInfo.class);
94
-        final Channel channel = mock(Channel.class);
95
-
96
-        when(channel.getChannelInfo()).thenReturn(channelInfo);
97
-        when(container.getConnection()).thenReturn(Optional.empty());
98
-
99 97
         command.execute(container, new CommandArguments(controller, "/ban *!*@my.host.name"),
100 98
                 new ChannelCommandContext(null, Ban.INFO, channel));
101 99
 

読み込み中…
キャンセル
保存