Ver código fonte

Use new whois event from parser.

pull/565/head
Greg Holmes 9 anos atrás
pai
commit
a8242ee8c4

+ 9
- 0
src/com/dmdirc/ServerEventHandler.java Ver arquivo

@@ -52,6 +52,7 @@ import com.dmdirc.events.ServerWallopsEvent;
52 52
 import com.dmdirc.events.ServerWallusersEvent;
53 53
 import com.dmdirc.events.StatusBarMessageEvent;
54 54
 import com.dmdirc.events.UserErrorEvent;
55
+import com.dmdirc.events.UserInfoResponseEvent;
55 56
 import com.dmdirc.interfaces.Connection;
56 57
 import com.dmdirc.logger.ErrorLevel;
57 58
 import com.dmdirc.parser.common.AwayState;
@@ -81,6 +82,7 @@ import com.dmdirc.parser.events.SocketCloseEvent;
81 82
 import com.dmdirc.parser.events.UnknownActionEvent;
82 83
 import com.dmdirc.parser.events.UnknownMessageEvent;
83 84
 import com.dmdirc.parser.events.UnknownNoticeEvent;
85
+import com.dmdirc.parser.events.UserInfoEvent;
84 86
 import com.dmdirc.parser.events.UserModeChangeEvent;
85 87
 import com.dmdirc.parser.events.UserModeDiscoveryEvent;
86 88
 import com.dmdirc.parser.events.WallDesyncEvent;
@@ -161,6 +163,13 @@ public class ServerEventHandler extends EventHandler {
161 163
         }
162 164
     }
163 165
 
166
+    @Handler
167
+    public void onWhoisEvent(final UserInfoEvent event) {
168
+        checkParser(event.getParser());
169
+        eventBus.publishAsync(new UserInfoResponseEvent(owner, event.getDate().getTime(),
170
+                owner.getUser(event.getClient().getNickname()), event.getInfo()));
171
+    }
172
+
164 173
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
165 174
     @Handler
166 175
     public void onErrorInfo(final ParserErrorEvent event) {

+ 67
- 0
src/com/dmdirc/events/UserInfoResponseEvent.java Ver arquivo

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.events;
24
+
25
+import com.dmdirc.interfaces.Connection;
26
+import com.dmdirc.interfaces.User;
27
+import com.dmdirc.parser.events.UserInfoEvent;
28
+
29
+import java.util.EnumMap;
30
+import java.util.Map;
31
+import java.util.Optional;
32
+
33
+/**
34
+ * Event raised when detailed user info has been received for a user.
35
+ */
36
+public class UserInfoResponseEvent extends ServerEvent {
37
+
38
+    private final User user;
39
+    private final Map<UserInfoEvent.UserInfoType, String> info;
40
+
41
+    public UserInfoResponseEvent(final Connection connection, final long date,
42
+            final User user, final Map<UserInfoEvent.UserInfoType, String> info) {
43
+        super(date, connection);
44
+        this.user = user;
45
+        this.info = new EnumMap<>(info);
46
+    }
47
+
48
+    /**
49
+     * Gets the client that the event is for.
50
+     *
51
+     * @return The user this event is for.
52
+     */
53
+    public User getUser() {
54
+        return user;
55
+    }
56
+
57
+    /**
58
+     * Gets a specific piece of information about the user.
59
+     *
60
+     * @param type The type of information to return.
61
+     *
62
+     * @return An optional containing the information, if it was provided.
63
+     */
64
+    public Optional<String> getInfo(final UserInfoEvent.UserInfoType type) {
65
+        return Optional.ofNullable(info.get(type));
66
+    }
67
+}

Carregando…
Cancelar
Salvar