X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=811950d2cd35f9f0ea738626ab227ae91a9cb6e6;hp=f979284efad1cbd9a8f34a03db608d39b686adc5;hb=bbd0a9e769d18091f7c15a1b87a6316f5abb88a1;hpb=cb6325fa54d93612c5aad307204d30600b27af81 diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index f979284..811950d 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -24,8 +24,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; @@ -40,12 +40,12 @@ import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; 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.Sone; -import net.pterodactylus.sone.data.TemporaryImage; -import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone.ShowCustomAvatars; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; import net.pterodactylus.sone.freenet.wot.Identity; @@ -863,6 +863,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0)); sone.setClient(new Client("Sone", SonePlugin.VERSION.toString())); + sone.setKnown(true); /* TODO - load posts ’n stuff */ localSones.put(ownIdentity.getId(), sone); final SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone); @@ -1167,15 +1168,13 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis List storedPosts = storedSone.getPosts(); synchronized (knownPosts) { for (Post post : sone.getPosts()) { - post.setSone(storedSone); + post.setSone(storedSone).setKnown(knownPosts.contains(post.getId())); if (!storedPosts.contains(post)) { if (post.getTime() < getSoneFollowingTime(sone)) { - sone.setKnown(true); knownPosts.add(post.getId()); } else if (!knownPosts.contains(post.getId())) { + sone.setKnown(false); coreListenerManager.fireNewPostFound(post); - } else { - sone.setKnown(true); } } posts.put(post.getId(), post); @@ -1194,15 +1193,13 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis Set storedReplies = storedSone.getReplies(); synchronized (knownReplies) { for (PostReply reply : sone.getReplies()) { - reply.setSone(storedSone); + reply.setSone(storedSone).setKnown(knownReplies.contains(reply.getId())); if (!storedReplies.contains(reply)) { if (reply.getTime() < getSoneFollowingTime(sone)) { - reply.setKnown(true); knownReplies.add(reply.getId()); } else if (!knownReplies.contains(reply.getId())) { + reply.setKnown(false); coreListenerManager.fireNewReplyFound(reply); - } else { - reply.setKnown(true); } } replies.put(reply.getId(), reply); @@ -1296,8 +1293,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** - * Marks the given Sone as known. If the Sone was {@link #isNewPost(String) - * new} before, a {@link CoreListener#markSoneKnown(Sone)} event is fired. + * Marks the given Sone as known. If the Sone was not {@link Post#isKnown() + * known} before, a {@link CoreListener#markSoneKnown(Sone)} event is fired. * * @param sone * The Sone to mark as known @@ -1644,8 +1641,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** - * Marks the given post as known, if it is currently a new post (according - * to {@link #isNewPost(String)}). + * Marks the given post as known, if it is currently not a known post + * (according to {@link Post#isKnown()}). * * @param post * The post to mark as known @@ -1653,11 +1650,14 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis public void markPostKnown(Post post) { post.setKnown(true); synchronized (knownPosts) { + coreListenerManager.fireMarkPostKnown(post); if (knownPosts.add(post.getId())) { - coreListenerManager.fireMarkPostKnown(post); touchConfiguration(); } } + for (PostReply reply : getReplies(post)) { + markReplyKnown(reply); + } } /** @@ -1783,8 +1783,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** - * Marks the given reply as known, if it is currently a new reply (according - * to {@link #isNewReply(String)}). + * Marks the given reply as known, if it is currently not a known reply + * (according to {@link Reply#isKnown()}). * * @param reply * The reply to mark as known @@ -1792,8 +1792,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis public void markReplyKnown(PostReply reply) { reply.setKnown(true); synchronized (knownReplies) { + coreListenerManager.fireMarkReplyKnown(reply); if (knownReplies.add(reply.getId())) { - coreListenerManager.fireMarkReplyKnown(reply); touchConfiguration(); } } @@ -2408,7 +2408,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ @Override public void ownIdentityAdded(OwnIdentity ownIdentity) { - logger.log(Level.FINEST, "Adding OwnIdentity: " + ownIdentity); + logger.log(Level.FINEST, "Adding OwnIdentity: %s", ownIdentity); if (ownIdentity.hasContext("Sone")) { trustedIdentities.put(ownIdentity, Collections.synchronizedSet(new HashSet())); addLocalSone(ownIdentity); @@ -2429,7 +2429,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ @Override public void identityAdded(OwnIdentity ownIdentity, Identity identity) { - logger.log(Level.FINEST, "Adding Identity: " + identity); + logger.log(Level.FINEST, "Adding Identity: %s", identity); trustedIdentities.get(ownIdentity).add(identity); addRemoteSone(identity); }