Ver código fonte

Switch topics over to events, fix lots of bugs in the events.

pull/340/head
Greg Holmes 9 anos atrás
pai
commit
ba464023fa

+ 12
- 4
res/com/dmdirc/ui/messages/format.yml Ver arquivo

@@ -15,13 +15,22 @@ ChannelSelfMessageEvent:
15 15
 ChannelSelfActionEvent:
16 16
   format: "* {{client.modePrefixedNickname}} {{message}}"
17 17
   colour: 6
18
+ChannelGottopicEvent:
19
+  format: "* The topic for {{channel.name}} is '{{topic.topic}}'.\nTopic was set by {{user.nickname}} at {{topic.time}}."
20
+  colour: 3
21
+ChannelTopicChangeEvent:
22
+  format: "* {{user.nickname}} has changed the topic to  {{topic.topic}}."
23
+  colour: 3
24
+ChannelNotopicEvent:
25
+  format: "* There is no topic set for {{channel.name}}."
26
+  colour: 3
27
+ChannelTopicUnsetEvent:
28
+  format: "* {{client.modePrefixedNickname}} has removed the topic on {{channel.name}}."
29
+  colour: 3
18 30
 
19 31
 # TODO:
20
-#  channelTopicChanged=3* %1$s%2$s has changed the topic to '%5$s'.
21
-#  channelTopicRemoved=3* %1$s%2$s has removed the topic on %6$s.
22 32
 #  channelModeChanged=3* %1$s%2$s sets mode: %5$s.
23 33
 #  channelSelfModeChanged=3* You set mode: %5$s.
24
-#  channelTopicDiscovered=3* The topic for %7$s is '%5$s'.\n3* Topic was set by %2$s at %6$tR on %6$tA, %6$tB %6$te %6$tY.
25 34
 #  channelCTCP=4-!- CTCP %5$S from %1$s%2$s
26 35
 #  channelPart=3* %1$s%2$s (%3$s@%4$s) has left %6$s.
27 36
 #  channelPartReason=3* %1$s%2$s (%3$s@%4$s) has left %6$s (%5$s).
@@ -75,7 +84,6 @@ ChannelSelfActionEvent:
75 84
 #  serverConnectInProgress=A connection attempt is in progress, please wait...
76 85
 #  authNotice=5-AUTH- %1$s
77 86
 #  away=14You are now marked as away (%1$s14).
78
-#  channelNoTopic=3* There is no topic set for %1$s.
79 87
 #  rawCommand=10>>> %1$s
80 88
 #  unknownCommand=14Unknown command %1$s.
81 89
 #  socketClosed=2-!- You have been disconnected from the server.

+ 0
- 3
src/com/dmdirc/Channel.java Ver arquivo

@@ -28,7 +28,6 @@ import com.dmdirc.config.ConfigBinding;
28 28
 import com.dmdirc.events.ChannelClosedEvent;
29 29
 import com.dmdirc.events.ChannelSelfActionEvent;
30 30
 import com.dmdirc.events.ChannelSelfMessageEvent;
31
-import com.dmdirc.events.ChannelTopicChangeEvent;
32 31
 import com.dmdirc.events.DisplayProperty;
33 32
 import com.dmdirc.events.NickListClientAddedEvent;
34 33
 import com.dmdirc.events.NickListClientRemovedEvent;
@@ -485,8 +484,6 @@ public class Channel extends MessageTarget implements GroupChat {
485 484
             topics.add(topic);
486 485
         }
487 486
         updateTitle();
488
-
489
-        getEventBus().publishAsync(new ChannelTopicChangeEvent(this, topic));
490 487
     }
491 488
 
492 489
     @Override

+ 9
- 19
src/com/dmdirc/ChannelEventHandler.java Ver arquivo

@@ -24,7 +24,6 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.events.ChannelActionEvent;
26 26
 import com.dmdirc.events.ChannelCtcpEvent;
27
-import com.dmdirc.events.ChannelDisplayableEvent;
28 27
 import com.dmdirc.events.ChannelGotnamesEvent;
29 28
 import com.dmdirc.events.ChannelGottopicEvent;
30 29
 import com.dmdirc.events.ChannelJoinEvent;
@@ -167,30 +166,21 @@ public class ChannelEventHandler extends EventHandler implements
167 166
 
