Skip to content

Commit

Permalink
Make topics have proper dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 2, 2016
1 parent ae354ae commit 9897426
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion res/com/dmdirc/ui/messages/format.yml
Expand Up @@ -106,7 +106,7 @@ ChannelCtcpEvent:
ChannelGotTopicEvent:
format: |
* The topic for {{channel.name}} is '{{topic.topic}}'.
* Topic was set by {{user.nickname}} at {{topic.time}}.
* Topic was set by {{user.nickname}} at {{topic.date}}.
colour: 3
ChannelTopicChangeEvent:
format: "* {{user.nickname}} has changed the topic to {{topic.topic}}."
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/Channel.java
Expand Up @@ -436,7 +436,7 @@ protected boolean processNotificationArg(final Object arg, final List<Object> ar
args.add(topic.getClient().flatMap(GroupChatUser::getUsername).orElse(""));
args.add(topic.getClient().flatMap(GroupChatUser::getHostname).orElse(""));
args.add(topic.getTopic());
args.add(topic.getTime() * 1000);
args.add(topic.getDate().getTime());

return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/ChannelEventHandler.java
Expand Up @@ -136,7 +136,7 @@ public void onChannelTopic(final ChannelTopicEvent event) {

final Topic topic = Topic.create(channel.getTopic(),
owner.getUser(getConnection().getUser(channel.getTopicSetter())).orElse(null),
channel.getTopicTime());
new Date(1000 * channel.getTopicTime()));

if (event.isJoinTopic()) {
if (Strings.isNullOrEmpty(channel.getTopic())) {
Expand Down
7 changes: 4 additions & 3 deletions src/com/dmdirc/Topic.java
Expand Up @@ -26,6 +26,7 @@

import com.google.auto.value.AutoValue;

import java.util.Date;
import java.util.Optional;

/**
Expand All @@ -41,11 +42,11 @@ public abstract class Topic {
/** Topic client. */
public abstract Optional<GroupChatUser> getClient();
/** Topic time. */
public abstract long getTime();
public abstract Date getDate();

public static Topic create(final String topic,
final GroupChatUser groupChatUser,
final long time) {
return new AutoValue_Topic(topic, Optional.ofNullable(groupChatUser), time);
final Date date) {
return new AutoValue_Topic(topic, Optional.ofNullable(groupChatUser), date);
}
}
3 changes: 2 additions & 1 deletion src/com/dmdirc/commandparser/commands/channel/ShowTopic.java
Expand Up @@ -38,6 +38,7 @@
import com.dmdirc.interfaces.GroupChatUser;
import com.dmdirc.interfaces.WindowModel;

import java.util.Date;
import java.util.Optional;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void execute(@Nonnull final WindowModel origin,
user.flatMap(GroupChatUser::getUsername).orElse(""),
user.flatMap(GroupChatUser::getHostname).orElse(""),
topic.map(Topic::getTopic).orElse(""),
1000 * topic.map(Topic::getTime).get(),
topic.map(Topic::getDate).map(Date::getTime).get(),
channel.getName());
} else {
sendLine(origin, args.isSilent(), "channelNoTopic", channel.getName());
Expand Down
9 changes: 9 additions & 0 deletions src/com/dmdirc/ui/messages/EventPropertyManager.java
Expand Up @@ -38,6 +38,15 @@

import static com.dmdirc.util.LogUtils.USER_ERROR;

/**
* Provides properties and functions used by an {@link EventFormatter}.
*
* <p>Properties are dyanamically supplied based on get methods within the class. For example, if
* channel objects have a 'getName()' method, then the name can be accessed as {{channel.name}}.
*
* <p>Functions are implemented as string transformations, and are defined in
* {@link #EventPropertyManager()}.
*/
@Singleton
public class EventPropertyManager {

Expand Down
10 changes: 6 additions & 4 deletions test/com/dmdirc/TopicTest.java
Expand Up @@ -24,6 +24,7 @@

import com.dmdirc.interfaces.GroupChatUser;

import java.util.Date;
import java.util.Optional;

import org.junit.Test;
Expand All @@ -41,19 +42,20 @@ public class TopicTest {

@Test
public void testGetClient() {
final Topic test = Topic.create("abc", user, 1);
final Topic test = Topic.create("abc", user, new Date());
assertEquals(Optional.of(user), test.getClient());
}

@Test
public void testGetTime() {
final Topic test = Topic.create("abc", user, 1);
assertEquals(1L, test.getTime());
final Date date = new Date(123394432);
final Topic test = Topic.create("abc", user, date);
assertEquals(date, test.getDate());
}

@Test
public void testGetTopic() {
final Topic test = Topic.create("abc", user, 1);
final Topic test = Topic.create("abc", user, new Date());
assertEquals("abc", test.getTopic());
}

Expand Down
6 changes: 3 additions & 3 deletions test/com/dmdirc/ui/messages/EventFormatterTest.java
Expand Up @@ -55,7 +55,7 @@ public void testBasicFormat() {
messageEvent = new ChannelMessageEvent(channel, null, null);

when(templateProvider.getFormat(ChannelMessageEvent.class))
.thenReturn(Optional.ofNullable(
.thenReturn(Optional.of(
EventFormat.create("Template {{channel}} meep", Optional.empty())));
when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
.thenReturn(Optional.of("MONKEY"));
Expand All @@ -68,7 +68,7 @@ public void testFormatWithFunction() {
messageEvent = new ChannelMessageEvent(channel, null, null);

when(templateProvider.getFormat(ChannelMessageEvent.class))
.thenReturn(Optional.ofNullable(
.thenReturn(Optional.of(
EventFormat.create("Template {{channel|lowercase}} meep",
Optional.empty())));
when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
Expand All @@ -83,7 +83,7 @@ public void testFormatWithNestedSubstitutions() {
messageEvent = new ChannelMessageEvent(channel, null, "{{channel}}");

when(templateProvider.getFormat(ChannelMessageEvent.class))
.thenReturn(Optional.ofNullable(
.thenReturn(Optional.of(
EventFormat.create("Template {{message}} meep", Optional.empty())));
when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "message"))
.thenReturn(Optional.of("{{channel}}"));
Expand Down

0 comments on commit 9897426

Please sign in to comment.