Browse Source

Use GroupChat in Connection.getChannels().

Fix the channel message sink actually doing common channels...
I guess we're not really using that one.
pull/299/head
Chris Smith 9 years ago
parent
commit
9d9857367e

+ 5
- 2
src/com/dmdirc/Server.java View File

@@ -87,6 +87,7 @@ import java.util.concurrent.TimeUnit;
87 87
 import java.util.concurrent.locks.ReadWriteLock;
88 88
 import java.util.concurrent.locks.ReentrantReadWriteLock;
89 89
 import java.util.function.Function;
90
+import java.util.stream.Collectors;
90 91
 
91 92
 import javax.annotation.Nonnull;
92 93
 import javax.annotation.Nullable;
@@ -489,8 +490,10 @@ public class Server extends FrameContainer implements Connection {
489 490
     }
490 491
 
491 492
     @Override
492
-    public Collection<Channel> getChannels() {
493
-        return channels.getAll();
493
+    public Collection<GroupChat> getChannels() {
494
+        return channels.getAll().parallelStream()
495
+                .map(c -> (GroupChat) c)
496
+                .collect(Collectors.toList());
494 497
     }
495 498
 
496 499
     @Override

+ 4
- 3
src/com/dmdirc/commandparser/CommandManager.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.GlobalWindow;
27 26
 import com.dmdirc.Query;
28 27
 import com.dmdirc.commandparser.commands.Command;
@@ -31,6 +30,7 @@ import com.dmdirc.config.ConfigBinding;
31 30
 import com.dmdirc.interfaces.CommandController;
32 31
 import com.dmdirc.interfaces.Connection;
33 32
 import com.dmdirc.interfaces.ConnectionManager;
33
+import com.dmdirc.interfaces.GroupChat;
34 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35 35
 import com.dmdirc.ui.input.TabCompleter;
36 36
 import com.dmdirc.ui.input.TabCompletionType;
@@ -178,8 +178,9 @@ public class CommandManager implements CommandController {
178 178
 
179 179
             if (command.getType() == CommandType.TYPE_CHANNEL
180 180
                     || command.getType() == CommandType.TYPE_CHAT) {
181
-                for (Channel channel : server.getChannels()) {
182
-                    registerCommandName(channel.getTabCompleter(),commandName, register);
181
+                for (GroupChat channel : server.getChannels()) {
182
+                    registerCommandName(channel.getWindowModel().getTabCompleter(),
183
+                            commandName, register);
183 184
                 }
184 185
             }
185 186
 

+ 4
- 3
src/com/dmdirc/commandparser/commands/server/AllChannels.java View File

@@ -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;
@@ -34,6 +33,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
34 33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
35 34
 import com.dmdirc.interfaces.CommandController;
36 35
 import com.dmdirc.interfaces.Connection;
36
+import com.dmdirc.interfaces.GroupChat;
37 37
 import com.dmdirc.ui.input.AdditionalTabTargets;
38 38
 import com.dmdirc.ui.input.TabCompleterUtils;
39 39
 
@@ -70,8 +70,9 @@ 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 (Channel channel : server.getChannels()) {
74
-            channel.getCommandParser().parseCommand(channel, command);
73
+        for (GroupChat channel : server.getChannels()) {
74
+            channel.getWindowModel().getCommandParser().parseCommand(channel.getWindowModel(),
75
+                    command);
75 76
         }
76 77
     }
77 78
 

+ 1
- 2
src/com/dmdirc/interfaces/Connection.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.interfaces;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.FrameContainer;
27 26
 import com.dmdirc.Invite;
28 27
 import com.dmdirc.Query;
@@ -169,7 +168,7 @@ public interface Connection {
169 168
      *
170 169
      * @return collection of channels belonging to this connection
171 170
      */
172
-    Collection<Channel> getChannels();
171
+    Collection<GroupChat> getChannels();
173 172
 
174 173
     /**
175 174
      * Retrieves this server's ignore list.

+ 7
- 11
src/com/dmdirc/ui/messages/sink/ChannelMessageSink.java View File

@@ -22,11 +22,12 @@
22 22
 
23 23
 package com.dmdirc.ui.messages.sink;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.FrameContainer;
27 26
 import com.dmdirc.interfaces.Connection;
27
+import com.dmdirc.interfaces.GroupChat;
28 28
 
29 29
 import java.util.Date;
30
+import java.util.Optional;
30 31
 import java.util.regex.Pattern;
31 32
 
32 33
 import javax.inject.Inject;
@@ -55,18 +56,13 @@ public class ChannelMessageSink implements MessageSink {
55 56
             final FrameContainer source,
56 57
             final String[] patternMatches, final Date date,
57 58
             final String messageType, final Object... args) {
58
-        final String user = String.format(patternMatches[0], args);
59
-        boolean found = false;
60
-
59
+        final String channelName = String.format(patternMatches[0], args);
61 60
         final Connection connection = source.getConnection().get();
62
-        for (Channel channel : connection.getChannels()) {
63
-            if (channel.getChannelInfo().getChannelClient(user) != null) {
64
-                channel.addLine(messageType, date, args);
65
-                found = true;
66
-            }
67
-        }
61
+        final Optional<GroupChat> channel = connection.getChannel(channelName);
68 62
 
69
-        if (!found) {
63
+        if (channel.isPresent()) {
64
+            channel.get().getWindowModel().addLine(messageType, date, args);
65
+        } else {
70 66
             if (patternMatches[1] == null) {
71 67
                 // No fallback specified
72 68
                 source.addLine(messageType, date, args);

+ 7
- 5
src/com/dmdirc/ui/messages/sink/CommonChannelsMessageSink.java View File

@@ -22,9 +22,10 @@
22 22
 
23 23
 package com.dmdirc.ui.messages.sink;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.FrameContainer;
27 26
 import com.dmdirc.interfaces.Connection;
27
+import com.dmdirc.interfaces.GroupChat;
28
+import com.dmdirc.interfaces.User;
28 29
 
29 30
 import java.util.Date;
30 31
 import java.util.regex.Pattern;
@@ -56,13 +57,14 @@ public class CommonChannelsMessageSink implements MessageSink {
56 57
             final FrameContainer source,
57 58
             final String[] patternMatches, final Date date,
58 59
             final String messageType, final Object... args) {
59
-        final String user = String.format(patternMatches[0], args);
60
+        final String username = String.format(patternMatches[0], args);
60 61
         final Connection connection = source.getConnection().get();
62
+        final User user = connection.getUser(username);
61 63
         boolean found = false;
62 64
 
63
-        for (Channel channel : connection.getChannels()) {
64
-            if (channel.getChannelInfo().getChannelClient(user) != null) {
65
-                channel.addLine(messageType, date, args);
65
+        for (GroupChat channel : connection.getChannels()) {
66
+            if (channel.getUser(user).isPresent()) {
67
+                channel.getWindowModel().addLine(messageType, date, args);
66 68
                 found = true;
67 69
             }
68 70
         }

Loading…
Cancel
Save