Quellcode durchsuchen

Use new formatter for channel joins.

This, uh, breaks some channels a little. Will fix in a follow-up.

Add support for Optionals in the event property manager.
pull/357/head
Chris Smith vor 9 Jahren
Ursprung
Commit
27c2985176

+ 11
- 2
res/com/dmdirc/ui/messages/format.yml Datei anzeigen

@@ -9,6 +9,17 @@ ServerCtcpReplyEvent:
9 9
   format: "-!- CTCP {{type}} reply from {{user.nickname}}: {{content}}."
10 10
   colour: 4
11 11
 
12
+################## Channel join/part/quit events ###################################################
13
+
14
+ChannelJoinEvent:
15
+  format: >
16
+            * {{client.nickname}} ({{client.username}}@{{client.hostname}})
17
+            has joined {{channel.name}}.
18
+  colour: 3
19
+ChannelSelfJoinEvent:
20
+  format: "* You are now talking in {{channel.name}}."
21
+  colour: 3
22
+
12 23
 ################## Channel message events ##########################################################
13 24
 
14 25
 ChannelActionEvent:
@@ -63,8 +74,6 @@ ChannelSelfModeChangeEvent:
63 74
 #  channelSelfPartReason=3* You have left the channel.
64 75
 #  channelNickChange=3* %1$s%5$s is now known as %2$s.
65 76
 #  channelSelfNickChange=3* You are now known as %2$s.
66
-#  channelJoin=3* %2$s (%3$s@%4$s) has joined %5$s.
67
-#  channelSelfJoin=3* You are now talking in %5$s.
68 77
 #  channelUserAway=14-- %1$s%2$s is now away.
69 78
 #  channelUserBack=14-- %1$s%2$s is now back.
70 79
 #  channelUserAwayDiscovered=14-- %1$s%2$s is away.

+ 2
- 2
src/com/dmdirc/Channel.java Datei anzeigen

@@ -27,6 +27,7 @@ import com.dmdirc.commandparser.parsers.ChannelCommandParser;
27 27
 import com.dmdirc.config.ConfigBinding;
28 28
 import com.dmdirc.events.ChannelClosedEvent;
29 29
 import com.dmdirc.events.ChannelSelfActionEvent;
30
+import com.dmdirc.events.ChannelSelfJoinEvent;
30 31
 import com.dmdirc.events.ChannelSelfMessageEvent;
31 32
 import com.dmdirc.events.DisplayProperty;
32 33
 import com.dmdirc.events.NickListClientAddedEvent;
@@ -224,8 +225,7 @@ public class Channel extends MessageTarget implements GroupChat {
224 225
         isOnChannel = true;
225 226
 
226 227
         final User me = server.getLocalUser().get();
227
-        addLine("channelSelfJoin", "", me.getNickname(), me.getUsername(),
228
-                me.getHostname(), channelInfo.getName());
228
+        getEventBus().publishAsync(new ChannelSelfJoinEvent(this, me));
229 229
 
230 230
         checkWho();
231 231
         setIcon("channel");

+ 2
- 4
src/com/dmdirc/ChannelEventHandler.java Datei anzeigen

@@ -203,10 +203,8 @@ public class ChannelEventHandler extends EventHandler implements
203 203
             final ChannelClientInfo client) {
204 204
         checkParser(parser);
205 205
 
206
-        final ChannelJoinEvent event = new ChannelJoinEvent(date.getTime(), owner,
207
-                groupChatUserManager.getUserFromClient(client, owner));
208
-        final String format = EventUtils.postDisplayable(eventBus, event, "channelJoin");
209
-        owner.doNotification(date, format, groupChatUserManager.getUserFromClient(client, owner));
206
+        eventBus.publish(new ChannelJoinEvent(date.getTime(), owner,
207
+                groupChatUserManager.getUserFromClient(client, owner)));
210 208
         owner.addClient(groupChatUserManager.getUserFromClient(client, owner));
211 209
     }
212 210
 

+ 50
- 0
src/com/dmdirc/events/ChannelSelfJoinEvent.java Datei anzeigen

@@ -0,0 +1,50 @@
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.Channel;
26
+import com.dmdirc.interfaces.User;
27
+
28
+/**
29
+ * Fired when the local user joins a channel.
30
+ */
31
+public class ChannelSelfJoinEvent extends ChannelDisplayableEvent {
32
+
33
+    private final User client;
34
+
35
+    public ChannelSelfJoinEvent(final long timestamp, final Channel channel,
36
+            final User client) {
37
+        super(timestamp, channel);
38
+        this.client = client;
39
+    }
40
+
41
+    public ChannelSelfJoinEvent(final Channel channel, final User client) {
42
+        super(channel);
43
+        this.client = client;
44
+    }
45
+
46
+    public User getClient() {
47
+        return client;
48
+    }
49
+
50
+}

+ 7
- 1
src/com/dmdirc/ui/messages/EventPropertyManager.java Datei anzeigen

@@ -61,7 +61,13 @@ public class EventPropertyManager {
61 61
             final Method method = type.getMethod(methodName);
62 62
             // TODO: This is needed for AutoValues, should probably get return types not real types
63 63
             method.setAccessible(true);
64
-            return Optional.ofNullable(method.invoke(object));
64
+            final Object result = method.invoke(object);
65
+
66
+            if (result instanceof Optional<?>) {
67
+                return Optional.ofNullable(((Optional<?>) result).orElse(null));
68
+            }
69
+
70
+            return Optional.ofNullable(result);
65 71
         } catch (ReflectiveOperationException ex) {
66 72
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
67 73
                     "Unable to format event: could not retrieve property " + property,

Laden…
Abbrechen
Speichern