X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=6ca7372898661dd7b8784d5d2cac7b3ff8440efb;hb=0aa389b2493e19484530698e2ce056372dc2a1e9;hp=2d23de39dcba5a43bfd71470d5e8c47c12724931;hpb=faf8ac927b8e188ba791aab1eec2574a4faa8bef;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 2d23de3..6ca7372 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -158,9 +158,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /* synchronize access on this on sones. */ private final Map soneRescuers = new HashMap(); - /** All known Sones. */ - private final Set knownSones = new HashSet(); - /** The post database. */ private final Database database; @@ -363,7 +360,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @return {@code true} if a modification has been detected in the Sone, * {@code false} otherwise */ - public boolean isModifiedSone(Sone sone) { + public boolean isModifiedSone(LocalSone sone) { return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified(); } @@ -608,7 +605,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The own identity to create a Sone from * @return The added (or already existing) Sone */ - public Sone addLocalSone(OwnIdentity ownIdentity) { + public LocalSone addLocalSone(OwnIdentity ownIdentity) { if (ownIdentity == null) { logger.log(Level.WARNING, "Given OwnIdentity is null!"); return null; @@ -640,7 +637,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity)); return null; } - Sone sone = addLocalSone(ownIdentity); + LocalSone sone = addLocalSone(ownIdentity); followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI"); touchConfiguration(); @@ -669,13 +666,11 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, Sone sone = !newSone ? existingSone.get() : database.newSoneBuilder().from(identity).build(); sone.setLatestEdition(latestEdition); if (newSone) { - synchronized (knownSones) { - newSone = !knownSones.contains(sone.getId()); - } + newSone = !database.isSoneKnown(sone); sone.setKnown(!newSone); if (newSone) { eventBus.post(new NewSoneFoundEvent(sone)); - for (Sone localSone : getLocalSones()) { + for (LocalSone localSone : getLocalSones()) { if (localSone.getOptions().isAutoFollow()) { followSone(localSone, sone.getId()); } @@ -696,7 +691,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @param soneId * The ID of the Sone to follow */ - public void followSone(Sone sone, String soneId) { + public void followSone(LocalSone sone, String soneId) { checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); database.addFriend(sone, soneId); @@ -731,7 +726,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @param soneId * The ID of the Sone being unfollowed */ - public void unfollowSone(Sone sone, String soneId) { + public void unfollowSone(LocalSone sone, String soneId) { checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); database.removeFriend(sone, soneId); @@ -939,9 +934,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, public void markSoneKnown(Sone sone) { if (!sone.isKnown()) { sone.setKnown(true); - synchronized (knownSones) { - knownSones.add(sone.getId()); - } + database.setSoneKnown(sone); eventBus.post(new MarkSoneKnownEvent(sone)); touchConfiguration(); } @@ -1283,17 +1276,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, try { preferences.saveTo(configuration); - /* save known Sones. */ - int soneCounter = 0; - synchronized (knownSones) { - for (String knownSoneId : knownSones) { - configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId); - } - configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null); - } - /* save Sone following times. */ - soneCounter = 0; + int soneCounter = 0; synchronized (soneFollowingTimes) { for (Entry soneFollowingTime : soneFollowingTimes.entrySet()) { configuration.getStringValue("SoneFollowingTimes/" + soneCounter + "/Sone").setValue(soneFollowingTime.getKey()); @@ -1326,20 +1310,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, private void loadConfiguration() { new PreferencesLoader(preferences).loadFrom(configuration); - /* load known Sones. */ - int soneCounter = 0; - while (true) { - String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null); - if (knownSoneId == null) { - break; - } - synchronized (knownSones) { - knownSones.add(knownSoneId); - } - } - /* load Sone following times. */ - soneCounter = 0; + int soneCounter = 0; while (true) { String soneId = configuration.getStringValue("SoneFollowingTimes/" + soneCounter + "/Sone").getValue(null); if (soneId == null) {