瀏覽代碼

Remove TopicChangeListener. Add Topic to topic events.

pull/287/head
Greg Holmes 9 年之前
父節點
當前提交
2ee996a75e

+ 2
- 14
src/com/dmdirc/Channel.java 查看文件

@@ -28,6 +28,7 @@ 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;
31 32
 import com.dmdirc.events.DisplayProperty;
32 33
 import com.dmdirc.events.NickListClientAddedEvent;
33 34
 import com.dmdirc.events.NickListClientRemovedEvent;
@@ -37,7 +38,6 @@ import com.dmdirc.interfaces.CommandController;
37 38
 import com.dmdirc.interfaces.Connection;
38 39
 import com.dmdirc.interfaces.GroupChat;
39 40
 import com.dmdirc.interfaces.GroupChatUser;
40
-import com.dmdirc.interfaces.TopicChangeListener;
41 41
 import com.dmdirc.interfaces.User;
42 42
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
43 43
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
@@ -502,9 +502,7 @@ public class Channel extends MessageTarget implements GroupChat {
502 502
         }
503 503
         updateTitle();
504 504
 
505
-        new Thread(
506
-                () -> listenerList.getCallable(TopicChangeListener.class).topicChanged(this, topic),
507
-                "Topic change listener runner").start();
505
+        getEventBus().publishAsync(new ChannelTopicChangeEvent(this, topic));
508 506
     }
509 507
 
510 508
     @Override
@@ -536,16 +534,6 @@ public class Channel extends MessageTarget implements GroupChat {
536 534
         return server.getParser().get().getMaxTopicLength();
537 535
     }
538 536
 
539
-    @Override
540
-    public void addTopicChangeListener(final TopicChangeListener listener) {
541
-        listenerList.add(TopicChangeListener.class, listener);
542
-    }
543
-
544
-    @Override
545
-    public void removeTopicChangeListener(final TopicChangeListener listener) {
546
-        listenerList.remove(TopicChangeListener.class, listener);
547
-    }
548
-
549 537
     @Override
