瀏覽代碼

Make more things use GroupChatUser.

  - Also by AutoValue Topic
  - Also make getUser in Topic Optional
pull/222/head
Greg Holmes 9 年之前
父節點
當前提交
5d4d0639ce

+ 21
- 60
logging/src/com/dmdirc/addons/logging/LoggingManager.java 查看文件

@@ -51,10 +51,6 @@ import com.dmdirc.interfaces.User;
51 51
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
52 52
 import com.dmdirc.interfaces.config.ConfigChangeListener;
53 53
 import com.dmdirc.logger.ErrorLevel;
54
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
55
-import com.dmdirc.parser.interfaces.ChannelInfo;
56
-import com.dmdirc.parser.interfaces.ClientInfo;
57
-import com.dmdirc.parser.interfaces.Parser;
58 54
 import com.dmdirc.plugins.PluginDomain;
59 55
 import com.dmdirc.ui.WindowManager;
60 56
 import com.dmdirc.ui.messages.BackBufferFactory;
@@ -270,45 +266,43 @@ public class LoggingManager implements ConfigChangeListener {
270 266
     @Handler
271 267
     public void handleChannelGotTopic(final ChannelGottopicEvent event) {
272 268
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
273
-        final ChannelInfo channel = event.getChannel().getChannelInfo();
274 269
         final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
275 270
         final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
276 271
 
277
-        appendLine(filename, "*** Topic is: %s", channel.getTopic());
278
-        appendLine(filename, "*** Set at: %s on %s by %s", timeFormat.format(1000 * channel.
279
-                getTopicTime()), dateFormat.format(1000 * channel.getTopicTime()), channel.
280
-                getTopicSetter());
272
+        appendLine(filename, "*** Topic is: %s", event.getTopic().getTopic());
273
+        appendLine(filename, "*** Set at: %s on %s by %s",
274
+                timeFormat.format(1000 * event.getTopic().getTime()),
275
+                dateFormat.format(1000 * event.getTopic().getTime()),
276
+                        event.getTopic().getClient()
277
+                                .map(GroupChatUser::getNickname).orElse("Unknown"));
281 278
     }
282 279
 
283 280
     @Handler
284 281
     public void handleChannelTopicChange(final ChannelTopicChangeEvent event) {
285 282
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
286
-        final GroupChatUser channelClient = event.getTopic().getClient();
287 283
         appendLine(filename, "*** %s Changed the topic to: %s",
288
-                getDisplayName(channelClient), event.getTopic());
284
+                event.getTopic().getClient().map(this::getDisplayName).orElse(""), event.getTopic());
289 285
     }
290 286
 
291 287
     @Handler
292 288
     public void handleChannelJoin(final ChannelJoinEvent event) {
293 289
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
294
-        final ChannelClientInfo channelClient = event.getClient();
295
-        final ClientInfo client = channelClient.getClient();
296
-        appendLine(filename, "*** %s (%s) joined the channel",
297
-                getDisplayName(channelClient), client.toString());
290
+        final GroupChatUser channelClient = event.getClient();
291
+        appendLine(filename, "*** %s (%s) joined the channel", getDisplayName(channelClient),
292
+                channelClient.getNickname());
298 293
     }
299 294
 
300 295
     @Handler
301 296
     public void handleChannelPart(final ChannelPartEvent event) {
302 297
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
303 298
         final String message = event.getMessage();
304
-        final ChannelClientInfo channelClient = event.getClient();
305
-        final ClientInfo client = channelClient.getClient();
299
+        final GroupChatUser channelClient = event.getClient();
306 300
         if (message.isEmpty()) {
307
-            appendLine(filename, "*** %s (%s) left the channel",
308
-                    getDisplayName(channelClient), client.toString());
301
+            appendLine(filename, "*** %s (%s) left the channel", getDisplayName(channelClient),
302
+                    channelClient.getNickname());
309 303
         } else {
310 304
             appendLine(filename, "*** %s (%s) left the channel (%s)",
311
-                    getDisplayName(channelClient), client.toString(), message);
305
+                    getDisplayName(channelClient), channelClient.getNickname(), message);
312 306
         }
