Ver código fonte

Use User in Topic.

pull/257/head
Chris Smith 9 anos atrás
pai
commit
0e26372a5c

+ 6
- 4
src/com/dmdirc/Channel.java Ver arquivo

@@ -461,11 +461,13 @@ public class Channel extends MessageTarget implements GroupChat {
461 461
             return true;
462 462
         } else if (arg instanceof Topic) {
463 463
             // Format topics
464
-
464
+            final Topic topic = (Topic) arg;
465 465
             args.add("");
466
-            args.addAll(Arrays.asList(server.parseHostmask(((Topic) arg).getClient())));
467
-            args.add(((Topic) arg).getTopic());
468
-            args.add(((Topic) arg).getTime() * 1000);
466
+            args.add(topic.getClient().getNickname());
467
+            args.add(topic.getClient().getUsername().orElse(""));
468
+            args.add(topic.getClient().getHostname().orElse(""));
469
+            args.add(topic.getTopic());
470
+            args.add(topic.getTime() * 1000);
469 471
 
470 472
             return true;
471 473
         } else {

+ 4
- 2
src/com/dmdirc/ChannelEventHandler.java Ver arquivo

@@ -160,7 +160,8 @@ public class ChannelEventHandler extends EventHandler implements
160 160
                 final String format = EventUtils.postDisplayable(eventBus, event, "channelNoTopic");
161 161
                 owner.doNotification(date, format);
162 162
             } else {
163
-                final Topic newTopic = new Topic(channel.getTopic(), channel.getTopicSetter(),
163
+                final Topic newTopic = new Topic(channel.getTopic(),
164
+                        getConnection().getUser(channel.getTopicSetter()).orElse(null),
164 165
                         channel.getTopicTime());
165 166
                 final ChannelGottopicEvent event = new ChannelGottopicEvent(owner, newTopic);
166 167
                 final String format = EventUtils.postDisplayable(eventBus, event,
@@ -189,7 +190,8 @@ public class ChannelEventHandler extends EventHandler implements
189 190
             //  - It's being set while we're in the channel (rather than discovered on join), or
190 191
             //  - We think the current topic is empty and are discovering a new one, or
191 192
             //  - The newly discovered topic is different to what we thought the current topic was.
192
-            owner.addTopic(new Topic(channel.getTopic(), channel.getTopicSetter(),
193
+            owner.addTopic(new Topic(channel.getTopic(),
194
+                    getConnection().getUser(channel.getTopicSetter()).orElse(null),
193 195
                     channel.getTopicTime()));
194 196
         }
195 197
     }

+ 6
- 4
src/com/dmdirc/Topic.java Ver arquivo

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.interfaces.User;
26
+
25 27
 /**
26 28
  * Stores information about a channel topic.
27 29
  */
@@ -30,7 +32,7 @@ public class Topic {
30 32
     /** Topic. */
31 33
     private final String topic;
32 34
     /** Topic client. */
33
-    private final String client;
35
+    private final User client;
34 36
     /** Topic time. */
35 37
     private final long time;
36 38
 
@@ -41,7 +43,7 @@ public class Topic {
41 43
      * @param client Topic client
42 44
      * @param time   Topic time
43 45
      */
44
-    public Topic(final String topic, final String client, final long time) {
46
+    public Topic(final String topic, final User client, final long time) {
45 47
         this.topic = topic;
46 48
         this.client = client;
47 49
         this.time = time;
@@ -50,9 +52,9 @@ public class Topic {
50 52
     /**
51 53
      * Returns the client who set the topic.
52 54
      *
53
-     * @return client host
55
+     * @return client
54 56
      */
55
-    public String getClient() {
57
+    public User getClient() {
56 58
         return client;
57 59
     }
58 60
 

+ 14
- 5
test/com/dmdirc/TopicTest.java Ver arquivo

@@ -22,33 +22,42 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.interfaces.User;
26
+
25 27
 import org.junit.Test;
28
+import org.junit.runner.RunWith;
29
+import org.mockito.Mock;
30
+import org.mockito.runners.MockitoJUnitRunner;
26 31
 
27 32
 import static org.junit.Assert.*;
28 33
 
34
+@RunWith(MockitoJUnitRunner.class)
29 35
 public class TopicTest {
30 36
 
37
+    @Mock
38
+    private User user;
39
+
31 40
     @Test
32 41
     public void testGetClient() {
33
-        final Topic test = new Topic("abc", "123!456@789", 1);
34
-        assertEquals("123!456@789", test.getClient());
42
+        final Topic test = new Topic("abc", user, 1);
43
+        assertEquals(user, test.getClient());
35 44
     }
36 45
 
37 46
     @Test
38 47
     public void testGetTime() {
39
-        final Topic test = new Topic("abc", "123!456@789", 1);
48
+        final Topic test = new Topic("abc", user, 1);
40 49
         assertEquals(1L, test.getTime());
41 50
     }
42 51
 
43 52
     @Test
44 53
     public void testGetTopic() {
45
-        final Topic test = new Topic("abc", "123!456@789", 1);
54
+        final Topic test = new Topic("abc", user, 1);
46 55
         assertEquals("abc", test.getTopic());
47 56
     }
48 57
 
49 58
     @Test
50 59
     public void testToString() {
51
-        final Topic test = new Topic("abc", "123!456@789", 1);
60
+        final Topic test = new Topic("abc", user, 1);
52 61
         assertEquals("abc", test.toString());
53 62
     }
54 63
 

Carregando…
Cancelar
Salvar