550 538
     public Optional<Connection> getConnection() {
551 539
         return Optional.of(server);

+ 8
- 11
src/com/dmdirc/ChannelEventHandler.java 查看文件

@@ -157,27 +157,26 @@ public class ChannelEventHandler extends EventHandler implements
157 157
             final ChannelInfo channel, final boolean isJoinTopic) {
158 158
         checkParser(parser);
159 159
 
160
+        final Topic topic = new Topic(channel.getTopic(),
161
+                owner.getUser(getConnection().getUser(channel.getTopicSetter())),
162
+                channel.getTopicTime());
163
+
160 164
         if (isJoinTopic) {
161 165
             if (Strings.isNullOrEmpty(channel.getTopic())) {
162 166
                 final ChannelNotopicEvent event = new ChannelNotopicEvent(owner);
163 167
                 final String format = EventUtils.postDisplayable(eventBus, event, "channelNoTopic");
164 168
                 owner.doNotification(date, format);
165 169
             } else {
166
-                final Topic newTopic = new Topic(channel.getTopic(),
167
-                        getConnection().getUser(channel.getTopicSetter()),
168
-                        channel.getTopicTime());
169
-                final ChannelGottopicEvent event = new ChannelGottopicEvent(owner, newTopic);
170
+                final ChannelGottopicEvent event = new ChannelGottopicEvent(owner, topic);
170 171
                 final String format = EventUtils.postDisplayable(eventBus, event,
171 172
                         "channelTopicDiscovered");
172
-                owner.doNotification(date, format, newTopic);
173
+                owner.doNotification(date, format, topic);
173 174
             }
174 175
         } else {
175 176
             final ChannelDisplayableEvent event;
176 177
             final String format;
177 178
             if (Strings.isNullOrEmpty(channel.getTopic())) {
178
-                event = new ChannelTopicChangeEvent(owner,
179
-                        channel.getChannelClient(channel.getTopicSetter(), true),
180
-                        channel.getTopic());
179
+                event = new ChannelTopicChangeEvent(owner, topic);
181 180
                 format = EventUtils.postDisplayable(eventBus, event,
182 181
                         "channelTopicRemoved");
183 182
             } else {
@@ -200,9 +199,7 @@ public class ChannelEventHandler extends EventHandler implements
200 199
             //  - It's being set while we're in the channel (rather than discovered on join), or
201 200
             //  - We think the current topic is empty and are discovering a new one, or
202 201
             //  - The newly discovered topic is different to what we thought the current topic was.
203
-            owner.addTopic(new Topic(channel.getTopic(),
204
-                    getConnection().getUser(channel.getTopicSetter()),
205
-                    channel.getTopicTime()));
202
+            owner.addTopic(topic);
206 203
         }
207 204
     }
208 205
 

+ 4
- 4
src/com/dmdirc/Topic.java 查看文件

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.interfaces.User;
25
+import com.dmdirc.interfaces.GroupChatUser;
26 26
 
27 27
 /**
28 28
  * Stores information about a channel topic.
@@ -32,7 +32,7 @@ public class Topic {
32 32
     /** Topic. */
33 33
     private final String topic;
34 34
     /** Topic client. */
35
-    private final User client;
35
+    private final GroupChatUser client;
36 36
     /** Topic time. */
37 37
     private final long time;
38 38
 
@@ -43,7 +43,7 @@ public class Topic {
43 43
      * @param client Topic client
44 44
      * @param time   Topic time
45 45
      */
46
-    public Topic(final String topic, final User client, final long time) {
46
+    public Topic(final String topic, final GroupChatUser client, final long time) {
47 47
         this.topic = topic;
48 48
         this.client = client;
49 49
         this.time = time;
@@ -54,7 +54,7 @@ public class Topic {
54 54
      *
55 55
      * @return client
56 56
      */
57
-    public User getClient() {
57
+    public GroupChatUser getClient() {
58 58
         return client;
59 59
     }
60 60
 

+ 5
- 5
src/com/dmdirc/commandparser/commands/channel/ShowTopic.java 查看文件

@@ -36,7 +36,7 @@ import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
36 36
 import com.dmdirc.commandparser.commands.context.CommandContext;
37 37
 import com.dmdirc.interfaces.CommandController;
38 38
 import com.dmdirc.interfaces.Connection;
39
-import com.dmdirc.interfaces.User;
39
+import com.dmdirc.interfaces.GroupChatUser;
40 40
 
41 41
 import java.util.Optional;
42 42
 
@@ -71,11 +71,11 @@ public class ShowTopic extends Command implements ExternalCommand {
71 71
         if (args.getArguments().length == 0) {
72 72
             final Optional<Topic> topic = channel.getCurrentTopic();
73 73
             if (topic.isPresent()) {
74
-                final Optional<User> user = topic.map(Topic::getClient);
74
+                final Optional<GroupChatUser> user = topic.map(Topic::getClient);
75 75
                 sendLine(origin, args.isSilent(), "channelTopicDiscovered", "",
76
-                        user.map(User::getNickname).orElse(""),
77
-                        user.flatMap(User::getUsername).orElse(""),
78
-                        user.flatMap(User::getHostname).orElse(""),
76
+                        user.map(GroupChatUser::getNickname).orElse(""),
77
+                        user.flatMap(GroupChatUser::getUsername).orElse(""),
78
+                        user.flatMap(GroupChatUser::getHostname).orElse(""),
79 79
                         topic.map(Topic::getTopic).orElse(""),
80 80
                         1000 * topic.map(Topic::getTime).get(),
81 81
                         channel.getName());

+ 5
- 16
src/com/dmdirc/events/ChannelTopicChangeEvent.java 查看文件

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

+ 0
- 14
src/com/dmdirc/interfaces/GroupChat.java 查看文件

@@ -33,13 +33,6 @@ import java.util.Optional;
33 33
  */
34 34
 public interface GroupChat extends Chat {
35 35
 
36
-    /**
37
-     * Adds a topic change listener to this channel.
38
-     *
39
-     * @param listener The listener to notify about topic changes.
40
-     */
41
-    void addTopicChangeListener(final TopicChangeListener listener);
42
-
43 36
     /**
44 37
      * Returns the current topic for this channel.
45 38
      *
@@ -87,13 +80,6 @@ public interface GroupChat extends Chat {
87 80
      */
88 81
     void part(final String reason);
89 82
 
90
-    /**
91
-     * Removes a topic change listener from this channel.
92
-     *
93
-     * @param listener The listener to be removed.
94
-     */
95
-    void removeTopicChangeListener(final TopicChangeListener listener);
96
-
97 83
     /**
98 84
      * Requests all available list modes for this channel.
99 85
      */

+ 0
- 43
src/com/dmdirc/interfaces/TopicChangeListener.java 查看文件

@@ -1,43 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 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.interfaces;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Topic;
27
-
28
-/**
29
- * An interface for objects interested in receiving topic change events from a {@link Channel}.
30
- *
31
- * @since 0.6.3
32
- */
33
-public interface TopicChangeListener {
34
-
35
-    /**
36
-     * Called whenever a topic is changed.
37
-     *
38
-     * @param channel The channel whose topic has been changed
39
-     * @param topic   The new topic of the channel
40
-     */
41
-    void topicChanged(final Channel channel, final Topic topic);
42
-
43
-}

+ 3
- 3
test/com/dmdirc/TopicTest.java 查看文件

@@ -22,20 +22,20 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.interfaces.User;
25
+import com.dmdirc.interfaces.GroupChatUser;
26 26
 
27 27
 import org.junit.Test;
28 28
 import org.junit.runner.RunWith;
29 29
 import org.mockito.Mock;
30 30
 import org.mockito.runners.MockitoJUnitRunner;
31 31
 
32
-import static org.junit.Assert.*;
32
+import static org.junit.Assert.assertEquals;
33 33
 
34 34
 @RunWith(MockitoJUnitRunner.class)
35 35
 public class TopicTest {
36 36
 
37 37
     @Mock
38
-    private User user;
38
+    private GroupChatUser user;
39 39
 
40 40
     @Test
41 41
     public void testGetClient() {

Loading…
取消
儲存