X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=93891ab3e4af5613d2a820a9c8989d31f4bfee6f;hb=19a2cb003837648db4d708eac8971343b5026257;hp=15a7b0e01052cd1c1b29bac1d62ec0e424791db8;hpb=4075fb19b937045f682b12c09b9873a9543f5ddb;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 15a7b0e..93891ab 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -109,6 +109,10 @@ public class Core implements IdentityListener { /** All new Sones. */ private Set newSones = new HashSet(); + /** All known Sones. */ + /* synchronize access on {@link #newSones}. */ + private Set knownSones = new HashSet(); + /** All posts. */ private Map posts = new HashMap(); @@ -333,7 +337,9 @@ public class Core implements IdentityListener { */ public boolean isNewSone(Sone sone) { synchronized (newSones) { - return newSones.remove(sone); + boolean isNew = !knownSones.contains(sone) && newSones.remove(sone); + knownSones.add(sone); + return isNew; } } @@ -735,6 +741,11 @@ public class Core implements IdentityListener { sone.setFriends(friends); sone.setModificationCounter(soneModificationCounter); } + synchronized (newSones) { + for (Sone friend : friends) { + knownSones.add(friend); + } + } } /** @@ -984,6 +995,17 @@ public class Core implements IdentityListener { options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null)); + /* load known Sones. */ + int soneCounter = 0; + while (true) { + String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null); + if (knownSoneId == null) { + break; + } + synchronized (newSones) { + knownSones.add(getRemoteSone(knownSoneId)); + } + } } /** @@ -995,6 +1017,16 @@ public class Core implements IdentityListener { configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal()); configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal()); + + /* save known Sones. */ + int soneCounter = 0; + synchronized (newSones) { + for (Sone knownSone : knownSones) { + configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSone.getId()); + } + configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null); + } + } catch (ConfigurationException ce1) { logger.log(Level.SEVERE, "Could not store configuration!", ce1); }