Browse Source

Merge pull request #375 from greboid/dev4

People can be on more than one channel, allow for this in channel who.
pull/378/head
Chris Smith 9 years ago
parent
commit
d79c4b5fa0
1 changed files with 13 additions and 15 deletions
  1. 13
    15
      channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java

+ 13
- 15
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java View File

@@ -34,9 +34,9 @@ import com.dmdirc.interfaces.GroupChatUser;
34 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35 35
 
36 36
 import com.google.common.annotations.VisibleForTesting;
37
+import com.google.common.collect.HashMultimap;
38
+import com.google.common.collect.Multimap;
37 39
 
38
-import java.util.HashMap;
39
-import java.util.Map;
40 40
 import java.util.Optional;
41 41
 import java.util.concurrent.ScheduledExecutorService;
42 42
 import java.util.concurrent.ScheduledFuture;
@@ -50,13 +50,12 @@ import net.engio.mbassy.listener.Handler;
50 50
  */
51 51
 public class ConnectionHandler {
52 52
 
53
-    private final Map<String, GroupChatUser> users;
53
+    private final Multimap<String, GroupChatUser> users;
54 54
     private final Connection connection;
55 55
     private final String domain;
56 56
     private final ScheduledExecutorService executorService;
57 57
     private final ConnectionManager connectionManager;
58 58
     private final ConfigBinder configBinder;
59
-    private int whoInterval;
60 59
     private ScheduledFuture<?> future;
61 60
 
62 61
     public ConnectionHandler(
@@ -69,7 +68,7 @@ public class ConnectionHandler {
69 68
         this.executorService = executorService;
70 69
         this.connectionManager = connectionManager;
71 70
         configBinder = config.getBinder().withDefaultDomain(domain);
72
-        users = new HashMap<>();
71
+        users = HashMultimap.create();
73 72
     }
74 73
 
75 74
     public void load() {
@@ -99,11 +98,10 @@ public class ConnectionHandler {
99 98
     @VisibleForTesting
100 99
     @ConfigBinding(key="whoInterval")
101 100
     void handleWhoInterval(final int value) {
102
-        whoInterval = value;
103 101
         if (future != null) {
104 102
             future.cancel(true);
105 103
         }
106
-        future = executorService.schedule(this::checkWho, whoInterval, TimeUnit.MILLISECONDS);
104
+        future = executorService.schedule(this::checkWho, value, TimeUnit.MILLISECONDS);
107 105
     }
108 106
 
109 107
     @VisibleForTesting
@@ -111,9 +109,12 @@ public class ConnectionHandler {
111 109
     void handleAwayEvent(final ChannelUserAwayEvent event) {
112 110
         if (!event.getReason().isPresent()) {
113 111
             event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
112
+            final boolean notseen = !users.containsKey(event.getUser().getNickname());
114 113
             users.put(event.getUser().getNickname(), event.getUser());
115
-            event.getChannel().getConnection()
116
-                    .ifPresent(c -> c.requestUserInfo(event.getUser().getUser()));
114
+            if (notseen) {
115
+                event.getChannel().getConnection()
116
+                        .ifPresent(c -> c.requestUserInfo(event.getUser().getUser()));
117
+            }
117 118
         }
118 119
     }
119 120
 
@@ -123,12 +124,9 @@ public class ConnectionHandler {
123 124
         if (event.getNumeric() == 301) {
124 125
             final String nickname = event.getArgs()[4];
125 126
             final String reason = event.getArgs()[5];
126
-            final GroupChatUser user = users.remove(nickname);
127
-            if (user != null) {
128
-                connection.getWindowModel().getEventBus().publishAsync(
129
-                        new ChannelUserAwayEvent(user.getGroupChat(), user,
130
-                                Optional.ofNullable(reason)));
131
-            }
127
+            users.removeAll(nickname).forEach(u -> connection.getWindowModel().getEventBus()
128
+                    .publishAsync(new ChannelUserAwayEvent(u.getGroupChat(), u,
129
+                            Optional.ofNullable(reason))));
132 130
         }
133 131
     }
134 132
 }

Loading…
Cancel
Save