Pārlūkot izejas kodu

Use new GroupChatManager methods.

Remove them from the Connection interface.
pull/367/head
Chris Smith 9 gadus atpakaļ
vecāks
revīzija
dfd6ee709c

+ 1
- 1
src/com/dmdirc/MessageEncoder.java Parādīt failu

@@ -65,7 +65,7 @@ public class MessageEncoder implements Encoder {
65 65
                 .getOption("general", "encoding");
66 66
 
67 67
         if (target != null && parser.isValidChannelName(target)) {
68
-            encoding = connection.getChannel(target)
68
+            encoding = connection.getGroupChatManager().getChannel(target)
69 69
                     .map(GroupChat::getWindowModel)
70 70
                     .map(FrameContainer::getConfigManager)
71 71
                     .map(cm -> cm.getOption("general", "encoding"))

+ 5
- 4
src/com/dmdirc/ServerManager.java Parādīt failu

@@ -188,7 +188,8 @@ public class ServerManager implements ConnectionManager {
188 188
         } else {
189 189
             final Collection<? extends ChannelJoinRequest> joinRequests =
190 190
                     server.getParser().get().extractChannels(uri);
191
-            server.join(joinRequests.toArray(new ChannelJoinRequest[joinRequests.size()]));
191
+            server.getGroupChatManager()
192
+                    .join(joinRequests.toArray(new ChannelJoinRequest[joinRequests.size()]));
192 193
         }
193 194
 
194 195
         return server;
@@ -204,8 +205,8 @@ public class ServerManager implements ConnectionManager {
204 205
             if (server.getState() == ServerState.CONNECTED) {
205 206
                 connectedServer = server;
206 207
 
207
-                if (server.getChannel("#DMDirc").isPresent()) {
208
-                    server.join(new ChannelJoinRequest("#DMDirc"));
208
+                if (server.getGroupChatManager().getChannel("#DMDirc").isPresent()) {
209
+                    server.getGroupChatManager().join(new ChannelJoinRequest("#DMDirc"));
209 210
                     return;
210 211
                 }
211 212
             }
@@ -219,7 +220,7 @@ public class ServerManager implements ConnectionManager {
219 220
                         "Unable to construct new server", ""));
220 221
             }
221 222
         } else {
222
-            connectedServer.join(new ChannelJoinRequest("#DMDirc"));
223
+            connectedServer.getGroupChatManager().join(new ChannelJoinRequest("#DMDirc"));
223 224
         }
224 225
     }
225 226
 

+ 1
- 1
src/com/dmdirc/commandparser/CommandManager.java Parādīt failu

