From 6163031365fd14a7351a9689ac3325e03c9d165d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Oct 2013 21:37:47 +0200 Subject: [PATCH] Add callback when reply is updated. --- src/main/java/net/pterodactylus/sone/core/Core.java | 17 +++++++++++++---- src/main/java/net/pterodactylus/sone/data/Reply.java | 9 ++++++++- .../pterodactylus/sone/data/impl/DefaultPostReply.java | 5 ++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 03091e3..af81054 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -63,6 +63,7 @@ import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Reply.Modifier.ReplyUpdated; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.ShowCustomAvatars; import net.pterodactylus.sone.data.Sone.SoneStatus; @@ -839,7 +840,7 @@ public class Core extends AbstractService implements SoneProvider { continue; } if (reply.getTime() < getSoneFollowingTime(sone)) { - reply.modify().setKnown().update(); + reply.modify().setKnown().update(Optional.>absent()); } else if (!reply.isKnown()) { eventBus.post(new NewPostReplyFoundEvent(reply)); } @@ -1134,7 +1135,7 @@ public class Core extends AbstractService implements SoneProvider { } database.storePostReplies(sone, replies); for (PostReply reply : replies) { - reply.modify().setKnown().update(); + reply.modify().setKnown().update(Optional.>absent()); } logger.info(String.format("Sone loaded successfully: %s", sone)); @@ -1234,8 +1235,7 @@ public class Core extends AbstractService implements SoneProvider { */ public void markReplyKnown(PostReply reply) { boolean previouslyKnown = reply.isKnown(); - reply.modify().setKnown().update(); - eventBus.post(new MarkPostReplyKnownEvent(reply)); + reply.modify().setKnown().update(postReplyUpdated()); if (!previouslyKnown) { touchConfiguration(); } @@ -1852,6 +1852,15 @@ public class Core extends AbstractService implements SoneProvider { }); } + public Optional> postReplyUpdated() { + return Optional.>of(new ReplyUpdated() { + @Override + public void replyUpdated(PostReply reply) { + eventBus.post(new MarkPostReplyKnownEvent(reply)); + } + }); + } + public Optional imageCreated() { return Optional.of(new ImageCreated() { @Override diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index 2c2a7bd..c660f27 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.data; import java.util.Comparator; +import com.google.common.base.Optional; import com.google.common.base.Predicate; /** @@ -96,7 +97,13 @@ public interface Reply> extends Identified { interface Modifier { Modifier setKnown(); - T update(); + T update(Optional> replyUpdated); + + interface ReplyUpdated { + + void replyUpdated(T reply); + + } } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReply.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReply.java index 705586b..41e64b0 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReply.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReply.java @@ -84,10 +84,13 @@ public class DefaultPostReply extends DefaultReply implements PostRep } @Override - public PostReply update() { + public PostReply update(Optional> replyUpdated) { if (known) { database.setPostReplyKnown(DefaultPostReply.this); } + if (replyUpdated.isPresent()) { + replyUpdated.get().replyUpdated(DefaultPostReply.this); + } return DefaultPostReply.this; } }; -- 2.7.4