Przeglądaj źródła

Use GroupChat in Connection.getChannel().

pull/298/head
Chris Smith 9 lat temu
rodzic
commit
657817fd9b

+ 5
- 0
src/com/dmdirc/Channel.java Wyświetl plik

@@ -570,4 +570,9 @@ public class Channel extends MessageTarget implements GroupChat {
570 570
                 .collect(Collectors.toList());
571 571
     }
572 572
 
573
+    @Override
574
+    public FrameContainer getWindowModel() {
575
+        return this;
576
+    }
577
+
573 578
 }

+ 3
- 1
src/com/dmdirc/MessageEncoder.java Wyświetl plik

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.events.UserErrorEvent;
26 26
 import com.dmdirc.interfaces.Connection;
27
+import com.dmdirc.interfaces.GroupChat;
27 28
 import com.dmdirc.logger.ErrorLevel;
28 29
 import com.dmdirc.parser.interfaces.Encoder;
29 30
 import com.dmdirc.parser.interfaces.Parser;
@@ -65,7 +66,8 @@ public class MessageEncoder implements Encoder {
65 66
 
66 67
         if (target != null && parser.isValidChannelName(target)) {
67 68
             encoding = connection.getChannel(target)
68
-                    .map(Channel::getConfigManager)
69
+                    .map(GroupChat::getWindowModel)
70
+                    .map(FrameContainer::getConfigManager)
69 71
                     .map(cm -> cm.getOption("general", "encoding"))
70 72
                     .orElse(encoding);
71 73
         }

+ 5
- 4
src/com/dmdirc/Server.java Wyświetl plik

@@ -34,6 +34,7 @@ import com.dmdirc.events.ServerConnectingEvent;
34 34
 import com.dmdirc.events.ServerDisconnectedEvent;
35 35
 import com.dmdirc.events.ServerInviteExpiredEvent;
36 36
 import com.dmdirc.interfaces.Connection;
37
+import com.dmdirc.interfaces.GroupChat;
37 38
 import com.dmdirc.interfaces.User;
38 39
 import com.dmdirc.interfaces.config.ConfigChangeListener;
39 40
 import com.dmdirc.interfaces.config.ConfigProvider;
@@ -483,8 +484,8 @@ public class Server extends FrameContainer implements Connection {
483 484
     }
484 485
 
485 486
     @Override
486
-    public Optional<Channel> getChannel(final String channel) {
487
-        return channels.get(channel);
487
+    public Optional<GroupChat> getChannel(final String channel) {
488
+        return channels.get(channel).map(c -> (GroupChat) c);
488 489
     }
489 490
 
490 491
     @Override
@@ -590,7 +591,7 @@ public class Server extends FrameContainer implements Connection {
590 591
 
591 592
         backgroundChannels.remove(chan.getName());
592 593
 
593
-        final Optional<Channel> channel = getChannel(chan.getName());
594
+        final Optional<Channel> channel = channels.get(chan.getName());
594 595
         if (channel.isPresent()) {
595 596
             channel.get().setChannelInfo(chan);
596 597
             channel.get().selfJoin();
@@ -723,7 +724,7 @@ public class Server extends FrameContainer implements Connection {
723 724
                                 + request.getName();
724 725
                     }
725 726
 
726
-                    if (getChannel(name).map(Channel::isOnChannel).orElse(false)) {
727
+                    if (getChannel(name).map(GroupChat::isOnChannel).orElse(false)) {
727 728
                         if (!focus) {
728 729
                             backgroundChannels.add(name);
729 730
                         }

+ 2
- 2
src/com/dmdirc/commandparser/commands/server/Message.java Wyświetl plik

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.server;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.FrameContainer;
27 26
 import com.dmdirc.commandparser.BaseCommandInfo;
28 27
 import com.dmdirc.commandparser.CommandArguments;
@@ -36,6 +35,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
36 35
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
37 36
 import com.dmdirc.interfaces.CommandController;
38 37
 import com.dmdirc.interfaces.Connection;
38
+import com.dmdirc.interfaces.GroupChat;
39 39
 import com.dmdirc.parser.interfaces.Parser;
40 40
 import com.dmdirc.ui.input.AdditionalTabTargets;
41 41
 import com.dmdirc.ui.input.TabCompletionType;
@@ -80,7 +80,7 @@ public class Message extends Command implements IntelligentCommand,
80 80
 
81 81
             // If this is a known server or channel, and this is not a silent
82 82
             // invocation, use sendLine, else send it raw to the parser.
83
-            final Optional<Channel> channel = connection.getChannel(target);
83
+            final Optional<GroupChat> channel = connection.getChannel(target);
84 84
             if (!args.isSilent() && channel.isPresent()) {
85 85
                 channel.get().sendLine(message);
86 86
             } else if (!args.isSilent() && connection.hasQuery(target)) {

+ 4
- 3
src/com/dmdirc/commandparser/parsers/CommandParser.java Wyświetl plik

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.commandparser.parsers;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.DMDircMBassador;
27 26
 import com.dmdirc.FrameContainer;
28 27
 import com.dmdirc.commandparser.CommandArguments;
@@ -37,6 +36,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
37 36
 import com.dmdirc.events.UnknownCommandEvent;
38 37
 import com.dmdirc.interfaces.CommandController;
39 38
 import com.dmdirc.interfaces.Connection;
39
+import com.dmdirc.interfaces.GroupChat;
40 40
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
41 41
 import com.dmdirc.util.EventUtils;
42 42
 import com.dmdirc.util.collections.RollingList;
@@ -208,9 +208,10 @@ public abstract class CommandParser implements Serializable {
208 208
                         + args.getCommandName()
209 209
                         + (cargs.length > 1 ? ' ' + args.getArgumentsAsString(1) : "");
210 210
 
211
-                final Optional<Channel> channel = server.getChannel(channelName);
211
+                final Optional<GroupChat> channel = server.getChannel(channelName);
212 212
                 if (channel.isPresent()) {
213
-                    channel.get().getCommandParser().parseCommand(origin, newCommandString, false);
213
+                    channel.get().getWindowModel().getCommandParser()
214
+                            .parseCommand(origin, newCommandString, false);
214 215
                 } else {
215 216
                     final Map.Entry<CommandInfo, Command> actCommand = commandManager.getCommand(
216 217
                             CommandType.TYPE_CHANNEL, command);

+ 7
- 7
src/com/dmdirc/interfaces/Connection.java Wyświetl plik

@@ -155,7 +155,7 @@ public interface Connection {
155 155
      *
156 156
      * @return The appropriate channel object
157 157
      */
158
-    Optional<Channel> getChannel(final String channel);
158
+    Optional<GroupChat> getChannel(final String channel);
159 159
 
160 160
     /**
161 161
      * Retrieves the possible channel prefixes in use on this server.
@@ -437,17 +437,17 @@ public interface Connection {
437 437
     void updateTitle();
438 438
 
439 439
     /**
440
-     * Gets the core model for the input/output window for this connection.
440
+     * Sends a raw line to the underlying connection.
441 441
      *
442
-     * @return A model for windows based on this connection.
442
+     * @param line The line to be sent
443 443
      */
444
-    FrameContainer getWindowModel();
444
+    void sendLine(String line);
445 445
 
446 446
     /**
447
-     * Sends a raw line to the underlying connection.
447
+     * Gets the core model for the input/output window for this connection.
448 448
      *
449
-     * @param line The line to be sent
449
+     * @return A model for windows based on this connection.
450 450
      */
451
-    void sendLine(String line);
451
+    FrameContainer getWindowModel();
452 452
 
453 453
 }

+ 8
- 0
src/com/dmdirc/interfaces/GroupChat.java Wyświetl plik

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.interfaces;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.FrameContainer;
26 27
 import com.dmdirc.Topic;
27 28
 
28 29
 import java.util.Collection;
@@ -117,4 +118,11 @@ public interface GroupChat extends Chat {
117 118
      */
118 119
     Collection<GroupChatUser> getUsers();
119 120
 
121
+    /**
122
+     * Gets the core model for the input/output window for this connection.
123
+     *
124
+     * @return A model for windows based on this connection.
125
+     */
126
+    FrameContainer getWindowModel();
127
+
120 128
 }

+ 1
- 0
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Wyświetl plik

@@ -86,6 +86,7 @@ public class CommandParserTest {
86 86
         channelCommandParser = new TestCommandParser(configProvider, commandController, eventBus);
87 87
         channelCommandParser.registerCommand(channelCommand, channelCommandInfo);
88 88
 
89
+        when(channel.getWindowModel()).thenReturn(channel);
89 90
         when(channel.getCommandParser()).thenReturn(channelCommandParser);
90 91
     }
91 92
 

Ładowanie…
Anuluj
Zapisz