@@ -178,7 +178,7 @@ public class CommandManager implements CommandController {
178 178
 
179 179
             if (command.getType() == CommandType.TYPE_CHANNEL
180 180
                     || command.getType() == CommandType.TYPE_CHAT) {
181
-                for (GroupChat channel : server.getChannels()) {
181
+                for (GroupChat channel : server.getGroupChatManager().getChannels()) {
182 182
                     registerCommandName(channel.getWindowModel().getTabCompleter(),
183 183
                             commandName, register);
184 184
                 }

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/AllChannels.java Parādīt failu

@@ -70,7 +70,7 @@ public class AllChannels extends Command implements IntelligentCommand {
70 70
         final Connection server = ((ServerCommandContext) context).getConnection();
71 71
         final String command = args.getArgumentsAsString();
72 72
 
73
-        for (GroupChat channel : server.getChannels()) {
73
+        for (GroupChat channel : server.getGroupChatManager().getChannels()) {
74 74
             channel.getWindowModel().getCommandParser().parseCommand(channel.getWindowModel(),
75 75
                     command);
76 76
         }

+ 5
- 3
src/com/dmdirc/commandparser/commands/server/JoinChannelCommand.java Parādīt failu

@@ -100,7 +100,8 @@ public class JoinChannelCommand extends Command implements IntelligentCommand {
100 100
             }
101 101
         }
102 102
 
103
-        connection.join(!args.isSilent(), channels.toArray(new ChannelJoinRequest[channels.size()]));
103
+        connection.getGroupChatManager()
104
+                .join(!args.isSilent(), channels.toArray(new ChannelJoinRequest[channels.size()]));
104 105
     }
105 106
 
106 107
     @Handler
@@ -140,11 +141,12 @@ public class JoinChannelCommand extends Command implements IntelligentCommand {
140 141
         if (!showExisting) {
141 142
             // Only tab complete channels we're not already on
142 143
             targets.addAll(results.stream()
143
-                    .filter(result -> !connection.getChannel(result).isPresent())
144
+                    .filter(result -> !connection.getGroupChatManager()
145
+                            .getChannel(result).isPresent())
144 146
                     .map(result -> prefix + result).collect(Collectors.toList()));
145 147
         }
146 148
 
147
-        for (char chPrefix : connection.getChannelPrefixes().toCharArray()) {
149
+        for (char chPrefix : connection.getGroupChatManager().getChannelPrefixes().toCharArray()) {
148 150
             // Let them tab complete the prefixes as well
149 151
             targets.add(prefix + chPrefix);
150 152
         }

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Message.java Parādīt failu

@@ -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<GroupChat> channel = connection.getChannel(target);
83
+            final Optional<GroupChat> channel = connection.getGroupChatManager().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 Parādīt failu

@@ -193,12 +193,12 @@ public abstract class CommandParser implements Serializable {
193 193
         final String[] parts = cargs[0].split(",");
194 194
         boolean someValid = false;
195 195
         for (String part : parts) {
196
-            someValid |= server.isValidChannelName(part);
196
+            someValid |= server.getGroupChatManager().isValidChannelName(part);
197 197
         }
198 198
 
199 199
         if (someValid) {
200 200
             for (String channelName : parts) {
201
-                if (!server.isValidChannelName(channelName)) {
201
+                if (!server.getGroupChatManager().isValidChannelName(channelName)) {
202 202
                     origin.addLine("commandError", "Invalid channel name: " + channelName);
203 203
                     continue;
204 204
                 }
@@ -208,7 +208,8 @@ public abstract class CommandParser implements Serializable {
208 208
                         + args.getCommandName()
209 209
                         + (cargs.length > 1 ? ' ' + args.getArgumentsAsString(1) : "");
210 210
 
211
-                final Optional<GroupChat> channel = server.getChannel(channelName);
211
+                final Optional<GroupChat> channel = server.getGroupChatManager()
212
+                        .getChannel(channelName);
212 213
                 if (channel.isPresent()) {
213 214
                     channel.get().getWindowModel().getCommandParser()
214 215
                             .parseCommand(origin, newCommandString, false);

+ 0
- 56
src/com/dmdirc/interfaces/Connection.java Parādīt failu

@@ -29,7 +29,6 @@ import com.dmdirc.ServerState;
29 29
 import com.dmdirc.ServerStatus;
30 30
 import com.dmdirc.config.profiles.Profile;
31 31
 import com.dmdirc.interfaces.config.ConfigProvider;
32
-import com.dmdirc.parser.common.ChannelJoinRequest;
33 32
 import com.dmdirc.parser.common.IgnoreList;
34 33
 import com.dmdirc.parser.interfaces.Parser;
35 34
 
@@ -147,29 +146,6 @@ public interface Connection {
147 146
      */
148 147
     String getAwayMessage();
149 148
 
150
-    /**
151
-     * Retrieves the specified channel belonging to this server.
152
-     *
153
-     * @param channel The channel to be retrieved
154
-     *
155
-     * @return The appropriate channel object
156
-     */
157
-    Optional<GroupChat> getChannel(final String channel);
158
-
159
-    /**
160
-     * Retrieves the possible channel prefixes in use on this server.
161
-     *
162
-     * @return This server's possible channel prefixes
163
-     */
164
-    String getChannelPrefixes();
165
-
166
-    /**
167
-     * Gets a collection of all channels on this connection.
168
-     *
169
-     * @return collection of channels belonging to this connection
170
-     */
171
-    Collection<GroupChat> getChannels();
172
-
173 149
     /**
174 150
      * Retrieves this server's ignore list.
175 151
      *
@@ -328,38 +304,6 @@ public interface Connection {
328 304
      */
329 305
     boolean isNetwork(final String target);
330 306
 
331
-    /**
332
-     * Determines if the specified channel name is valid. A channel name is valid if we already have
333
-     * an existing Channel with the same name, or we have a valid parser instance and the parser
334
-     * says it's valid.
335
-     *
336
-     * @param channelName The name of the channel to test
337
-     *
338
-     * @return True if the channel name is valid, false otherwise
339
-     */
340
-    boolean isValidChannelName(final String channelName);
341
-
342
-    /**
343
-     * Attempts to join the specified channels. If channels with the same name already exist, they
344
-     * are (re)joined and their windows activated.
345
-     *
346
-     * @param requests The channel join requests to process
347
-     *
348
-     * @since 0.6.4
349
-     */
350
-    void join(final ChannelJoinRequest... requests);
351
-
352
-    /**
353
-     * Attempts to join the specified channels. If channels with the same name already exist, they
354
-     * are (re)joined.
355
-     *
356
-     * @param focus    Whether or not to focus any new channels
357
-     * @param requests The channel join requests to process
358
-     *
359
-     * @since 0.6.4
360
-     */
361
-    void join(final boolean focus, final ChannelJoinRequest... requests);
362
-
363 307
     /**
364 308
      * Reconnects to the server with a specified reason.
365 309
      *

+ 1
- 1
src/com/dmdirc/lists/GroupListManager.java Parādīt failu

@@ -98,7 +98,7 @@ public class GroupListManager implements GroupListStartListener,
98 98
      * @param entry Group list entry to join
99 99
      */
100 100
     public void joinGroupListEntry(final GroupListEntry entry) {
101
-        connection.join(new ChannelJoinRequest(entry.getName()));
101
+        connection.getGroupChatManager().join(new ChannelJoinRequest(entry.getName()));
102 102
     }
103 103
 
104 104
     /**

+ 1
- 1
src/com/dmdirc/ui/messages/Styliser.java Parādīt failu

@@ -261,7 +261,7 @@ public class Styliser implements ConfigChangeListener {
261 261
     public String doLinks(final String string) {
262 262
         String target = string;
263 263
         final String prefixes = connection == null ? null
264
-                : connection.getChannelPrefixes();
264
+                : connection.getGroupChatManager().getChannelPrefixes();
265 265
 
266 266
         String target2 = target;
267 267
         target = target.replaceAll(URL_REGEXP, CODE_HYPERLINK + "$0" + CODE_HYPERLINK);

+ 2
- 1
src/com/dmdirc/ui/messages/sink/ChannelMessageSink.java Parādīt failu

@@ -58,7 +58,8 @@ public class ChannelMessageSink implements MessageSink {
58 58
             final String messageType, final Object... args) {
59 59
         final String channelName = String.format(patternMatches[0], args);
60 60
         final Connection connection = source.getConnection().get();
61
-        final Optional<GroupChat> channel = connection.getChannel(channelName);
61
+        final Optional<GroupChat> channel = connection.getGroupChatManager()
62
+                .getChannel(channelName);
62 63
 
63 64
         if (channel.isPresent()) {
64 65
             channel.get().getWindowModel().addLine(messageType, date, args);

+ 1
- 1
src/com/dmdirc/ui/messages/sink/CommonChannelsMessageSink.java Parādīt failu

@@ -62,7 +62,7 @@ public class CommonChannelsMessageSink implements MessageSink {
62 62
         final User user = connection.getUser(username);
63 63
         boolean found = false;
64 64
 
65
-        for (GroupChat channel : connection.getChannels()) {
65
+        for (GroupChat channel : connection.getGroupChatManager().getChannels()) {
66 66
             if (channel.getUser(user).isPresent()) {
67 67
                 channel.getWindowModel().addLine(messageType, date, args);
68 68
                 found = true;

+ 9
- 4
test/com/dmdirc/ServerManagerTest.java Parādīt failu

@@ -26,6 +26,7 @@ import com.dmdirc.commandparser.parsers.CommandParser;
26 26
 import com.dmdirc.config.profiles.Profile;
27 27
 import com.dmdirc.config.profiles.ProfileManager;
28 28
 import com.dmdirc.interfaces.CommandController;
29
+import com.dmdirc.interfaces.GroupChatManager;
29 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 31
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
31 32
 import com.dmdirc.interfaces.config.IdentityFactory;
@@ -68,6 +69,7 @@ public class ServerManagerTest {
68 69
     @Mock private WindowManager windowManager;
69 70
     @Mock private ServerFactoryImpl serverFactoryImpl;
70 71
     @Mock private Server server;
72
+    @Mock private GroupChatManager groupChatManager;
71 73
     @Mock private DMDircMBassador eventBus;
72 74
     @Mock private Channel channel;
73 75
 
@@ -81,6 +83,7 @@ public class ServerManagerTest {
81 83
                 commandControllerProvider, windowManager, serverFactoryImpl, eventBus);
82 84
 
83 85
         when(server.getState()).thenReturn(ServerState.DISCONNECTED);
86
+        when(server.getGroupChatManager()).thenReturn(groupChatManager);
84 87
         when(commandControllerProvider.get()).thenReturn(commandController);
85 88
 
86 89
         when(profileManager.getProfiles()).thenReturn(Collections.singletonList(profile));
@@ -160,27 +163,29 @@ public class ServerManagerTest {
160 163
     @Test
161 164
     public void testDevChatWithChannel() {
162 165
         final Server serverA = mock(Server.class);
166
+        when(serverA.getGroupChatManager()).thenReturn(groupChatManager);
163 167
         when(serverA.isNetwork("Quakenet")).thenReturn(true);
164
-        when(serverA.getChannel("#DMDirc")).thenReturn(Optional.of(channel));
168
+        when(groupChatManager.getChannel("#DMDirc")).thenReturn(Optional.of(channel));
165 169
         when(serverA.getState()).thenReturn(ServerState.CONNECTED);
166 170
 
167 171
         serverManager.registerServer(serverA);
168 172
         serverManager.joinDevChat();
169 173
 
170
-        verify(serverA).join(new ChannelJoinRequest("#DMDirc"));
174
+        verify(groupChatManager).join(new ChannelJoinRequest("#DMDirc"));
171 175
     }
172 176
 
173 177
     @Test
174 178
     public void testDevChatWithoutChannel() {
175 179
         final Server serverA = mock(Server.class);
176 180
         when(serverA.isNetwork("Quakenet")).thenReturn(true);
177
-        when(serverA.getChannel("#DMDirc")).thenReturn(Optional.empty());
181
+        when(serverA.getGroupChatManager()).thenReturn(groupChatManager);
182
+        when(groupChatManager.getChannel("#DMDirc")).thenReturn(Optional.empty());
178 183
         when(serverA.getState()).thenReturn(ServerState.CONNECTED);
179 184
 
180 185
         serverManager.registerServer(serverA);
181 186
         serverManager.joinDevChat();
182 187
 
183
-        verify(serverA).join(new ChannelJoinRequest("#DMDirc"));
188
+        verify(groupChatManager).join(new ChannelJoinRequest("#DMDirc"));
184 189
     }
185 190
 
186 191
     @Test

+ 6
- 3
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Parādīt failu

@@ -30,6 +30,7 @@ import com.dmdirc.commandparser.commands.Command;
30 30
 import com.dmdirc.harness.TestCommandParser;
31 31
 import com.dmdirc.interfaces.CommandController;
32 32
 import com.dmdirc.interfaces.Connection;
33
+import com.dmdirc.interfaces.GroupChatManager;
33 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34 35
 
35 36
 import java.util.Optional;
@@ -59,6 +60,7 @@ public class CommandParserTest {
59 60
     @Mock private FrameContainer container;
60 61
     @Mock private Channel channel;
61 62
     @Mock private Connection connection;
63
+    @Mock private GroupChatManager groupChatManager;
62 64
     @Mock private DMDircMBassador eventBus;
63 65
     private TestCommandParser commandParser;
64 66
     private TestCommandParser channelCommandParser;
@@ -75,9 +77,10 @@ public class CommandParserTest {
75 77
         when(configProvider.getOptionInt("general", "commandhistory")).thenReturn(10);
76 78
 
77 79
         when(container.getConnection()).thenReturn(Optional.of(connection));
78
-        when(connection.isValidChannelName("#channel1")).thenReturn(true);
79
-        when(connection.isValidChannelName("#channel2")).thenReturn(true);
80
-        when(connection.getChannel("#channel1")).thenReturn(Optional.of(channel));
80
+        when(connection.getGroupChatManager()).thenReturn(groupChatManager);
81
+        when(groupChatManager.isValidChannelName("#channel1")).thenReturn(true);
82
+        when(groupChatManager.isValidChannelName("#channel2")).thenReturn(true);
83
+        when(groupChatManager.getChannel("#channel1")).thenReturn(Optional.of(channel));
81 84
 
82 85
         commandParser = new TestCommandParser(configProvider, commandController, eventBus);
83 86
         commandParser.registerCommand(command, commandInfo);

+ 4
- 1
test/com/dmdirc/ui/messages/IntelligentLinkingTest.java Parādīt failu

@@ -23,6 +23,7 @@ package com.dmdirc.ui.messages;
23 23
 
24 24
 import com.dmdirc.DMDircMBassador;
25 25
 import com.dmdirc.interfaces.Connection;
26
+import com.dmdirc.interfaces.GroupChatManager;
26 27
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 28
 
28 29
 import java.util.Arrays;
@@ -50,7 +51,9 @@ public class IntelligentLinkingTest {
50 51
 
51 52
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
52 53
         final Connection connection = mock(Connection.class);
53
-        when(connection.getChannelPrefixes()).thenReturn("#&+");
54
+        final GroupChatManager groupChatManager = mock(GroupChatManager.class);
55
+        when(connection.getGroupChatManager()).thenReturn(groupChatManager);
56
+        when(groupChatManager.getChannelPrefixes()).thenReturn("#&+");
54 57
 
55 58
         styliser = new Styliser(connection, manager, new ColourManager(manager,
56 59
                 mock(DMDircMBassador.class)));

Notiek ielāde…
Atcelt
Saglabāt