313 307
     }
314 308
 
@@ -316,21 +310,20 @@ public class LoggingManager implements ConfigChangeListener {
316 310
     public void handleChannelQuit(final ChannelQuitEvent event) {
317 311
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
318 312
         final String reason = event.getMessage();
319
-        final ChannelClientInfo channelClient = event.getClient();
320
-        final ClientInfo client = channelClient.getClient();
313
+        final GroupChatUser channelClient = event.getClient();
321 314
         if (reason.isEmpty()) {
322 315
             appendLine(filename, "*** %s (%s) Quit IRC",
323
-                    getDisplayName(channelClient), client.toString());
316
+                    getDisplayName(channelClient), channelClient.getNickname());
324 317
         } else {
325 318
             appendLine(filename, "*** %s (%s) Quit IRC (%s)",
326
-                    getDisplayName(channelClient), client.toString(), reason);
319
+                    getDisplayName(channelClient), channelClient.getNickname(), reason);
327 320
         }
328 321
     }
329 322
 
330 323
     @Handler
331 324
     public void handleChannelKick(final ChannelKickEvent event) {
332
-        final ChannelClientInfo victim = event.getVictim();
333
-        final ChannelClientInfo perpetrator = event.getClient();
325
+        final GroupChatUser victim = event.getVictim();
326
+        final GroupChatUser perpetrator = event.getClient();
334 327
         final String reason = event.getReason();
335 328
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
336 329
 
@@ -353,7 +346,7 @@ public class LoggingManager implements ConfigChangeListener {
353 346
     @Handler
354 347
     public void handleModeChange(final ChannelModechangeEvent event) {
355 348
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
356
-        if (event.getClient().getClient().getNickname().isEmpty()) {
349
+        if (event.getClient().getNickname().isEmpty()) {
357 350
             appendLine(filename, "*** Channel modes are: %s", event.getModes());
358 351
         } else {
359 352
             appendLine(filename, "*** %s set modes: %s",
@@ -538,17 +531,6 @@ public class LoggingManager implements ConfigChangeListener {
538 531
         return false;
539 532
     }
540 533
 
541
-    /**
542
-     * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
543
-     *
544
-     * @param channelClient The client to get the display name for
545
-     *
546
-     * @return name to display
547
-     */
548
-    protected String getDisplayName(final ChannelClientInfo channelClient) {
549
-        return getDisplayName(channelClient, "");
550
-    }
551
-
552 534
     /**
553 535
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
554 536
      *
@@ -560,26 +542,6 @@ public class LoggingManager implements ConfigChangeListener {
560 542
         return getDisplayName(channelClient, "");
561 543
     }
562 544
 
563
-    /**
564
-     * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
565
-     *
566
-     * @param channelClient The client to get the display name for
567
-     * @param overrideNick  Nickname to display instead of real nickname
568
-     *
569
-     * @return name to display
570
-     */
571
-    protected String getDisplayName(final ChannelClientInfo channelClient, final String overrideNick) {
572
-        if (channelClient == null) {
573
-            return overrideNick.isEmpty() ? "Unknown Client" : overrideNick;
574
-        } else if (overrideNick.isEmpty()) {
575
-            return channelmodeprefix ? channelClient.toString() : channelClient.getClient().
576
-                    getNickname();
577
-        } else {
578
-            return channelmodeprefix ? channelClient.getImportantModePrefix() + overrideNick
579
-                    : overrideNick;
580
-        }
581
-    }
582
-
583 545
     /**
584 546
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
585 547
      *
@@ -612,8 +574,7 @@ public class LoggingManager implements ConfigChangeListener {
612 574
         if (target instanceof Channel) {
613 575
             descriptor = target.getName();
614 576
         } else if (target instanceof Query) {
615
-            final Parser parser = target.getConnection().get().getParser().get();
616
-            descriptor = parser.getClient(((PrivateChat) target).getHost()).getNickname();
577
+            descriptor = ((PrivateChat) target).getNickname();
617 578
         } else {
618 579
             // Unknown component
619 580
             return false;

+ 17
- 23
nickcolours/src/com/dmdirc/addons/nickcolours/NickColourManager.java 查看文件

@@ -27,15 +27,15 @@ import com.dmdirc.ClientModule.GlobalConfig;
27 27
 import com.dmdirc.DMDircMBassador;
28 28
 import com.dmdirc.events.ChannelGotnamesEvent;
29 29
 import com.dmdirc.events.ChannelJoinEvent;
30
+import com.dmdirc.interfaces.GroupChatUser;
31
+import com.dmdirc.interfaces.User;
30 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31 33
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32 34
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
33
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
34
-import com.dmdirc.parser.interfaces.ChannelInfo;
35
-import com.dmdirc.parser.interfaces.ClientInfo;
35
+import com.dmdirc.parser.interfaces.StringConverter;
36 36
 import com.dmdirc.plugins.PluginDomain;
37
-import com.dmdirc.util.colours.Colour;
38 37
 import com.dmdirc.ui.messages.ColourManager;
38
+import com.dmdirc.util.colours.Colour;
39 39
 
40 40
 import java.util.ArrayList;
41 41
 import java.util.Collection;
@@ -45,6 +45,7 @@ import java.util.Map;
45 45
 import javax.inject.Inject;
46 46
 import javax.inject.Singleton;
47 47
 
48
+import autovalue.shaded.com.google.common.common.collect.Maps;
48 49
 import net.engio.mbassy.listener.Handler;
49 50
 
50 51
 /**
@@ -82,12 +83,8 @@ public class NickColourManager implements ConfigChangeListener {
82 83
 
83 84
     @Handler
84 85
     public void handleChannelNames(final ChannelGotnamesEvent event) {
85
-        final ChannelInfo chanInfo = event.getChannel().getChannelInfo();
86 86
         final String network = event.getChannel().getConnection().get().getNetwork();
87
-
88
-        for (ChannelClientInfo client : chanInfo.getChannelClients()) {
89
-            colourClient(network, client);
90
-        }
87
+        event.getChannel().getUsers().forEach(client -> colourClient(network, client));
91 88
     }
92 89
 
93 90
     @Handler
@@ -102,23 +99,20 @@ public class NickColourManager implements ConfigChangeListener {
102 99
      * @param network The network to use for the colouring
103 100
      * @param client  The client to be coloured
104 101
      */
105
-    private void colourClient(final String network,
106
-            final ChannelClientInfo client) {
107
-        final Map<Object, Object> map = client.getMap();
108
-        final ClientInfo myself = client.getClient().getParser().getLocalClient();
109
-        final String nickOption1 = "color:"
110
-                + client.getClient().getParser().getStringConverter().
111
-                toLowerCase(network + ':' + client.getClient().getNickname());
112
-        final String nickOption2 = "color:"
113
-                + client.getClient().getParser().getStringConverter().
114
-                toLowerCase("*:" + client.getClient().getNickname());
115
-
116
-        if (useowncolour && client.getClient().equals(myself)) {
102
+    private void colourClient(final String network, final GroupChatUser client) {
103
+        final StringConverter sc = client.getUser().getConnection().getParser().get()
104
+                .getStringConverter();
105
+        // TODO: This needs to use the new setDisplayableProperty on GroupChatUser
106
+        final Map<Object, Object> map = Maps.newHashMap();
107
+        final User myself = client.getUser();
108
+        final String nickOption1 = "color:" + sc.toLowerCase(network + ':' + client.getNickname());
109
+        final String nickOption2 = "color:" + sc.toLowerCase("*:" + client.getNickname());
110
+
111
+        if (useowncolour && client.getUser().equals(myself)) {
117 112
             final Colour color = colourManager.getColourFromString(owncolour, null);
118 113
             putColour(map, color, color);
119 114
         } else if (userandomcolour) {
120
-            putColour(map, getColour(client.getClient().getNickname()), getColour(client.
121
-                    getClient().getNickname()));
115
+            putColour(map, getColour(client.getNickname()), getColour(client.getNickname()));
122 116
         }
123 117
 
124 118
         String[] parts = null;

+ 4
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/components/NicklistComparator.java 查看文件

@@ -57,15 +57,14 @@ public final class NicklistComparator implements Comparator<GroupChatUser>, Seri
57 57
     public int compare(final GroupChatUser client1, final GroupChatUser client2) {
58 58
         ComparisonChain comparisonChain = ComparisonChain.start();
59 59
         if (sortByMode) {
60
-            comparisonChain = comparisonChain
61
-                    .compare(client1.getImportantMode(), client2.getImportantMode());
60
+            comparisonChain = comparisonChain.compare(client1.getImportantMode(),
61
+                    client2.getImportantMode(), Comparator.<String>naturalOrder());
62 62
         }
63 63
         if (sortByCase) {
64 64
             comparisonChain = comparisonChain.compare(client1.getNickname(), client2.getNickname());
65 65
         } else {
66
-            comparisonChain = comparisonChain
67
-                    .compare(client1.getNickname().toLowerCase(),
68
-                            client2.getNickname().toLowerCase());
66
+            comparisonChain = comparisonChain.compare(client1.getNickname().toLowerCase(),
67
+                    client2.getNickname().toLowerCase());
69 68
         }
70 69
         return comparisonChain.result();
71 70
     }

+ 3
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java 查看文件

@@ -31,6 +31,7 @@ import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler;
31 31
 import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
32 32
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
33 33
 import com.dmdirc.interfaces.CommandController;
34
+import com.dmdirc.interfaces.GroupChatUser;
34 35
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35 36
 import com.dmdirc.interfaces.ui.InputWindow;
36 37
 import com.dmdirc.plugins.ServiceManager;
@@ -166,7 +167,8 @@ public class TopicDisplayPane extends JPanel implements DocumentListener {
166 167
      */
167 168
     public void setTopic(final Optional<Topic> topic) {
168 169
         if (topic.isPresent()) {
169
-            topicWho.setText("Topic set by " + topic.get().getClient().getNickname()
170
+            topicWho.setText("Topic set by " + topic.get().getClient()
171
+                    .map(GroupChatUser::getNickname).orElse("Unknown")
170 172
                     + "<br> on " + new Date(1000 * topic.get().getTime()));
171 173
             topicText.setText(topic.get().getTopic());
172 174
         } else {

+ 5
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java 查看文件

@@ -26,6 +26,7 @@ import com.dmdirc.Channel;
26 26
 import com.dmdirc.Topic;
27 27
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28 28
 import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
29
+import com.dmdirc.interfaces.GroupChatUser;
29 30
 
30 31
 import java.awt.Color;
31 32
 import java.util.Date;
@@ -130,9 +131,11 @@ public class TopicLabel extends JPanel {
130 131
 
131 132
         TextLabel label;
132 133
         if (topic.getTopic().isEmpty()) {
133
-            label = new TextLabel("Topic unset by " + topic.getClient().getNickname());
134
+            label = new TextLabel("Topic unset by " + topic.getClient()
135
+                    .map(GroupChatUser::getNickname).orElse("Unknown"));
134 136
         } else {
135
-            label = new TextLabel("Topic set by " + topic.getClient().getNickname());
137
+            label = new TextLabel("Topic set by " + topic.getClient()
138
+                    .map(GroupChatUser::getNickname).orElse("Unknown"));
136 139
         }
137 140
         add(label, "wmax 450, grow, push, wrap, gapleft 5, pad 0");
138 141
 

Loading…
取消
儲存