Sfoglia il codice sorgente

Make topics have proper dates.

pull/611/head
Chris Smith 8 anni fa
parent
commit
9897426a7a

+ 1
- 1
res/com/dmdirc/ui/messages/format.yml Vedi File

@@ -106,7 +106,7 @@ ChannelCtcpEvent:
106 106
 ChannelGotTopicEvent:
107 107
   format: |
108 108
             * The topic for {{channel.name}} is '{{topic.topic}}'.
109
-            * Topic was set by {{user.nickname}} at {{topic.time}}.
109
+            * Topic was set by {{user.nickname}} at {{topic.date}}.
110 110
   colour: 3
111 111
 ChannelTopicChangeEvent:
112 112
   format: "* {{user.nickname}} has changed the topic to {{topic.topic}}."

+ 1
- 1
src/com/dmdirc/Channel.java Vedi File

@@ -436,7 +436,7 @@ public class Channel extends FrameContainer implements GroupChat {
436 436
             args.add(topic.getClient().flatMap(GroupChatUser::getUsername).orElse(""));
437 437
             args.add(topic.getClient().flatMap(GroupChatUser::getHostname).orElse(""));
438 438
             args.add(topic.getTopic());
439
-            args.add(topic.getTime() * 1000);
439
+            args.add(topic.getDate().getTime());
440 440
 
441 441
             return true;
442 442
         } else {

+ 1
- 1
src/com/dmdirc/ChannelEventHandler.java Vedi File

@@ -136,7 +136,7 @@ public class ChannelEventHandler extends EventHandler {
136 136
 
137 137
         final Topic topic = Topic.create(channel.getTopic(),
138 138
                 owner.getUser(getConnection().getUser(channel.getTopicSetter())).orElse(null),
139
-                channel.getTopicTime());
139
+                new Date(1000 * channel.getTopicTime()));
140 140
 
141 141
         if (event.isJoinTopic()) {
142 142
             if (Strings.isNullOrEmpty(channel.getTopic())) {

+ 4
- 3
src/com/dmdirc/Topic.java Vedi File

@@ -26,6 +26,7 @@ import com.dmdirc.interfaces.GroupChatUser;
26 26
 
27 27
 import com.google.auto.value.AutoValue;
28 28
 
29
+import java.util.Date;
29 30
 import java.util.Optional;
30 31
 
31 32
 /**
@@ -41,11 +42,11 @@ public abstract class Topic {
41 42
     /** Topic client. */
42 43
     public abstract Optional<GroupChatUser> getClient();
43 44
     /** Topic time. */
44
-    public abstract long getTime();
45
+    public abstract Date getDate();
45 46
 
46 47
     public static Topic create(final String topic,
47 48
             final GroupChatUser groupChatUser,
48
-            final long time) {
49
-        return new AutoValue_Topic(topic, Optional.ofNullable(groupChatUser), time);
49
+            final Date date) {
50
+        return new AutoValue_Topic(topic, Optional.ofNullable(groupChatUser), date);
50 51
     }
51 52
 }

+ 2
- 1
src/com/dmdirc/commandparser/commands/channel/ShowTopic.java Vedi File

@@ -38,6 +38,7 @@ import com.dmdirc.interfaces.GroupChat;
38 38
 import com.dmdirc.interfaces.GroupChatUser;
39 39
 import com.dmdirc.interfaces.WindowModel;
40 40
 
41
+import java.util.Date;
41 42
 import java.util.Optional;
42 43
 
43 44
 import javax.annotation.Nonnull;
@@ -77,7 +78,7 @@ public class ShowTopic extends Command implements ExternalCommand {
77 78
                         user.flatMap(GroupChatUser::getUsername).orElse(""),
78 79
                         user.flatMap(GroupChatUser::getHostname).orElse(""),
79 80
                         topic.map(Topic::getTopic).orElse(""),
80
-                        1000 * topic.map(Topic::getTime).get(),
81
+                        topic.map(Topic::getDate).map(Date::getTime).get(),
81 82
                         channel.getName());
82 83
             } else {
83 84
                 sendLine(origin, args.isSilent(), "channelNoTopic", channel.getName());

+ 9
- 0
src/com/dmdirc/ui/messages/EventPropertyManager.java Vedi File

@@ -38,6 +38,15 @@ import org.slf4j.LoggerFactory;
38 38
 
39 39
 import static com.dmdirc.util.LogUtils.USER_ERROR;
40 40
 
41
+/**
42
+ * Provides properties and functions used by an {@link EventFormatter}.
43
+ *
44
+ * <p>Properties are dyanamically supplied based on get methods within the class. For example, if
45
+ * channel objects have a 'getName()' method, then the name can be accessed as {{channel.name}}.
46
+ *
47
+ * <p>Functions are implemented as string transformations, and are defined in
48
+ * {@link #EventPropertyManager()}.
49
+ */
41 50
 @Singleton
42 51
 public class EventPropertyManager {
43 52
 

+ 6
- 4
test/com/dmdirc/TopicTest.java Vedi File

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.interfaces.GroupChatUser;
26 26
 
27
+import java.util.Date;
27 28
 import java.util.Optional;
28 29
 
29 30
 import org.junit.Test;
@@ -41,19 +42,20 @@ public class TopicTest {
41 42
 
42 43
     @Test
43 44
     public void testGetClient() {
44
-        final Topic test = Topic.create("abc", user, 1);
45
+        final Topic test = Topic.create("abc", user, new Date());
45 46
         assertEquals(Optional.of(user), test.getClient());
46 47
     }
47 48
 
48 49
     @Test
49 50
     public void testGetTime() {
50
-        final Topic test = Topic.create("abc", user, 1);
51
-        assertEquals(1L, test.getTime());
51
+        final Date date = new Date(123394432);
52
+        final Topic test = Topic.create("abc", user, date);
53
+        assertEquals(date, test.getDate());
52 54
     }
53 55
 
54 56
     @Test
55 57
     public void testGetTopic() {
56
-        final Topic test = Topic.create("abc", user, 1);
58
+        final Topic test = Topic.create("abc", user, new Date());
57 59
         assertEquals("abc", test.getTopic());
58 60
     }
59 61
 

+ 3
- 3
test/com/dmdirc/ui/messages/EventFormatterTest.java Vedi File

@@ -55,7 +55,7 @@ public class EventFormatterTest {
55 55
         messageEvent = new ChannelMessageEvent(channel, null, null);
56 56
 
57 57
         when(templateProvider.getFormat(ChannelMessageEvent.class))
58
-                .thenReturn(Optional.ofNullable(
58
+                .thenReturn(Optional.of(
59 59
                         EventFormat.create("Template {{channel}} meep", Optional.empty())));
60 60
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
61 61
                 .thenReturn(Optional.of("MONKEY"));
@@ -68,7 +68,7 @@ public class EventFormatterTest {
68 68
         messageEvent = new ChannelMessageEvent(channel, null, null);
69 69
 
70 70
         when(templateProvider.getFormat(ChannelMessageEvent.class))
71
-                .thenReturn(Optional.ofNullable(
71
+                .thenReturn(Optional.of(
72 72
                         EventFormat.create("Template {{channel|lowercase}} meep",
73 73
                                 Optional.empty())));
74 74
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
@@ -83,7 +83,7 @@ public class EventFormatterTest {
83 83
         messageEvent = new ChannelMessageEvent(channel, null, "{{channel}}");
84 84
 
85 85
         when(templateProvider.getFormat(ChannelMessageEvent.class))
86
-                .thenReturn(Optional.ofNullable(
86
+                .thenReturn(Optional.of(
87 87
                         EventFormat.create("Template {{message}} meep", Optional.empty())));
88 88
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "message"))
89 89
                 .thenReturn(Optional.of("{{channel}}"));

Loading…
Annulla
Salva