Преглед изворни кода

Make topics have proper dates.

pull/611/head
Chris Smith пре 8 година
родитељ
комит
9897426a7a

+ 1
- 1
res/com/dmdirc/ui/messages/format.yml Прегледај датотеку

106
 ChannelGotTopicEvent:
106
 ChannelGotTopicEvent:
107
   format: |
107
   format: |
108
             * The topic for {{channel.name}} is '{{topic.topic}}'.
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
   colour: 3
110
   colour: 3
111
 ChannelTopicChangeEvent:
111
 ChannelTopicChangeEvent:
112
   format: "* {{user.nickname}} has changed the topic to {{topic.topic}}."
112
   format: "* {{user.nickname}} has changed the topic to {{topic.topic}}."

+ 1
- 1
src/com/dmdirc/Channel.java Прегледај датотеку

436
             args.add(topic.getClient().flatMap(GroupChatUser::getUsername).orElse(""));
436
             args.add(topic.getClient().flatMap(GroupChatUser::getUsername).orElse(""));
437
             args.add(topic.getClient().flatMap(GroupChatUser::getHostname).orElse(""));
437
             args.add(topic.getClient().flatMap(GroupChatUser::getHostname).orElse(""));
438
             args.add(topic.getTopic());
438
             args.add(topic.getTopic());
439
-            args.add(topic.getTime() * 1000);
439
+            args.add(topic.getDate().getTime());
440
 
440
 
441
             return true;
441
             return true;
442
         } else {
442
         } else {

+ 1
- 1
src/com/dmdirc/ChannelEventHandler.java Прегледај датотеку

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

+ 4
- 3
src/com/dmdirc/Topic.java Прегледај датотеку

26
 
26
 
27
 import com.google.auto.value.AutoValue;
27
 import com.google.auto.value.AutoValue;
28
 
28
 
29
+import java.util.Date;
29
 import java.util.Optional;
30
 import java.util.Optional;
30
 
31
 
31
 /**
32
 /**
41
     /** Topic client. */
42
     /** Topic client. */
42
     public abstract Optional<GroupChatUser> getClient();
43
     public abstract Optional<GroupChatUser> getClient();
43
     /** Topic time. */
44
     /** Topic time. */
44
-    public abstract long getTime();
45
+    public abstract Date getDate();
45
 
46
 
46
     public static Topic create(final String topic,
47
     public static Topic create(final String topic,
47
             final GroupChatUser groupChatUser,
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 Прегледај датотеку

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

+ 9
- 0
src/com/dmdirc/ui/messages/EventPropertyManager.java Прегледај датотеку

38
 
38
 
39
 import static com.dmdirc.util.LogUtils.USER_ERROR;
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
 @Singleton
50
 @Singleton
42
 public class EventPropertyManager {
51
 public class EventPropertyManager {
43
 
52
 

+ 6
- 4
test/com/dmdirc/TopicTest.java Прегледај датотеку

24
 
24
 
25
 import com.dmdirc.interfaces.GroupChatUser;
25
 import com.dmdirc.interfaces.GroupChatUser;
26
 
26
 
27
+import java.util.Date;
27
 import java.util.Optional;
28
 import java.util.Optional;
28
 
29
 
29
 import org.junit.Test;
30
 import org.junit.Test;
41
 
42
 
42
     @Test
43
     @Test
43
     public void testGetClient() {
44
     public void testGetClient() {
44
-        final Topic test = Topic.create("abc", user, 1);
45
+        final Topic test = Topic.create("abc", user, new Date());
45
         assertEquals(Optional.of(user), test.getClient());
46
         assertEquals(Optional.of(user), test.getClient());
46
     }
47
     }
47
 
48
 
48
     @Test
49
     @Test
49
     public void testGetTime() {
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
     @Test
56
     @Test
55
     public void testGetTopic() {
57
     public void testGetTopic() {
56
-        final Topic test = Topic.create("abc", user, 1);
58
+        final Topic test = Topic.create("abc", user, new Date());
57
         assertEquals("abc", test.getTopic());
59
         assertEquals("abc", test.getTopic());
58
     }
60
     }
59
 
61
 

+ 3
- 3
test/com/dmdirc/ui/messages/EventFormatterTest.java Прегледај датотеку

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

Loading…
Откажи
Сачувај