X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=055ede4a30c59c5036bdd78730861292ba92a335;hb=0dc8ce4308f55d8f13e41c7ac312c11a379418b9;hp=52b885e011ce4e840db70a95a3316824152b48f7;hpb=d1c7f645f187884df0171309ecb63617373afb59;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 52b885e..055ede4 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -106,6 +106,9 @@ public class Core implements IdentityListener { /* synchronize access on this on itself. */ private Map remoteSones = new HashMap(); + /** All new Sones. */ + private Set newSones = new HashSet(); + /** All posts. */ private Map posts = new HashMap(); @@ -306,6 +309,35 @@ public class Core implements IdentityListener { } /** + * Returns whether the Sone with the given ID is a remote Sone. + * + * @param id + * The ID of the Sone to check + * @return {@code true} if the Sone with the given ID is a remote Sone, + * {@code false} otherwise + */ + public boolean isRemoteSone(String id) { + synchronized (remoteSones) { + return remoteSones.containsKey(id); + } + } + + /** + * Returns whether the given Sone is a new Sone. After this check, the Sone + * is marked as known, i.e. a second call with the same parameters will + * always yield {@code false}. + * + * @param sone + * The sone to check for + * @return {@code true} if the given Sone is new, false otherwise + */ + public boolean isNewSone(Sone sone) { + synchronized (newSones) { + return newSones.remove(sone); + } + } + + /** * Returns the post with the given ID. * * @param postId @@ -494,11 +526,18 @@ public class Core implements IdentityListener { return null; } synchronized (remoteSones) { + boolean newSone = !isRemoteSone(identity.getId()); final Sone sone = getRemoteSone(identity.getId()).setIdentity(identity); sone.setRequestUri(getSoneUri(identity.getRequestUri())); sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0)); + if (newSone) { + synchronized (newSones) { + newSones.add(sone); + } + } remoteSones.put(identity.getId(), sone); soneDownloader.addSone(sone); + setSoneStatus(sone, SoneStatus.unknown); new Thread(new Runnable() { @Override @@ -508,7 +547,6 @@ public class Core implements IdentityListener { } }, "Sone Downloader").start(); - setSoneStatus(sone, SoneStatus.idle); return sone; } }