Browse Source

Make more things use GroupChatUser.

  - Also by AutoValue Topic
  - Also make getUser in Topic Optional
pull/222/head
Greg Holmes 9 years ago
parent
commit
5d4d0639ce

+ 21
- 60
logging/src/com/dmdirc/addons/logging/LoggingManager.java View File

51
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
51
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
52
 import com.dmdirc.interfaces.config.ConfigChangeListener;
52
 import com.dmdirc.interfaces.config.ConfigChangeListener;
53
 import com.dmdirc.logger.ErrorLevel;
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
 import com.dmdirc.plugins.PluginDomain;
54
 import com.dmdirc.plugins.PluginDomain;
59
 import com.dmdirc.ui.WindowManager;
55
 import com.dmdirc.ui.WindowManager;
60
 import com.dmdirc.ui.messages.BackBufferFactory;
56
 import com.dmdirc.ui.messages.BackBufferFactory;
270
     @Handler
266
     @Handler
271
     public void handleChannelGotTopic(final ChannelGottopicEvent event) {
267
     public void handleChannelGotTopic(final ChannelGottopicEvent event) {
272
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
268
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
273
-        final ChannelInfo channel = event.getChannel().getChannelInfo();
274
         final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
269
         final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
275
         final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
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
     @Handler
280
     @Handler
284
     public void handleChannelTopicChange(final ChannelTopicChangeEvent event) {
281
     public void handleChannelTopicChange(final ChannelTopicChangeEvent event) {
285
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
282
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
286
-        final GroupChatUser channelClient = event.getTopic().getClient();
287
         appendLine(filename, "*** %s Changed the topic to: %s",
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
     @Handler
287
     @Handler
292
     public void handleChannelJoin(final ChannelJoinEvent event) {
288
     public void handleChannelJoin(final ChannelJoinEvent event) {
293
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
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
     @Handler
295
     @Handler
301
     public void handleChannelPart(final ChannelPartEvent event) {
296
     public void handleChannelPart(final ChannelPartEvent event) {
302
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
297
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
303
         final String message = event.getMessage();
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
         if (message.isEmpty()) {
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
         } else {
303
         } else {
310
             appendLine(filename, "*** %s (%s) left the channel (%s)",
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
     public void handleChannelQuit(final ChannelQuitEvent event) {
310
     public void handleChannelQuit(final ChannelQuitEvent event) {
317
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
311
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
318
         final String reason = event.getMessage();
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
         if (reason.isEmpty()) {
314
         if (reason.isEmpty()) {
322
             appendLine(filename, "*** %s (%s) Quit IRC",
315
             appendLine(filename, "*** %s (%s) Quit IRC",
323
-                    getDisplayName(channelClient), client.toString());
316
+                    getDisplayName(channelClient), channelClient.getNickname());
324
         } else {
317
         } else {
325
             appendLine(filename, "*** %s (%s) Quit IRC (%s)",
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
     @Handler
323
     @Handler
331
     public void handleChannelKick(final ChannelKickEvent event) {
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
         final String reason = event.getReason();
327
         final String reason = event.getReason();
335
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
328
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
336
 
329
 
353
     @Handler
346
     @Handler
354
     public void handleModeChange(final ChannelModechangeEvent event) {
347
     public void handleModeChange(final ChannelModechangeEvent event) {
355
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
348
         final String filename = locator.getLogFile(event.getChannel().getChannelInfo());
356
-        if (event.getClient().getClient().getNickname().isEmpty()) {
349
+        if (event.getClient().getNickname().isEmpty()) {
357
             appendLine(filename, "*** Channel modes are: %s", event.getModes());
350
             appendLine(filename, "*** Channel modes are: %s", event.getModes());
358
         } else {
351
         } else {
359
             appendLine(filename, "*** %s set modes: %s",
352
             appendLine(filename, "*** %s set modes: %s",
538
         return false;
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
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
535
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
554
      *
536
      *
560
         return getDisplayName(channelClient, "");
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
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
546
      * Get name to display for channelClient (Taking into account the channelmodeprefix setting).
585
      *
547
      *
612
         if (target instanceof Channel) {
574
         if (target instanceof Channel) {
613
             descriptor = target.getName();
575
             descriptor = target.getName();
614
         } else if (target instanceof Query) {
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
         } else {
578
         } else {
618
             // Unknown component
579
             // Unknown component
619
             return false;
580
             return false;

+ 17
- 23
nickcolours/src/com/dmdirc/addons/nickcolours/NickColourManager.java View File

27
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.DMDircMBassador;
28
 import com.dmdirc.events.ChannelGotnamesEvent;
28
 import com.dmdirc.events.ChannelGotnamesEvent;
29
 import com.dmdirc.events.ChannelJoinEvent;
29
 import com.dmdirc.events.ChannelJoinEvent;
30
+import com.dmdirc.interfaces.GroupChatUser;
31
+import com.dmdirc.interfaces.User;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
33
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
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
 import com.dmdirc.plugins.PluginDomain;
36
 import com.dmdirc.plugins.PluginDomain;
37
-import com.dmdirc.util.colours.Colour;
38
 import com.dmdirc.ui.messages.ColourManager;
37
 import com.dmdirc.ui.messages.ColourManager;
38
+import com.dmdirc.util.colours.Colour;
39
 
39
 
40
 import java.util.ArrayList;
40
 import java.util.ArrayList;
41
 import java.util.Collection;
41
 import java.util.Collection;
45
 import javax.inject.Inject;
45
 import javax.inject.Inject;
46
 import javax.inject.Singleton;
46
 import javax.inject.Singleton;
47
 
47
 
48
+import autovalue.shaded.com.google.common.common.collect.Maps;
48
 import net.engio.mbassy.listener.Handler;
49
 import net.engio.mbassy.listener.Handler;
49
 
50
 
50
 /**
51
 /**
82
 
83
 
83
     @Handler
84
     @Handler
84
     public void handleChannelNames(final ChannelGotnamesEvent event) {
85
     public void handleChannelNames(final ChannelGotnamesEvent event) {
85
-        final ChannelInfo chanInfo = event.getChannel().getChannelInfo();
86
         final String network = event.getChannel().getConnection().get().getNetwork();
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
     @Handler
90
     @Handler
102
      * @param network The network to use for the colouring
99
      * @param network The network to use for the colouring
103
      * @param client  The client to be coloured
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
             final Colour color = colourManager.getColourFromString(owncolour, null);
112
             final Colour color = colourManager.getColourFromString(owncolour, null);
118
             putColour(map, color, color);
113
             putColour(map, color, color);
119
         } else if (userandomcolour) {
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
         String[] parts = null;
118
         String[] parts = null;

+ 4
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/components/NicklistComparator.java View File

57
     public int compare(final GroupChatUser client1, final GroupChatUser client2) {
57
     public int compare(final GroupChatUser client1, final GroupChatUser client2) {
58
         ComparisonChain comparisonChain = ComparisonChain.start();
58
         ComparisonChain comparisonChain = ComparisonChain.start();
59
         if (sortByMode) {
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
         if (sortByCase) {
63
         if (sortByCase) {
64
             comparisonChain = comparisonChain.compare(client1.getNickname(), client2.getNickname());
64
             comparisonChain = comparisonChain.compare(client1.getNickname(), client2.getNickname());
65
         } else {
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
         return comparisonChain.result();
69
         return comparisonChain.result();
71
     }
70
     }

+ 3
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java View File

31
 import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
31
 import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
32
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
32
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
33
 import com.dmdirc.interfaces.CommandController;
33
 import com.dmdirc.interfaces.CommandController;
34
+import com.dmdirc.interfaces.GroupChatUser;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35
 import com.dmdirc.interfaces.ui.InputWindow;
36
 import com.dmdirc.interfaces.ui.InputWindow;
36
 import com.dmdirc.plugins.ServiceManager;
37
 import com.dmdirc.plugins.ServiceManager;
166
      */
167
      */
167
     public void setTopic(final Optional<Topic> topic) {
168
     public void setTopic(final Optional<Topic> topic) {
168
         if (topic.isPresent()) {
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
                     + "<br> on " + new Date(1000 * topic.get().getTime()));
172
                     + "<br> on " + new Date(1000 * topic.get().getTime()));
171
             topicText.setText(topic.get().getTopic());
173
             topicText.setText(topic.get().getTopic());
172
         } else {
174
         } else {

+ 5
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java View File

26
 import com.dmdirc.Topic;
26
 import com.dmdirc.Topic;
27
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28
 import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
28
 import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
29
+import com.dmdirc.interfaces.GroupChatUser;
29
 
30
 
30
 import java.awt.Color;
31
 import java.awt.Color;
31
 import java.util.Date;
32
 import java.util.Date;
130
 
131
 
131
         TextLabel label;
132
         TextLabel label;
132
         if (topic.getTopic().isEmpty()) {
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
         } else {
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
         add(label, "wmax 450, grow, push, wrap, gapleft 5, pad 0");
140
         add(label, "wmax 450, grow, push, wrap, gapleft 5, pad 0");
138
 
141
 

Loading…
Cancel
Save