168 167
         if (isJoinTopic) {
169 168
             if (Strings.isNullOrEmpty(channel.getTopic())) {
170
-                final ChannelNotopicEvent event = new ChannelNotopicEvent(owner);
171
-                final String format = EventUtils.postDisplayable(eventBus, event, "channelNoTopic");
172
-                owner.doNotification(date, format);
169
+                eventBus.publishAsync(new ChannelNotopicEvent(owner));
173 170
             } else {
174
-                final ChannelGottopicEvent event = new ChannelGottopicEvent(owner, topic);
175
-                final String format = EventUtils.postDisplayable(eventBus, event,
176
-                        "channelTopicDiscovered");
177
-                owner.doNotification(date, format, topic);
171
+                eventBus.publishAsync(new ChannelGottopicEvent(owner, topic,
172
+                        owner.getConnection().get().getUser(channel.getTopicSetter())));
178 173
             }
179 174
         } else {
180
-            final ChannelDisplayableEvent event;
181
-            final String format;
182 175
             if (Strings.isNullOrEmpty(channel.getTopic())) {
183
-                event = new ChannelTopicChangeEvent(date.getTime(), owner, topic);
184
-                format = EventUtils.postDisplayable(eventBus, event,
185
-                        "channelTopicRemoved");
186
-            } else {
187
-                event = new ChannelTopicUnsetEvent(date.getTime(), owner,
176
+                eventBus.publishAsync(new ChannelTopicUnsetEvent(date.getTime(), owner,
188 177
                         owner.getUser(owner.getConnection().get()
189
-                                .getUser(channel.getTopicSetter())).orElse(null));
190
-                format = EventUtils.postDisplayable(eventBus, event, "channelTopicChanged");
178
+                                .getUser(channel.getTopicSetter())).orElse(null)));
179
+            } else {
180
+                eventBus.publishAsync(new ChannelTopicChangeEvent(date.getTime(), owner, topic,
181
+                        topic.getClient().get()));
182
+
191 183
             }
192
-            owner.doNotification(date, format, channel.getChannelClient(channel.getTopicSetter(),
193
-                    true), channel.getTopic());
194 184
         }
195 185
 
196 186
         final Optional<Topic> currentTopic = owner.getCurrentTopic();

+ 12
- 2
src/com/dmdirc/events/ChannelGottopicEvent.java Ver arquivo

@@ -24,6 +24,7 @@ package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.Topic;
27
+import com.dmdirc.interfaces.User;
27 28
 
28 29
 /**
29 30
  * Fired when a channel topic is changed.
@@ -31,19 +32,28 @@ import com.dmdirc.Topic;
31 32
 public class ChannelGottopicEvent extends ChannelDisplayableEvent {
32 33
 
33 34
     private final Topic topic;
35
+    private final User user;
34 36
 
35
-    public ChannelGottopicEvent(final long timestamp, final Channel channel, final Topic topic) {
37
+    public ChannelGottopicEvent(final long timestamp, final Channel channel, final Topic topic,
38
+            final User user) {
36 39
         super(timestamp, channel);
37 40
         this.topic = topic;
41
+        this.user = user;
38 42
     }
39 43
 
40
-    public ChannelGottopicEvent(final Channel channel, final Topic topic) {
44
+    public ChannelGottopicEvent(final Channel channel, final Topic topic,
45
+            final User user) {
41 46
         super(channel);
42 47
         this.topic = topic;
48
+        this.user = user;
43 49
     }
44 50
 
45 51
     public Topic getTopic() {
46 52
         return topic;
47 53
     }
48 54
 
55
+    public User getUser() {
56
+        return user;
57
+    }
58
+
49 59
 }

+ 11
- 2
src/com/dmdirc/events/ChannelTopicChangeEvent.java Ver arquivo

@@ -24,6 +24,7 @@ package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.Topic;
27
+import com.dmdirc.interfaces.GroupChatUser;
27 28
 
28 29
 /**
29 30
  * Fired when a topic is changed.
@@ -31,20 +32,28 @@ import com.dmdirc.Topic;
31 32
 public class ChannelTopicChangeEvent extends ChannelDisplayableEvent {
32 33
 
33 34
     private final Topic topic;
35
+    private final GroupChatUser user;
34 36
 
35 37
     public ChannelTopicChangeEvent(final long timestamp, final Channel channel,
36
-            final Topic topic) {
38
+            final Topic topic, final GroupChatUser user) {
37 39
         super(timestamp, channel);
38 40
         this.topic = topic;
41
+        this.user = user;
39 42
     }
40 43
 
41
-    public ChannelTopicChangeEvent(final Channel channel, final Topic topic) {
44
+    public ChannelTopicChangeEvent(final Channel channel, final Topic topic,
45
+            final GroupChatUser user) {
42 46
         super(channel);
43 47
         this.topic = topic;
48
+        this.user = user;
44 49
     }
45 50
 
46 51
     public Topic getTopic() {
47 52
         return topic;
48 53
     }
49 54
 
55
+    public GroupChatUser getUser() {
56
+        return user;
57
+    }
58
+
50 59
 }

+ 2
- 0
src/com/dmdirc/ui/messages/EventPropertyManager.java Ver arquivo

@@ -56,6 +56,8 @@ public class EventPropertyManager {
56 56
                 + property.substring(1);
57 57
         try {
58 58
             final Method method = type.getMethod(methodName);
59
+            // TODO: This is needed for AutoValues, should probably get return types not real types
60
+            method.setAccessible(true);
59 61
             return Optional.ofNullable(method.invoke(object));
60 62
         } catch (ReflectiveOperationException ex) {
61 63
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, ex,

Carregando…
Cancelar
Salvar