X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=291cb95cd35e163c0812040041648c931762d0c2;hp=6ca7372898661dd7b8784d5d2cac7b3ff8440efb;hb=722b47810ffbe01465f104791c9f660ae161023b;hpb=0aa389b2493e19484530698e2ce056372dc2a1e9 diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 6ca7372..291cb95 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -143,9 +143,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** The trust updater. */ private final WebOfTrustUpdater webOfTrustUpdater; - /** The times Sones were followed. */ - private final Map soneFollowingTimes = new HashMap(); - /** Locked local Sones. */ /* synchronize on itself. */ private final Set lockedSones = new HashSet(); @@ -373,9 +370,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * been followed, or {@link Long#MAX_VALUE} */ public long getSoneFollowingTime(Sone sone) { - synchronized (soneFollowingTimes) { - return Optional.fromNullable(soneFollowingTimes.get(sone.getId())).or(Long.MAX_VALUE); - } + return database.getSoneFollowingTime(sone.getId()).or(Long.MAX_VALUE); } /** @@ -694,28 +689,25 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, public void followSone(LocalSone sone, String soneId) { checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); + boolean newFriend = !database.getSoneFollowingTime(soneId).isPresent(); database.addFriend(sone, soneId); - synchronized (soneFollowingTimes) { - if (!soneFollowingTimes.containsKey(soneId)) { - long now = System.currentTimeMillis(); - soneFollowingTimes.put(soneId, now); - Optional followedSone = getSone(soneId); - if (!followedSone.isPresent()) { - return; - } - for (Post post : followedSone.get().getPosts()) { - if (post.getTime() < now) { - markPostKnown(post); - } + if (newFriend) { + long now = System.currentTimeMillis(); + Optional followedSone = getSone(soneId); + if (!followedSone.isPresent()) { + return; + } + for (Post post : followedSone.get().getPosts()) { + if (post.getTime() < now) { + markPostKnown(post); } - for (PostReply reply : followedSone.get().getReplies()) { - if (reply.getTime() < now) { - markReplyKnown(reply); - } + } + for (PostReply reply : followedSone.get().getReplies()) { + if (reply.getTime() < now) { + markReplyKnown(reply); } } } - touchConfiguration(); } /** @@ -730,16 +722,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); database.removeFriend(sone, soneId); - boolean unfollowedSoneStillFollowed = false; - for (Sone localSone : getLocalSones()) { - unfollowedSoneStillFollowed |= localSone.hasFriend(soneId); - } - if (!unfollowedSoneStillFollowed) { - synchronized (soneFollowingTimes) { - soneFollowingTimes.remove(soneId); - } - } - touchConfiguration(); } /** @@ -1276,17 +1258,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, try { preferences.saveTo(configuration); - /* save Sone following times. */ - int soneCounter = 0; - synchronized (soneFollowingTimes) { - for (Entry soneFollowingTime : soneFollowingTimes.entrySet()) { - configuration.getStringValue("SoneFollowingTimes/" + soneCounter + "/Sone").setValue(soneFollowingTime.getKey()); - configuration.getLongValue("SoneFollowingTimes/" + soneCounter + "/Time").setValue(soneFollowingTime.getValue()); - ++soneCounter; - } - configuration.getStringValue("SoneFollowingTimes/" + soneCounter + "/Sone").setValue(null); - } - /* save known posts. */ database.save(); @@ -1309,20 +1280,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, */ private void loadConfiguration() { new PreferencesLoader(preferences).loadFrom(configuration); - - /* load Sone following times. */ - int soneCounter = 0; - while (true) { - String soneId = configuration.getStringValue("SoneFollowingTimes/" + soneCounter + "/Sone").getValue(null); - if (soneId == null) { - break; - } - long time = configuration.getLongValue("SoneFollowingTimes/" + soneCounter + "/Time").getValue(Long.MAX_VALUE); - synchronized (soneFollowingTimes) { - soneFollowingTimes.put(soneId, time); - } - ++soneCounter; - } } /**