Ver código fonte

Use GroupChatUser some more.

pull/289/head
Greg Holmes 9 anos atrás
pai
commit
d88a183d9c

+ 13
- 9
src/com/dmdirc/Channel.java Ver arquivo

@@ -292,7 +292,7 @@ public class Channel extends MessageTarget implements GroupChat {
292 292
         setIcon("channel-inactive");
293 293
 
294 294
         getEventBus().publishAsync(new NickListClientsChangedEvent(this,
295
-                Collections.<ChannelClientInfo>emptyList()));
295
+                Collections.<GroupChatUser>emptyList()));
296 296
     }
297 297
 
298 298
     @Override
@@ -332,11 +332,10 @@ public class Channel extends MessageTarget implements GroupChat {
332 332
      *
333 333
      * @param client The client to be added
334 334
      */
335
-    public void addClient(final ChannelClientInfo client) {
335
+    public void addClient(final GroupChatUser client) {
336 336
         getEventBus().publishAsync(new NickListClientAddedEvent(this, client));
337 337
 
338
-        getTabCompleter().addEntry(TabCompletionType.CHANNEL_NICK,
339
-                client.getClient().getNickname());
338
+        getTabCompleter().addEntry(TabCompletionType.CHANNEL_NICK, client.getNickname());
340 339
     }
341 340
 
342 341
     /**
@@ -344,13 +343,13 @@ public class Channel extends MessageTarget implements GroupChat {
344 343
      *
345 344
      * @param client The client to be removed
346 345
      */
347
-    public void removeClient(final ChannelClientInfo client) {
346
+    public void removeClient(final GroupChatUser client) {
348 347
         getEventBus().publishAsync(new NickListClientRemovedEvent(this, client));
349 348
 
350 349
         getTabCompleter().removeEntry(TabCompletionType.CHANNEL_NICK,
351
-                client.getClient().getNickname());
350
+                client.getNickname());
352 351
 
353
-        if (client.getClient().equals(server.getParser().get().getLocalClient())) {
352
+        if (client.getUser().equals(server.getLocalUser())) {
354 353
             resetWindow();
355 354
         }
356 355
     }
@@ -360,13 +359,13 @@ public class Channel extends MessageTarget implements GroupChat {
360 359
      *
361 360
      * @param clients The list of clients to use
362 361
      */
363
-    public void setClients(final Collection<ChannelClientInfo> clients) {
362
+    public void setClients(final Collection<GroupChatUser> clients) {
364 363
         getEventBus().publishAsync(new NickListClientsChangedEvent(this, clients));
365 364
 
366 365
         getTabCompleter().clear(TabCompletionType.CHANNEL_NICK);
367 366
 
368 367
         getTabCompleter().addEntries(TabCompletionType.CHANNEL_NICK,
369
-            clients.stream().map(c -> c.getClient().getNickname()).collect(Collectors.toList()));
368
+            clients.stream().map(GroupChatUser::getNickname).collect(Collectors.toList()));
370 369
     }
371 370
 
372 371
     /**
@@ -549,4 +548,9 @@ public class Channel extends MessageTarget implements GroupChat {
549 548
         return groupChatUserFactory.getGroupChatUser(user, this);
550 549
     }
551 550
 
551
+    public Collection<GroupChatUser> getUsers() {
552
+        return channelInfo.getChannelClients().stream().map(this::getUserFromClient)
553
+                .collect(Collectors.toList());
554
+    }
555
+
552 556
 }

+ 11
- 8
src/com/dmdirc/ChannelEventHandler.java Ver arquivo

@@ -76,6 +76,7 @@ import com.google.common.base.Strings;
76 76
 
77 77
 import java.util.Date;
78 78
 import java.util.Optional;
79
+import java.util.stream.Collectors;
79 80
 
80 81
 import javax.annotation.Nonnull;
81 82
 
@@ -148,7 +149,9 @@ public class ChannelEventHandler extends EventHandler implements
148 149
     public void onChannelGotNames(final Parser parser, final Date date, final ChannelInfo channel) {
149 150
         checkParser(parser);
150 151
 
151
-        owner.setClients(channel.getChannelClients());
152
+        owner.setClients(channel.getChannelClients().stream()
153
+                .map(owner::getUserFromClient)
154
+                .collect(Collectors.toList()));
152 155
         eventBus.publishAsync(new ChannelGotnamesEvent(owner));
153 156
     }
154 157
 
@@ -192,9 +195,9 @@ public class ChannelEventHandler extends EventHandler implements
192 195
         final Optional<Topic> currentTopic = owner.getCurrentTopic();
193 196
         final boolean hasNewTopic = !Strings.isNullOrEmpty(channel.getTopic());
194 197
         if (!isJoinTopic
195
-                || (!currentTopic.isPresent() && hasNewTopic)
196
-                || (currentTopic.isPresent() && !channel.getTopic().equals(
197
-                        owner.getCurrentTopic().get().getTopic()))) {
198
+                || !currentTopic.isPresent() && hasNewTopic
199
+                || currentTopic.isPresent() && !channel.getTopic().equals(
200
+                        owner.getCurrentTopic().get().getTopic())) {
198 201
             // Only add the topic if:
199 202
             //  - It's being set while we're in the channel (rather than discovered on join), or
200 203
             //  - We think the current topic is empty and are discovering a new one, or
@@ -211,7 +214,7 @@ public class ChannelEventHandler extends EventHandler implements
211 214
         final ChannelJoinEvent event = new ChannelJoinEvent(owner, client);
212 215
         final String format = EventUtils.postDisplayable(eventBus, event, "channelJoin");
213 216
         owner.doNotification(date, format, client);
214
-        owner.addClient(client);
217
+        owner.addClient(owner.getUserFromClient(client));
215 218
     }
216 219
 
217 220
     @Override
@@ -225,7 +228,7 @@ public class ChannelEventHandler extends EventHandler implements
225 228
                 + (isMyself(client) ? "Self" : "") + "Part"
226 229
                 + (reason.isEmpty() ? "" : "Reason"));
227 230
         owner.doNotification(date, format, client, reason);
228
-        owner.removeClient(client);
231
+        owner.removeClient(owner.getUserFromClient(client));
229 232
     }
230 233
 
231 234
     @Override
@@ -238,7 +241,7 @@ public class ChannelEventHandler extends EventHandler implements
238 241
         final String format = EventUtils.postDisplayable(eventBus, event,
239 242
                 "channelKick" + (reason.isEmpty() ? "" : "Reason"));
240 243
         owner.doNotification(date, format, client, kickedClient, reason);
241
-        owner.removeClient(kickedClient);
244
+        owner.removeClient(owner.getUserFromClient(kickedClient));
242 245
     }
243 246
 
244 247
     @Override
@@ -250,7 +253,7 @@ public class ChannelEventHandler extends EventHandler implements
250 253
         final String format = EventUtils.postDisplayable(eventBus, event,
251 254
                 "channelQuit" + (reason.isEmpty() ? "" : "Reason"));
252 255
         owner.doNotification(date, format, client, reason);
253
-        owner.removeClient(client);
256
+        owner.removeClient(owner.getUserFromClient(client));
254 257
     }
255 258
 
256 259
     @Override

+ 5
- 5
src/com/dmdirc/events/NickListClientAddedEvent.java Ver arquivo

@@ -23,27 +23,27 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired when a user is added to the list of users.
30 30
  */
31 31
 public class NickListClientAddedEvent extends NickListEvent {
32 32
 
33
-    private final ChannelClientInfo user;
33
+    private final GroupChatUser user;
34 34
 
35 35
     public NickListClientAddedEvent(final long timestamp, final Channel channel,
36
-            final ChannelClientInfo user) {
36
+            final GroupChatUser user) {
37 37
         super(timestamp, channel);
38 38
         this.user = user;
39 39
     }
40 40
 
41
-    public NickListClientAddedEvent(final Channel channel, final ChannelClientInfo user) {
41
+    public NickListClientAddedEvent(final Channel channel, final GroupChatUser user) {
42 42
         super(channel);
43 43
         this.user = user;
44 44
     }
45 45
 
46
-    public ChannelClientInfo getUser() {
46
+    public GroupChatUser getUser() {
47 47
         return user;
48 48
     }
49 49
 }

+ 5
- 5
src/com/dmdirc/events/NickListClientRemovedEvent.java Ver arquivo

@@ -23,27 +23,27 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 /**
29 29
  * Fired when a user is removed from the list of users.
30 30
  */
31 31
 public class NickListClientRemovedEvent extends NickListEvent {
32 32
 
33
-    private final ChannelClientInfo user;
33
+    private final GroupChatUser user;
34 34
 
35 35
     public NickListClientRemovedEvent(final long timestamp, final Channel channel,
36
-            final ChannelClientInfo user) {
36
+            final GroupChatUser user) {
37 37
         super(timestamp, channel);
38 38
         this.user = user;
39 39
     }
40 40
 
41
-    public NickListClientRemovedEvent(final Channel channel, final ChannelClientInfo user) {
41
+    public NickListClientRemovedEvent(final Channel channel, final GroupChatUser user) {
42 42
         super(channel);
43 43
         this.user = user;
44 44
     }
45 45
 
46
-    public ChannelClientInfo getUser() {
46
+    public GroupChatUser getUser() {
47 47
         return user;
48 48
     }
49 49
 }

+ 5
- 5
src/com/dmdirc/events/NickListClientsChangedEvent.java Ver arquivo

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.interfaces.GroupChatUser;
27 27
 
28 28
 import com.google.common.collect.Lists;
29 29
 
@@ -35,21 +35,21 @@ import java.util.Collections;
35 35
  */
36 36
 public class NickListClientsChangedEvent extends NickListEvent {
37 37
 
38
-    private final Collection<ChannelClientInfo> users;
38
+    private final Collection<GroupChatUser> users;
39 39
 
40 40
     public NickListClientsChangedEvent(final long timestamp, final Channel channel,
41
-            final Iterable<ChannelClientInfo> users) {
41
+            final Iterable<GroupChatUser> users) {
42 42
         super(timestamp, channel);
43 43
         this.users = Lists.newArrayList(users);
44 44
     }
45 45
 
46 46
     public NickListClientsChangedEvent(final Channel channel,
47
-            final Iterable<ChannelClientInfo> users) {
47
+            final Iterable<GroupChatUser> users) {
48 48
         super(channel);
49 49
         this.users = Lists.newArrayList(users);
50 50
     }
51 51
 
52
-    public Collection<ChannelClientInfo> getUsers() {
52
+    public Collection<GroupChatUser> getUsers() {
53 53
         return Collections.unmodifiableCollection(users);
54 54
     }
55 55
 }

Carregando…
Cancelar
Salvar